Esempio n. 1
0
int
main(int argc, char *argv[])
{
    hg_class_t *hg_class = NULL;
    hg_context_t *context = NULL;
    unsigned int number_of_peers;
    hg_return_t ret = HG_SUCCESS;

    hg_class = HG_Test_server_init(argc, argv, &na_addr_table,
            NULL, &number_of_peers, &context);

    do {
        unsigned int actual_count = 0;

        do {
            ret = HG_Trigger(hg_class, context, 0, 1, &actual_count);
        } while ((ret == HG_SUCCESS) && actual_count);

        if (hg_atomic_cas32(&hg_test_finalizing_count_g, 1, 1))
            break;

        ret = HG_Progress(hg_class, context, HG_MAX_IDLE_TIME);
    } while (ret == HG_SUCCESS);

    printf("# Finalizing...\n");
    HG_Test_finalize(hg_class);

    return EXIT_SUCCESS;
}
Esempio n. 2
0
/* dedicated thread function to drive Mercury progress */
static void* hg_progress_fn(void* foo)
{
    hg_return_t ret;
    unsigned int actual_count;
    (void)foo;

    while(!hg_progress_shutdown_flag)
    {
        do {
            ret = HG_Trigger(hg_context, 0, 1, &actual_count);
        } while((ret == HG_SUCCESS) && actual_count && !hg_progress_shutdown_flag);

        if(!hg_progress_shutdown_flag)
            HG_Progress(hg_context, 100);
    }

    return(NULL);
}
Esempio n. 3
0
int
main(void)
{
    const char *na_info_string = NULL;

    char target_addr_string[PATH_MAX], *p;
    FILE *na_config = NULL;
    struct snappy_lookup_args snappy_lookup_args;

    hg_class_t *hg_class;
    hg_context_t *hg_context;

    hg_return_t hg_ret;

    /* Get info string */
    na_info_string = getenv(HG_PORT_NAME);
    if (!na_info_string) {
        fprintf(stderr, HG_PORT_NAME " environment variable must be set");
        exit(0);
    }
    printf("Using %s\n", na_info_string);

    /* Initialize Mercury with the desired network abstraction class */
    hg_class = HG_Init(na_info_string, NA_FALSE);

    /* Create HG context */
    hg_context = HG_Context_create(hg_class);

    /* The connection string is generated after NA_Addr_self()/NA_Addr_to_string(),
     * we must get that string and pass it to  NA_Addr_lookup() */
    na_config = fopen(TEMP_DIRECTORY CONFIG_FILE_NAME, "r");
    if (!na_config) {
        fprintf(stderr, "Could not open config file from: %s\n",
                TEMP_DIRECTORY CONFIG_FILE_NAME);
        exit(0);
    }
    fgets(target_addr_string, PATH_MAX, na_config);
    p = strrchr(target_addr_string, '\n');
    if (p != NULL) *p = '\0';
    printf("Target address is: %s\n", target_addr_string);
    fclose(na_config);

    /* Look up target address */
    snappy_lookup_args.hg_class = hg_class;
    snappy_lookup_args.hg_context = hg_context;
    HG_Addr_lookup(hg_context, snappy_lookup_cb, &snappy_lookup_args,
            target_addr_string, HG_OP_ID_IGNORE);

    /* 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_g) break;

        hg_ret = HG_Progress(hg_context, HG_MAX_IDLE_TIME);
    } while (hg_ret == HG_SUCCESS);

    /* Finalize */
    HG_Addr_free(hg_class, snappy_lookup_args.hg_target_addr);

    HG_Context_destroy(hg_context);
    HG_Finalize(hg_class);

    return EXIT_SUCCESS;
}
Esempio n. 4
0
/*---------------------------------------------------------------------------*/
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;
}
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;
}