/*---------------------------------------------------------------------------*/ 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; }
int main(void) { const char *na_info_string = NULL; na_class_t *na_class; na_context_t * na_context; char self_addr_string[PATH_MAX]; na_addr_t self_addr; FILE *na_config = NULL; hg_class_t *hg_class; hg_context_t *hg_context; unsigned major; unsigned minor; unsigned patch; hg_return_t hg_ret; na_size_t self_addr_string_size = PATH_MAX; HG_Version_get(&major, &minor, &patch); printf("Server running mercury version %u.%u-%u\n", major, minor, patch); /* Get info string */ /* bmi+tcp://localhost:port */ na_info_string = getenv(HG_PORT_NAME); if (!na_info_string) { fprintf(stderr, HG_PORT_NAME " environment variable must be set, e.g.:\nMERCURY_PORT_NAME=\"tcp://127.0.0.1:22222\"\n"); exit(0); } /* Initialize NA */ na_class = NA_Initialize(na_info_string, NA_TRUE); /* Get self addr to tell client about */ NA_Addr_self(na_class, &self_addr); NA_Addr_to_string(na_class, self_addr_string, &self_addr_string_size, self_addr); NA_Addr_free(na_class, self_addr); printf("Server address is: %s\n", self_addr_string); /* Write addr to a file */ na_config = fopen(TEMP_DIRECTORY CONFIG_FILE_NAME, "w+"); if (!na_config) { fprintf(stderr, "Could not open config file from: %s\n", TEMP_DIRECTORY CONFIG_FILE_NAME); exit(0); } fprintf(na_config, "%s\n", self_addr_string); fclose(na_config); /* Create NA context */ na_context = NA_Context_create(na_class); /* Initialize Mercury with the desired network abstraction class */ hg_class = HG_Init_na(na_class, na_context); /* Create HG context */ hg_context = HG_Context_create(hg_class); /* Register RPC */ snappy_compress_register(hg_class); /* Poke progress engine and check for events */ do { unsigned int actual_count = 0; do { hg_ret = HG_Trigger(hg_context, 0 /* timeout */, 1 /* max count */, &actual_count); } while ((hg_ret == HG_SUCCESS) && actual_count); /* Do not try to make progress anymore if we're done */ if (snappy_compress_done_target_g) break; hg_ret = HG_Progress(hg_context, HG_MAX_IDLE_TIME); } while (hg_ret == HG_SUCCESS); /* Finalize */ HG_Context_destroy(hg_context); HG_Finalize(hg_class); NA_Context_destroy(na_class, na_context); NA_Finalize(na_class); return EXIT_SUCCESS; }