/*---------------------------------------------------------------------------*/ hg_class_t * HG_Test_client_init(int argc, char *argv[], hg_addr_t *addr, int *rank, hg_context_t **context, hg_request_class_t **request_class) { char test_addr_name[NA_TEST_MAX_ADDR_NAME]; hg_return_t ret; hg_test_na_class_g = NA_Test_client_init(argc, argv, test_addr_name, NA_TEST_MAX_ADDR_NAME, &hg_test_rank_g); hg_test_na_context_g = NA_Context_create(hg_test_na_class_g); ret = HG_Hl_init_na(hg_test_na_class_g, hg_test_na_context_g); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not initialize Mercury\n"); goto done; } if (na_test_use_self_g) { size_t bulk_size = 1024 * 1024 * MERCURY_TESTING_BUFFER_SIZE; /* Self addr */ HG_Addr_self(HG_CLASS_DEFAULT, &hg_test_addr_g); /* In case of self we need the local thread pool */ #ifdef MERCURY_TESTING_HAS_THREAD_POOL hg_thread_mutex_init(&hg_test_local_bulk_handle_mutex_g); hg_thread_pool_init(MERCURY_TESTING_NUM_THREADS, &hg_test_thread_pool_g); printf("# Starting server with %d threads...\n", MERCURY_TESTING_NUM_THREADS); #endif /* Create bulk buffer that can be used for receiving data */ HG_Bulk_create(HG_CLASS_DEFAULT, 1, NULL, &bulk_size, HG_BULK_READWRITE, &hg_test_local_bulk_handle_g); } else { /* Look up addr using port name info */ ret = HG_Hl_addr_lookup_wait(HG_CONTEXT_DEFAULT, HG_REQUEST_CLASS_DEFAULT, test_addr_name, &hg_test_addr_g, HG_MAX_IDLE_TIME); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not find addr %s\n", test_addr_name); goto done; } } /* Register routines */ hg_test_register(HG_CLASS_DEFAULT); /* When finalize is called we need to free the addr etc */ hg_test_is_client_g = HG_TRUE; if (addr) *addr = hg_test_addr_g; if (rank) *rank = hg_test_rank_g; if (context) *context = HG_CONTEXT_DEFAULT; if (request_class) * request_class = HG_REQUEST_CLASS_DEFAULT; done: return HG_CLASS_DEFAULT; }
/*---------------------------------------------------------------------------*/ hg_return_t hg_test_drc_acquire(int argc, char *argv[], struct hg_test_info *hg_test_info) { struct hg_test_info hg_test_drc_info = { 0 }; struct hg_init_info hg_test_drc_init_info = { 0 }; hg_return_t ret = HG_SUCCESS; if (!hg_test_info->credential) { /* Create an NA class with "tcp" protocol */ hg_test_drc_info.na_test_info.extern_init = NA_TRUE; hg_test_drc_info.na_test_info.protocol = strdup("tcp"); hg_test_drc_info.na_test_info.listen = hg_test_info->na_test_info.listen; if (NA_Test_init(argc, argv, &hg_test_drc_info.na_test_info) != NA_SUCCESS) { HG_LOG_ERROR("Could not initialize NA test layer"); ret = HG_NA_ERROR; goto done; } /* Assign NA class */ hg_test_drc_init_info.na_class = hg_test_drc_info.na_test_info.na_class; /* Init HG HL with init options */ ret = HG_Hl_init_opt(NULL, hg_test_drc_info.na_test_info.listen, &hg_test_drc_init_info); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not initialize HG HL"); goto done; } hg_test_drc_info.hg_class = HG_CLASS_DEFAULT; hg_test_drc_info.context = HG_CONTEXT_DEFAULT; hg_test_drc_info.request_class = HG_REQUEST_CLASS_DEFAULT; /* Attach test info to class */ HG_Class_set_data(hg_test_drc_info.hg_class, &hg_test_drc_info, NULL); /* Register routines */ hg_test_drc_register(hg_test_drc_info.hg_class); /* Acquire DRC token */ if (hg_test_drc_info.na_test_info.listen) { char addr_string[NA_TEST_MAX_ADDR_NAME]; na_size_t addr_string_len = NA_TEST_MAX_ADDR_NAME; hg_addr_t self_addr; ret = hg_test_drc_token_acquire(&hg_test_drc_info); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not acquire DRC token"); goto done; } /* TODO only rank 0 */ ret = HG_Addr_self(hg_test_drc_info.hg_class, &self_addr); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not get self addr"); goto done; } ret = HG_Addr_to_string(hg_test_drc_info.hg_class, addr_string, &addr_string_len, self_addr); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not convert addr to string"); goto done; } HG_Addr_free(hg_test_drc_info.hg_class, self_addr); na_test_set_config(addr_string); /* Used by CTest Test Driver to know when to launch clients */ MERCURY_TESTING_READY_MSG(); /* Progress */ do { unsigned int total_count = 0; unsigned int actual_count = 0; do { ret = HG_Trigger(hg_test_drc_info.context, 0, 1, &actual_count); total_count += actual_count; } while ((ret == HG_SUCCESS) && actual_count); /* Break as soon as something was triggered */ if (total_count) break; ret = HG_Progress(hg_test_drc_info.context, HG_MAX_IDLE_TIME); } while (ret == HG_SUCCESS || ret == HG_TIMEOUT); } else { char test_addr_name[NA_TEST_MAX_ADDR_NAME] = { '\0' }; if (hg_test_drc_info.na_test_info.mpi_comm_rank == 0) na_test_get_config(test_addr_name, NA_TEST_MAX_ADDR_NAME); /* Broadcast addr name */ NA_Test_bcast(test_addr_name, NA_TEST_MAX_ADDR_NAME, 0, &hg_test_drc_info.na_test_info); hg_test_drc_info.na_test_info.target_name = strdup(test_addr_name); printf("# Target name read: %s\n", hg_test_drc_info.na_test_info.target_name); ret = hg_test_drc_token_request(&hg_test_drc_info); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not request DRC token"); goto done; } } #ifdef MERCURY_HAS_PARALLEL_TESTING /* TODO bcast cookie when parallel mode */ #endif /* Finalize HG HL interface */ ret = HG_Hl_finalize(); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not finalize HG HL"); goto done; } /* Finalize NA test class interface */ #ifdef MERCURY_HAS_PARALLEL_TESTING hg_test_drc_info.na_test_info.mpi_no_finalize = NA_TRUE; #endif if (NA_Test_finalize(&hg_test_drc_info.na_test_info) != NA_SUCCESS) { HG_LOG_ERROR("Could not finalize NA test interface"); ret = HG_NA_ERROR; goto done; } hg_test_info->credential = hg_test_drc_info.credential; } else { hg_test_drc_info.credential = hg_test_info->credential; ret = hg_test_drc_token_acquire(&hg_test_drc_info); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not acquire DRC token"); goto done; } } /* Copy cookie/credential info */ hg_test_info->wlm_id = hg_test_drc_info.wlm_id; hg_test_info->credential_info = hg_test_drc_info.credential_info; hg_test_info->cookie = hg_test_drc_info.cookie; /* Sleep a few seconds to make sure listener is initialized */ if (!hg_test_drc_info.na_test_info.listen) { unsigned int sleep_sec = 5; printf("# Sleeping now for %d seconds...\n", sleep_sec); fflush(stdout); sleep(sleep_sec); } done: return ret; }