/** * Initialize UPC runtime. * * All hardware/software components of the Portals4 interface * are initialized in this routine. */ static void gupcr_init (void) { int run_threads_count; upc_shared_ptr_t heap_region_base; size_t heap_region_size; /* Set up debugging, tracing, statistics, and timing support. */ gupcr_utils_init (); /* Initialize Runtime. */ gupcr_runtime_init (); /* Initialize Portals. */ gupcr_portals_init (); /* Get the thread number. */ MYTHREAD = gupcr_get_rank (); /* Validate program info. */ gupcr_validate_pgm_info (); run_threads_count = gupcr_get_threads_count (); /* THREADS == -1, dynamic number of threads THREADS != -1, static number of threads and number of running and compiled threads must match. */ if (THREADS == -1) THREADS = run_threads_count; else if (THREADS != run_threads_count) gupcr_abort_with_msg ("number of running threads (%d) is " "not equal to compiled threads (%d)", THREADS, run_threads_count); gupcr_assert (THREADS >= 1); /* Initialize the Portals Network Interface. */ gupcr_portals_ni_init (); /* Initialize this thread's multi-node tree position. */ gupcr_nodetree_setup (); /* Initialize various runtime components. */ gupcr_node_init (); gupcr_gmem_init (); gupcr_lock_init (); gupcr_barrier_init (); gupcr_broadcast_init (); gupcr_coll_init (); gupcr_shutdown_init (); GUPCR_PTS_SET_NULL_SHARED (heap_region_base); GUPCR_PTS_SET_THREAD (heap_region_base, MYTHREAD); GUPCR_PTS_SET_VADDR (heap_region_base, gupcr_gmem_heap_base_offset); heap_region_size = gupcr_gmem_heap_size; gupcr_alloc_init (heap_region_base, heap_region_size); /* Indicate that runtime initialization is complete. */ gupcr_init_complete (); /* It is ok to call the finalization routines */ gupcr_finalize_ok = 1; }
static upc_info_p __upc_init (char *pgm, const char **err_msg) { upc_info_p u; os_heap_p runtime_heap; size_t alloc_data_size, local_size, max_init_alloc, heap_size; size_t mmap_fn_len; char mmap_file_name[2046]; upc_page_num_t init_page_alloc; const size_t gpt_size = (GUPCR_VM_MAX_PAGES_PER_THREAD * THREADS) * sizeof (upc_pte_t); /* On SGI/Irix, create the shared arena, used for inter-process synchronization, otherwise probably a no-op. */ max_init_alloc = GUPCR_ROUND (sizeof (upc_info_t) + gpt_size + sizeof (mmap_file_name), 0x4000); runtime_heap = __upc_create_runtime_heap (max_init_alloc, err_msg); if (!runtime_heap) return 0; /* allocate the UPC info structure */ u = __upc_runtime_alloc (sizeof (upc_info_t), &runtime_heap, err_msg); if (!u) return 0; memset (u, '\0', sizeof (upc_info_t)); u->runtime_heap = runtime_heap; u->program_name = pgm; u->monitor_pid = getpid (); u->num_cpus = __upc_num_cpus; /* Defaults to 1, will be overidden if NUMA supported. */ u->num_nodes = 1; u->sched_policy = __upc_sched_policy; u->mem_policy = __upc_mem_policy; /* MPIR_partial_attach_ok support. */ if (MPIR_being_debugged) u->partial_attach_start = 0; /* Stop the threads until MPIR_berakpint. */ else u->partial_attach_start = 1; /* No debugging, threads can proceed. */ /* Find host name for MPIR interface. */ if (!gethostname (host_name, HOST_NAME_LEN)) u->host_name = host_name; else perror ("unable to find hostname"); /* Calculate per-thread contribution to global shared memory region. */ alloc_data_size = GUPCR_SHARED_SECTION_END - GUPCR_SHARED_SECTION_START; alloc_data_size = GUPCR_ROUND (alloc_data_size, C64K); heap_size = GUPCR_ROUND (__upc_init_heap_size, C64K); local_size = alloc_data_size + heap_size; /* Round up to a page boundary */ local_size = GUPCR_ROUND (local_size, GUPCR_VM_PAGE_SIZE); init_page_alloc = local_size / GUPCR_VM_PAGE_SIZE; /* Everything that isn't initially allocated to data will be used for the heap. */ heap_size = local_size - alloc_data_size; u->init_page_alloc = init_page_alloc; u->init_heap_size = heap_size; GUPCR_PTS_SET_NULL_SHARED (u->init_heap_base); GUPCR_PTS_SET_VADDR (u->init_heap_base, alloc_data_size); u->smem_fd = __upc_create_global_mem_file (mmap_file_name, err_msg); if (u->smem_fd < 0) return 0; mmap_fn_len = strlen (mmap_file_name); u->mmap_file_name = (char *) __upc_runtime_alloc (mmap_fn_len + 1, &runtime_heap, err_msg); if (!u->mmap_file_name) return 0; strcpy (u->mmap_file_name, mmap_file_name); /* Allocate the GPT. Avoid initializing it, because it may be a rather large data structure of which only a few initial locations are used. The VM routines that manipulate the GPT will initialize all needed entries as they are used. */ u->gpt = (upc_pte_p) __upc_runtime_alloc (gpt_size, &runtime_heap, err_msg); if (!u->gpt) return 0; return u; }