コード例 #1
0
ファイル: na_test.c プロジェクト: carns/mercury
/*---------------------------------------------------------------------------*/
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;
}
コード例 #2
0
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;
}