Exemple #1
0
/*---------------------------------------------------------------------------*/
na_context_t *
NA_Context_create(na_class_t *na_class)
{
    na_return_t ret = NA_SUCCESS;
    struct na_private_context *na_private_context = NULL;

    if (!na_class) {
        NA_LOG_ERROR("NULL NA class");
        ret = NA_INVALID_PARAM;
        goto done;
    }

    na_private_context = (struct na_private_context *) malloc(
            sizeof(struct na_private_context));
    if (!na_private_context) {
        NA_LOG_ERROR("Could not allocate context");
        ret = NA_NOMEM_ERROR;
        goto done;
    }

    if (na_class->context_create) {
        ret = na_class->context_create(na_class,
                &na_private_context->context.plugin_context);
        if (ret != NA_SUCCESS) {
            goto done;
        }
    }

    /* Initialize completion queue */
    na_private_context->completion_queue = hg_queue_new();
    if (!na_private_context->completion_queue) {
        NA_LOG_ERROR("Could not create completion queue");
        ret = NA_NOMEM_ERROR;
        goto done;
    }

    /* Initialize completion queue mutex/cond */
    hg_thread_mutex_init(&na_private_context->completion_queue_mutex);
    hg_thread_cond_init(&na_private_context->completion_queue_cond);

    /* Initialize progress mutex/cond */
    hg_thread_mutex_init(&na_private_context->progress_mutex);
    hg_thread_cond_init(&na_private_context->progress_cond);
    na_private_context->progressing = NA_FALSE;

done:
    if (ret != NA_SUCCESS) {
        free(na_private_context);
        na_private_context = NULL;
    }
    return (na_context_t *) na_private_context;
}
Exemple #2
0
/*---------------------------------------------------------------------------*/
hg_class_t *
HG_Test_server_init(int argc, char *argv[], hg_addr_t **addr_table,
        unsigned int *addr_table_size, unsigned int *max_number_of_peers,
        hg_context_t **context)
{
    size_t bulk_size = 1024 * 1024 * MERCURY_TESTING_BUFFER_SIZE;
    hg_return_t ret;

    hg_test_na_class_g = NA_Test_server_init(argc, argv, NA_FALSE,
            &hg_test_addr_name_table_g, &hg_test_addr_table_size_g, max_number_of_peers);

    hg_test_na_context_g = NA_Context_create(hg_test_na_class_g);

    /* Initalize atomic variable to finalize server */
    hg_atomic_set32(&hg_test_finalizing_count_g, 0);

#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

    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;
    }

    /* Register test routines */
    hg_test_register(HG_CLASS_DEFAULT);

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

    if (hg_test_addr_table_size_g > 1) {
        unsigned int i;

        hg_test_addr_table_g = (hg_addr_t *) malloc(hg_test_addr_table_size_g * sizeof(hg_addr_t));
        for (i = 0; i < hg_test_addr_table_size_g; i++) {
            ret = HG_Hl_addr_lookup_wait(HG_CONTEXT_DEFAULT, HG_REQUEST_CLASS_DEFAULT,
                    hg_test_addr_name_table_g[i], &hg_test_addr_table_g[i], HG_MAX_IDLE_TIME);
            if (ret != HG_SUCCESS) {
                fprintf(stderr, "Could not find addr %s\n", hg_test_addr_name_table_g[i]);
                goto done;
            }
        }
    }
    if (addr_table) *addr_table = hg_test_addr_table_g;
    if (addr_table_size) *addr_table_size = hg_test_addr_table_size_g;

    /* Used by CTest Test Driver */
    printf("Waiting for client...\n");
    fflush(stdout);

    if (context) *context = HG_CONTEXT_DEFAULT;

done:
    return HG_CLASS_DEFAULT;
}
int
main(int argc, char *argv[])
{
    hg_thread_t thread[MERCURY_TESTING_NUM_THREADS];
    int ret = EXIT_SUCCESS;
    int i;

    (void) argc;
    (void) argv;

    for (i = 0; i < MERCURY_TESTING_NUM_THREADS; i++)
        hg_thread_init(&thread[i]);
    hg_thread_mutex_init(&thread_mutex);
    hg_thread_cond_init(&thread_cond);

    for (i = 0; i < MERCURY_TESTING_NUM_THREADS; i++)
        hg_thread_create(&thread[i], thread_cb_cond, NULL);
    for (i = 0; i < MERCURY_TESTING_NUM_THREADS; i++)
        hg_thread_join(thread[i]);

    working = 1;

    for (i = 0; i < MERCURY_TESTING_NUM_THREADS; i++)
        hg_thread_create(&thread[i], thread_cb_cond_all, NULL);

    hg_thread_mutex_lock(&thread_mutex);
    working = 0;
    hg_thread_cond_broadcast(&thread_cond);
    hg_thread_mutex_unlock(&thread_mutex);

    for (i = 0; i < MERCURY_TESTING_NUM_THREADS; i++)
        hg_thread_join(thread[i]);

    return ret;
}
Exemple #4
0
/*---------------------------------------------------------------------------*/
na_class_t *
NA_Initialize(const char *info_string, na_bool_t listen)
{
    na_class_t *na_class = NULL;
    struct na_info *na_info = NULL;
    unsigned int plugin_index = 0;
    unsigned int plugin_count = 0;
    na_bool_t plugin_found = NA_FALSE;
    na_return_t ret;

    plugin_count = sizeof(na_class_info) / sizeof(na_class_info[0]) - 1;

    ret = na_info_parse(info_string, &na_info);
    if (ret != NA_SUCCESS) {
        NA_LOG_ERROR("Could not parse host string");
        goto done;
    }

#ifdef NA_DEBUG
    na_info_print(na_info);
#endif

    while (plugin_index < plugin_count) {
        na_bool_t verified = NA_FALSE;

        verified = na_class_info[plugin_index]->check_protocol(
                na_info->protocol_name);

        if (verified) {
            /* Take the first plugin that supports the protocol */
            if (!na_info->class_name) {
                plugin_found = NA_TRUE;
                break;
            }

            /* Otherwise try to use the plugin name */
            if (strcmp(na_class_info[plugin_index]->class_name,
                    na_info->class_name) == 0) {
                plugin_found = NA_TRUE;
                break;
            }
        }
        plugin_index++;
    }

    if (!plugin_found) {
        NA_LOG_ERROR("No suitable plugin was found");
        goto done;
    }

    /* Initialize lookup mutex */
    hg_thread_mutex_init(&na_addr_lookup_mutex_g);

    na_class = na_class_info[plugin_index]->initialize(na_info, listen);

done:
    na_info_free(na_info);
    return na_class;
}
Exemple #5
0
/*---------------------------------------------------------------------------*/
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;
}