/*---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { struct na_test_lat_info na_test_lat_info = { 0 }; na_size_t size, max_size; int ret = EXIT_SUCCESS; /* Initialize the interface */ NA_Test_init(argc, argv, &na_test_lat_info.na_test_info); na_test_lat_info.na_class = na_test_lat_info.na_test_info.na_class; na_test_lat_info.context = NA_Context_create(na_test_lat_info.na_class); na_test_lat_info.request_class = hg_request_init(na_test_request_progress, na_test_request_trigger, &na_test_lat_info); /* Lookup target addr */ na_test_target_lookup(&na_test_lat_info); /* Set max size */ max_size = NA_Msg_get_max_unexpected_size(na_test_lat_info.na_class); if (na_test_lat_info.na_test_info.mpi_comm_rank == 0) { fprintf(stdout, "# %s v%s\n", BENCHMARK_NAME, VERSION_NAME); fprintf(stdout, "# Loop %d times from size %d to %zu byte(s)\n", na_test_lat_info.na_test_info.loop, 1, max_size); #ifdef MERCURY_TESTING_HAS_VERIFY_DATA fprintf(stdout, "# WARNING verifying data, output will be slower\n"); #endif fprintf(stdout, "%-*s%*s\n", 10, "# Size", NWIDTH, "Latency (us)"); fflush(stdout); } /* Msg with different sizes */ for (size = 1; size <= max_size; size *= 2) na_test_measure_latency(&na_test_lat_info, size); /* Finalize interface */ if (na_test_lat_info.na_test_info.mpi_comm_rank == 0) na_test_send_finalize(&na_test_lat_info); NA_Addr_free(na_test_lat_info.na_class, na_test_lat_info.target_addr); hg_request_finalize(na_test_lat_info.request_class, NULL); NA_Context_destroy(na_test_lat_info.na_class, na_test_lat_info.context); NA_Test_finalize(&na_test_lat_info.na_test_info); return ret; }
int main(int argc, char *argv[]) { struct na_test_info na_test_info = { 0 }; struct na_test_params params; na_return_t na_ret; unsigned int i; int ret = EXIT_SUCCESS; /* Initialize the interface */ NA_Test_init(argc, argv, &na_test_info); params.na_class = na_test_info.na_class; params.context = NA_Context_create(params.na_class); /* Allocate send and recv bufs */ params.send_buf_len = NA_Msg_get_max_unexpected_size(params.na_class); params.recv_buf_len = params.send_buf_len; params.send_buf = (char*)NA_Msg_buf_alloc(params.na_class, params.send_buf_len, ¶ms.send_buf_plugin_data); params.recv_buf = (char*)NA_Msg_buf_alloc(params.na_class, params.recv_buf_len, ¶ms.recv_buf_plugin_data); /* Prepare bulk_buf */ params.bulk_size = NA_TEST_BULK_SIZE; params.bulk_buf = (unsigned int *) malloc( params.bulk_size * sizeof(unsigned int)); for (i = 0; i < params.bulk_size; i++) { params.bulk_buf[i] = i; } /* Perform an address lookup on the target */ na_ret = NA_Addr_lookup(params.na_class, params.context, lookup_cb, ¶ms, na_test_info.target_name, NA_OP_ID_IGNORE); if (na_ret != NA_SUCCESS) { NA_LOG_ERROR("Could not start lookup of addr %s", na_test_info.target_name); ret = EXIT_FAILURE; goto done; } while (1) { na_return_t trigger_ret; unsigned int actual_count = 0; unsigned int timeout = 0; do { trigger_ret = NA_Trigger(params.context, 0, 1, NULL, &actual_count); } while ((trigger_ret == NA_SUCCESS) && actual_count); if (test_msg_done_g && test_bulk_done_g) break; if (NA_Poll_try_wait(params.na_class, params.context)) timeout = NA_MAX_IDLE_TIME; na_ret = NA_Progress(params.na_class, params.context, timeout); if (na_ret != NA_SUCCESS) { ret = EXIT_FAILURE; goto done; } } ret = params.ret; printf("Finalizing...\n"); /* Free memory and addresses */ na_ret = NA_Addr_free(params.na_class, params.server_addr); if (na_ret != NA_SUCCESS) { NA_LOG_ERROR("Could not free addr"); ret = EXIT_FAILURE; goto done; } NA_Msg_buf_free(params.na_class, params.recv_buf, params.recv_buf_plugin_data); NA_Msg_buf_free(params.na_class, params.send_buf, params.send_buf_plugin_data); free(params.bulk_buf); NA_Context_destroy(params.na_class, params.context); NA_Test_finalize(&na_test_info); done: return ret; }
int main(int argc, char **argv) { char server_name[NA_TEST_MAX_ADDR_NAME]; struct na_test_params params; na_return_t na_ret; unsigned int i; /* Initialize the interface */ params.na_class = NA_Test_client_init(argc, argv, server_name, NA_TEST_MAX_ADDR_NAME, NULL); params.context = NA_Context_create(params.na_class); /* Allocate send and recv bufs */ params.send_buf_len = NA_Msg_get_max_unexpected_size(params.na_class); params.recv_buf_len = params.send_buf_len; params.send_buf = (char*) calloc(params.send_buf_len, sizeof(char)); params.recv_buf = (char*) calloc(params.recv_buf_len, sizeof(char)); /* Prepare bulk_buf */ params.bulk_size = NA_TEST_BULK_SIZE; params.bulk_buf = (int*) malloc(params.bulk_size * sizeof(int)); for (i = 0; i < params.bulk_size; i++) { params.bulk_buf[i] = i; } /* Perform an address lookup on the target */ na_ret = NA_Addr_lookup(params.na_class, params.context, lookup_cb, ¶ms, server_name, NA_OP_ID_IGNORE); if (na_ret != NA_SUCCESS) { fprintf(stderr, "Could not start lookup of addr %s\n", server_name); return EXIT_FAILURE; } while (!test_done_g) { na_return_t trigger_ret; unsigned int actual_count = 0; do { trigger_ret = NA_Trigger(params.context, 0, 1, &actual_count); } while ((trigger_ret == NA_SUCCESS) && actual_count); if (test_done_g) break; NA_Progress(params.na_class, params.context, NA_MAX_IDLE_TIME); } printf("Finalizing...\n"); /* Free memory and addresses */ na_ret = NA_Addr_free(params.na_class, params.server_addr); if (na_ret != NA_SUCCESS) { fprintf(stderr, "Could not free addr\n"); return EXIT_FAILURE; } free(params.recv_buf); free(params.send_buf); free(params.bulk_buf); NA_Context_destroy(params.na_class, params.context); NA_Test_finalize(params.na_class); return EXIT_SUCCESS; }
/*---------------------------------------------------------------------------*/ na_return_t NA_Test_init(int argc, char *argv[], struct na_test_info *na_test_info) { char *info_string = NULL; struct na_init_info na_init_info; na_return_t ret = NA_SUCCESS; na_test_parse_options(argc, argv, na_test_info); #ifdef MERCURY_HAS_PARALLEL_TESTING /* Test run in parallel using mpirun so must intialize MPI to get * basic setup info etc */ na_test_mpi_init(na_test_info); na_test_info->max_number_of_peers = MPIEXEC_MAX_NUMPROCS; #else na_test_info->mpi_comm_rank = 0; na_test_info->mpi_comm_size = 1; na_test_info->max_number_of_peers = 1; #endif /* Generate NA init string and get config options */ info_string = na_test_gen_config(na_test_info); if (!info_string) { NA_LOG_ERROR("Could not generate config string"); ret = NA_PROTOCOL_ERROR; goto done; } /* Call cleanup before doing anything */ if (na_test_info->listen && na_test_info->mpi_comm_rank == 0) NA_Cleanup(); memset(&na_init_info, 0, sizeof(struct na_init_info)); if (na_test_info->busy_wait) { na_init_info.progress_mode = NA_NO_BLOCK; printf("# Initializing NA in busy wait mode\n"); } else na_init_info.progress_mode = NA_DEFAULT; na_init_info.auth_key = na_test_info->key; na_init_info.max_contexts = na_test_info->max_contexts; printf("# Using info string: %s\n", info_string); na_test_info->na_class = NA_Initialize_opt(info_string, na_test_info->listen, &na_init_info); if (!na_test_info->na_class) { NA_LOG_ERROR("Could not initialize NA"); ret = NA_PROTOCOL_ERROR; goto done; } if (!na_test_info->extern_init) { if (na_test_info->listen) { char addr_string[NA_TEST_MAX_ADDR_NAME]; na_size_t addr_string_len = NA_TEST_MAX_ADDR_NAME; na_addr_t self_addr; na_return_t nret; /* TODO only rank 0 */ nret = NA_Addr_self(na_test_info->na_class, &self_addr); if (nret != NA_SUCCESS) { NA_LOG_ERROR("Could not get self addr"); } nret = NA_Addr_to_string(na_test_info->na_class, addr_string, &addr_string_len, self_addr); if (nret != NA_SUCCESS) { NA_LOG_ERROR("Could not convert addr to string"); } NA_Addr_free(na_test_info->na_class, self_addr); na_test_set_config(addr_string); #ifdef MERCURY_HAS_PARALLEL_TESTING /* If static client must wait for server to write config file */ if (na_test_info->mpi_static) MPI_Barrier(MPI_COMM_WORLD); #endif /* Used by CTest Test Driver to know when to launch clients */ MERCURY_TESTING_READY_MSG(); } /* Get config from file if self option is not passed */ else if (!na_test_info->self_send) { char test_addr_name[NA_TEST_MAX_ADDR_NAME] = { '\0' }; #ifdef MERCURY_HAS_PARALLEL_TESTING /* If static client must wait for server to write config file */ if (na_test_info->mpi_static) MPI_Barrier(MPI_COMM_WORLD); #endif if (na_test_info->mpi_comm_rank == 0) { na_test_get_config(test_addr_name, NA_TEST_MAX_ADDR_NAME); } #ifdef MERCURY_HAS_PARALLEL_TESTING /* Broadcast addr name */ MPI_Bcast(test_addr_name, NA_TEST_MAX_ADDR_NAME, MPI_BYTE, 0, na_test_info->mpi_comm); #endif na_test_info->target_name = strdup(test_addr_name); printf("# Target name read: %s\n", na_test_info->target_name); } } done: if (ret != NA_SUCCESS) NA_Test_finalize(na_test_info); free(info_string); return ret; }
/*---------------------------------------------------------------------------*/ 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; }
/*---------------------------------------------------------------------------*/ hg_return_t HG_Test_finalize(hg_class_t *hg_class) { hg_return_t ret = HG_SUCCESS; na_return_t na_ret; NA_Test_barrier(); (void)hg_class; if (hg_test_is_client_g) { /* Terminate server */ if (hg_test_rank_g == 0) hg_test_finalize_rpc(); /* Free addr id */ ret = HG_Addr_free(HG_CLASS_DEFAULT, hg_test_addr_g); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not free addr\n"); goto done; } hg_test_addr_g = HG_ADDR_NULL; } else if (hg_test_addr_table_g) { unsigned int i; for (i = 0; i < hg_test_addr_table_size_g; i++) HG_Addr_free(HG_CLASS_DEFAULT, hg_test_addr_table_g[i]); free(hg_test_addr_table_g); hg_test_addr_table_g = NULL; } /* Destroy bulk handle */ HG_Bulk_free(hg_test_local_bulk_handle_g); hg_test_local_bulk_handle_g = HG_BULK_NULL; #ifdef MERCURY_TESTING_HAS_THREAD_POOL hg_thread_pool_destroy(hg_test_thread_pool_g); hg_thread_mutex_destroy(&hg_test_local_bulk_handle_mutex_g); #endif /* Finalize interface */ ret = HG_Hl_finalize(); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not finalize HG\n"); goto done; } na_ret = NA_Context_destroy(hg_test_na_class_g, hg_test_na_context_g); if (na_ret != NA_SUCCESS) { fprintf(stderr, "Could not destroy NA context\n"); goto done; } hg_test_na_context_g = NULL; na_ret = NA_Test_finalize(hg_test_na_class_g); if (na_ret != NA_SUCCESS) { fprintf(stderr, "Could not finalize NA interface\n"); goto done; } done: return ret; }