static inline int populate_av(void) { int i, ret = 0; char *alladdrs = NULL; #ifdef USE_ON_NODE_COMMS int num_on_node = 0; char ephostname[EPHOSTNAMELEN]; #endif alladdrs = malloc(shmem_internal_num_pes * shmem_transport_ofi_addrlen); if (alladdrs == NULL) { OFI_ERRMSG("Out of memory allocating 'alladdrs'\n"); return ret; } for (i = 0; i < shmem_internal_num_pes; i++) { char *addr_ptr = alladdrs + i * shmem_transport_ofi_addrlen; shmem_runtime_get(i, "fi_epname", addr_ptr, shmem_transport_ofi_addrlen); #ifdef USE_ON_NODE_COMMS shmem_runtime_get(i, "fi_ephostname", ephostname, EPHOSTNAMELEN); if(strncmp(myephostname, ephostname, EPHOSTNAMELEN) == 0) { SHMEM_SET_RANK_SAME_NODE(i, num_on_node++); if (num_on_node > 255) { OFI_ERRMSG("ERROR: Too many local ranks\n"); return 1; } } #endif } ret = fi_av_insert(shmem_transport_ofi_avfd, alladdrs, shmem_internal_num_pes, addr_table, 0, NULL); if (ret != shmem_internal_num_pes) { OFI_ERRMSG("av insert failed\n"); return ret; } free(alladdrs); return 0; }
int shmem_transport_startup(void) { int ret, i; ptl_process_t *desired = NULL; ptl_md_t md; ptl_le_t le; ptl_uid_t uid = PTL_UID_ANY; ptl_process_t my_id; #ifdef USE_ON_NODE_COMMS int num_on_node = 0; #endif #ifdef ENABLE_REMOTE_VIRTUAL_ADDRESSING /* Make sure the heap and data bases are actually symmetric */ { int peer; uint64_t bases[2]; peer = (shmem_internal_my_pe + 1) % shmem_internal_num_pes; ret = shmem_runtime_get(peer, "portals4-bases", bases, sizeof(uint64_t) * 2); if (0 != ret) { fprintf(stderr, "[%03d] ERROR: runtime_put failed: %d\n", shmem_internal_my_pe, ret); return ret; } if ((uintptr_t) shmem_internal_heap_base != bases[0]) { fprintf(stderr, "[%03d] ERROR: heap base address does not match with rank %03d and virtual addressing is enabled\n", shmem_internal_my_pe, peer); return -1; } if ((uintptr_t) shmem_internal_data_base != bases[1]) { fprintf(stderr, "[%03d] ERROR: data base address does not match with rank %03d and virtual addressing is enabled\n", shmem_internal_my_pe, peer); return -1; } } #endif desired = malloc(sizeof(ptl_process_t) * shmem_internal_num_pes); if (NULL == desired) { ret = 1; goto cleanup; } ret = PtlGetPhysId(shmem_transport_portals4_ni_h, &my_id); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlGetPhysId failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } for (i = 0 ; i < shmem_internal_num_pes; ++i) { ret = shmem_runtime_get(i, "portals4-procid", &desired[i], sizeof(ptl_process_t)); if (0 != ret) { fprintf(stderr, "[%03d] ERROR: runtime_get failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } #ifdef USE_ON_NODE_COMMS /* update the connectivity map... */ if (desired[i].phys.nid == my_id.phys.nid) { SHMEM_SET_RANK_SAME_NODE(i, num_on_node++); if (num_on_node > 255) { fprintf(stderr, "[%03d] ERROR: Too many local ranks.\n", shmem_internal_my_pe); goto cleanup; } } #endif } ret = PtlSetMap(shmem_transport_portals4_ni_h, shmem_internal_num_pes, desired); if (PTL_OK != ret && PTL_IGNORED != ret) { fprintf(stderr, "[%03d] ERROR: PtlSetMap failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } ret = PtlGetUid(shmem_transport_portals4_ni_h, &uid); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlGetUid failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } shmem_transport_portals4_max_volatile_size = ni_limits.max_volatile_size; shmem_transport_portals4_max_atomic_size = ni_limits.max_atomic_size; shmem_transport_portals4_max_fetch_atomic_size = ni_limits.max_fetch_atomic_size; shmem_transport_portals4_max_msg_size = ni_limits.max_msg_size; if (shmem_transport_portals4_max_volatile_size < sizeof(long double complex)) { fprintf(stderr, "[%03d] ERROR: Max volatile size found to be %lu, too small to continue\n", shmem_internal_my_pe, (unsigned long) shmem_transport_portals4_max_volatile_size); goto cleanup; } if (shmem_transport_portals4_max_atomic_size < sizeof(long double complex)) { fprintf(stderr, "[%03d] ERROR: Max atomic size found to be %lu, too small to continue\n", shmem_internal_my_pe, (unsigned long) shmem_transport_portals4_max_atomic_size); goto cleanup; } if (shmem_transport_portals4_max_fetch_atomic_size < sizeof(long double complex)) { fprintf(stderr, "[%03d] ERROR: Max fetch atomic size found to be %lu, too small to continue\n", shmem_internal_my_pe, (unsigned long) shmem_transport_portals4_max_fetch_atomic_size); goto cleanup; } /* create portal table entries */ ret = PtlEQAlloc(shmem_transport_portals4_ni_h, shmem_transport_portals4_event_slots, &shmem_transport_portals4_eq_h); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlEQAlloc failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } #ifdef ENABLE_REMOTE_VIRTUAL_ADDRESSING ret = PtlPTAlloc(shmem_transport_portals4_ni_h, 0, shmem_transport_portals4_eq_h, shmem_transport_portals4_pt, &all_pt); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlPTAlloc of table entry failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } #else ret = PtlPTAlloc(shmem_transport_portals4_ni_h, 0, shmem_transport_portals4_eq_h, shmem_transport_portals4_data_pt, &data_pt); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlPTAlloc of data table failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } ret = PtlPTAlloc(shmem_transport_portals4_ni_h, 0, shmem_transport_portals4_eq_h, shmem_transport_portals4_heap_pt, &heap_pt); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlPTAlloc of heap table failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } #endif #ifndef ENABLE_HARD_POLLING /* target ct */ ret = PtlCTAlloc(shmem_transport_portals4_ni_h, &shmem_transport_portals4_target_ct_h); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlCTAlloc of target ct failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } le.ct_handle = shmem_transport_portals4_target_ct_h; #endif le.uid = uid; le.options = PTL_LE_OP_PUT | PTL_LE_OP_GET | PTL_LE_EVENT_LINK_DISABLE | PTL_LE_EVENT_SUCCESS_DISABLE; #if !defined(ENABLE_HARD_POLLING) le.options |= PTL_LE_EVENT_CT_COMM; #endif #ifdef ENABLE_REMOTE_VIRTUAL_ADDRESSING le.start = NULL; le.length = PTL_SIZE_MAX; ret = PtlLEAppend(shmem_transport_portals4_ni_h, shmem_transport_portals4_pt, &le, PTL_PRIORITY_LIST, NULL, &shmem_transport_portals4_le_h); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlLEAppend of all memory failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } #else /* Open LE to heap section */ le.start = shmem_internal_heap_base; le.length = shmem_internal_heap_length; ret = PtlLEAppend(shmem_transport_portals4_ni_h, shmem_transport_portals4_heap_pt, &le, PTL_PRIORITY_LIST, NULL, &shmem_transport_portals4_heap_le_h); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlLEAppend of heap section failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } /* Open LE to data section */ le.start = shmem_internal_data_base; le.length = shmem_internal_data_length; ret = PtlLEAppend(shmem_transport_portals4_ni_h, shmem_transport_portals4_data_pt, &le, PTL_PRIORITY_LIST, NULL, &shmem_transport_portals4_data_le_h); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlLEAppend of data section failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } #endif /* Open MD to all memory */ ret = PtlCTAlloc(shmem_transport_portals4_ni_h, &shmem_transport_portals4_put_ct_h); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlCTAlloc of put ct failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } ret = PtlCTAlloc(shmem_transport_portals4_ni_h, &shmem_transport_portals4_get_ct_h); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlCTAlloc of get ct failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } md.start = 0; md.length = PTL_SIZE_MAX; md.options = PTL_MD_EVENT_CT_ACK; if (1 == PORTALS4_TOTAL_DATA_ORDERING) { md.options |= PTL_MD_UNORDERED; } md.eq_handle = shmem_transport_portals4_eq_h; md.ct_handle = shmem_transport_portals4_put_ct_h; ret = PtlMDBind(shmem_transport_portals4_ni_h, &md, &shmem_transport_portals4_put_event_md_h); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlMDBind of put MD failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } md.start = 0; md.length = PTL_SIZE_MAX; md.options = PTL_MD_EVENT_CT_ACK | PTL_MD_EVENT_SUCCESS_DISABLE | PTL_MD_VOLATILE; if (1 == PORTALS4_TOTAL_DATA_ORDERING) { md.options |= PTL_MD_UNORDERED; } md.eq_handle = shmem_transport_portals4_eq_h; md.ct_handle = shmem_transport_portals4_put_ct_h; ret = PtlMDBind(shmem_transport_portals4_ni_h, &md, &shmem_transport_portals4_put_volatile_md_h); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlMDBind of put MD failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } md.start = 0; md.length = PTL_SIZE_MAX; md.options = PTL_MD_EVENT_CT_ACK | PTL_MD_EVENT_SUCCESS_DISABLE; if (1 == PORTALS4_TOTAL_DATA_ORDERING) { md.options |= PTL_MD_UNORDERED; } md.eq_handle = shmem_transport_portals4_eq_h; md.ct_handle = shmem_transport_portals4_put_ct_h; ret = PtlMDBind(shmem_transport_portals4_ni_h, &md, &shmem_transport_portals4_put_cntr_md_h); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlMDBind of put cntr MD failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } md.start = 0; md.length = PTL_SIZE_MAX; md.options = PTL_MD_EVENT_CT_REPLY | PTL_MD_EVENT_SUCCESS_DISABLE; if (1 == PORTALS4_TOTAL_DATA_ORDERING) { md.options |= PTL_MD_UNORDERED; } md.eq_handle = shmem_transport_portals4_eq_h; md.ct_handle = shmem_transport_portals4_get_ct_h; ret = PtlMDBind(shmem_transport_portals4_ni_h, &md, &shmem_transport_portals4_get_md_h); if (PTL_OK != ret) { fprintf(stderr, "[%03d] ERROR: PtlMDBind of get MD failed: %d\n", shmem_internal_my_pe, ret); goto cleanup; } ret = 0; cleanup: if (NULL != desired) free(desired); return ret; }