示例#1
0
static int
test_bulk(struct na_test_params *params)
{
    na_tag_t bulk_tag = NA_TEST_BULK_TAG, ack_tag = NA_TEST_BULK_ACK_TAG;
    na_return_t na_ret;

    /* Register memory */
    printf("Registering local memory...\n");
    na_ret = NA_Mem_handle_create(params->network_class, params->bulk_buf,
            sizeof(int) * params->bulk_size, NA_MEM_READWRITE,
            &params->local_mem_handle);
    if (na_ret != NA_SUCCESS) {
        fprintf(stderr, "Could not create bulk handle\n");
        return EXIT_FAILURE;
    }

    na_ret = NA_Mem_register(params->network_class, params->local_mem_handle);
    if (na_ret != NA_SUCCESS) {
        fprintf(stderr, "Could not create bulk handle\n");
        return EXIT_FAILURE;
    }

    /* Serialize mem handle */
    printf("Serializing bulk memory handle...\n");
    na_ret = NA_Mem_handle_serialize(params->network_class, params->send_buf,
            params->send_buf_len, params->local_mem_handle);
    if (na_ret != NA_SUCCESS) {
        fprintf(stderr, "Could not serialize memory handle\n");
        return EXIT_FAILURE;
    }

    /* Recv completion ack */
    printf("Preposting recv of transfer ack...\n");
    na_ret = NA_Msg_recv_expected(params->network_class, params->context,
            &ack_expected_recv_cb, params, params->recv_buf,
            params->recv_buf_len, params->server_addr, ack_tag,
            NA_OP_ID_IGNORE);
    if (na_ret != NA_SUCCESS) {
        fprintf(stderr, "Could not start receive of acknowledgment\n");
        return EXIT_FAILURE;
    }

    /* Send mem handle */
    printf("Sending local memory handle...\n");
    na_ret = NA_Msg_send_expected(params->network_class, params->context,
            NULL, NULL, params->send_buf, params->send_buf_len,
            params->server_addr, bulk_tag, NA_OP_ID_IGNORE);
    if (na_ret != NA_SUCCESS) {
        fprintf(stderr, "Could not start send of memory handle\n");
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
示例#2
0
static int
test_bulk(struct na_test_params *params)
{
    na_return_t na_ret;
    int ret = EXIT_SUCCESS;

    /* Register memory */
    printf("Registering local memory...\n");
    na_ret = NA_Mem_handle_create(params->na_class, params->bulk_buf,
        sizeof(int) * params->bulk_size, NA_MEM_READWRITE,
        &params->local_mem_handle);
    if (na_ret != NA_SUCCESS) {
        NA_LOG_ERROR("Could not create NA memory handle");
        ret = EXIT_FAILURE;
        goto done;
    }

    na_ret = NA_Mem_register(params->na_class, params->local_mem_handle);
    if (na_ret != NA_SUCCESS) {
        NA_LOG_ERROR("Could not register NA memory handle");
        ret = EXIT_FAILURE;
        goto done;
    }

    /* Serialize mem handle */
    printf("Serializing bulk memory handle...\n");
    na_ret = NA_Mem_handle_serialize(params->na_class, params->send_buf,
        params->send_buf_len, params->local_mem_handle);
    if (na_ret != NA_SUCCESS) {
        NA_LOG_ERROR("Could not serialize memory handle");
        ret = EXIT_FAILURE;
        goto done;
    }

    /* Recv completion ack */
    printf("Preposting recv of transfer ack...\n");
    na_ret = NA_Msg_recv_expected(params->na_class, params->context,
        &ack_expected_recv_cb, params, params->recv_buf, params->recv_buf_len,
        params->recv_buf_plugin_data, params->server_addr, 0,
        NA_TEST_BULK_ACK_TAG, NA_OP_ID_IGNORE);
    if (na_ret != NA_SUCCESS) {
        NA_LOG_ERROR("Could not start receive of ack");
        ret = EXIT_FAILURE;
        goto done;
    }

    /* Send mem handle */
    printf("Sending local memory handle...\n");
    na_ret = NA_Msg_send_expected(params->na_class, params->context, NULL,
        NULL, params->send_buf, params->send_buf_len,
        params->send_buf_plugin_data, params->server_addr, 0,
        NA_TEST_BULK_TAG, NA_OP_ID_IGNORE);
    if (na_ret != NA_SUCCESS) {
        NA_LOG_ERROR("Could not start send of memory handle");
        ret = EXIT_FAILURE;
        goto done;
    }

done:
    return ret;
}
示例#3
0
/*---------------------------------------------------------------------------*/
static hg_return_t
hg_bulk_create(struct hg_class *hg_class, hg_uint32_t count,
    void **buf_ptrs, const hg_size_t *buf_sizes, hg_uint8_t flags,
    struct hg_bulk **hg_bulk_ptr)
{
    struct hg_bulk *hg_bulk = NULL;
    hg_return_t ret = HG_SUCCESS;
    na_return_t na_ret;
    na_class_t *na_class = HG_Core_class_get_na(hg_class);
    hg_bool_t use_register_segments = (hg_bool_t)
        (na_class->mem_handle_create_segments && count > 1);
    unsigned int i;

    hg_bulk = (struct hg_bulk *) malloc(sizeof(struct hg_bulk));
    if (!hg_bulk) {
        HG_LOG_ERROR("Could not allocate handle");
        ret = HG_NOMEM_ERROR;
        goto done;
    }
    hg_bulk->hg_class = hg_class;
    hg_bulk->total_size = 0;
    hg_bulk->segment_count = count;
    hg_bulk->segments = NULL;
    hg_bulk->na_mem_handle_count = (use_register_segments) ? 1 : count;
    hg_bulk->na_mem_handles = NULL;
    hg_bulk->segment_published = HG_FALSE;
    hg_bulk->segment_alloc = (!buf_ptrs);
    hg_bulk->flags = flags;
    hg_bulk->eager_mode = HG_FALSE;
    hg_atomic_set32(&hg_bulk->ref_count, 1);

    /* Allocate segments */
    hg_bulk->segments = (struct hg_bulk_segment *) malloc(
        hg_bulk->segment_count * sizeof(struct hg_bulk_segment));
    if (!hg_bulk->segments) {
        HG_LOG_ERROR("Could not allocate segment array");
        ret = HG_NOMEM_ERROR;
        goto done;
    }
    memset(hg_bulk->segments, 0,
           hg_bulk->segment_count * sizeof(struct hg_bulk_segment));

    /* Loop over the list of segments */
    for (i = 0; i < hg_bulk->segment_count; i++) {
        hg_bulk->segments[i].size = buf_sizes[i];
        hg_bulk->total_size += hg_bulk->segments[i].size;

        if (buf_ptrs)
            hg_bulk->segments[i].address = (hg_ptr_t) buf_ptrs[i];
        else {
            /* Use calloc to avoid uninitialized memory used for transfer */
            hg_bulk->segments[i].address = (hg_ptr_t) calloc(
                hg_bulk->segments[i].size, sizeof(char));
            if (!hg_bulk->segments[i].address) {
                HG_LOG_ERROR("Could not allocate segment");
                ret = HG_NOMEM_ERROR;
                goto done;
            }
        }
    }

    /* Allocate NA memory handles */
    hg_bulk->na_mem_handles = (na_mem_handle_t *) malloc(
        hg_bulk->na_mem_handle_count * sizeof(na_mem_handle_t));
    if (!hg_bulk->na_mem_handles) {
        HG_LOG_ERROR("Could not allocate mem handle array");
        ret = HG_NOMEM_ERROR;
        goto done;
    }
    for (i = 0; i < hg_bulk->na_mem_handle_count; i++)
        hg_bulk->na_mem_handles[i] = NA_MEM_HANDLE_NULL;


    /* Create and register NA memory handles */
    for (i = 0; i < hg_bulk->na_mem_handle_count; i++) {
        /* na_mem_handle_count always <= segment_count */
        if (!hg_bulk->segments[i].address)
            continue;

        if (use_register_segments) {
            struct na_segment *na_segments =
                (struct na_segment *) hg_bulk->segments;
            na_size_t na_segment_count = (na_size_t) hg_bulk->segment_count;
            na_ret = NA_Mem_handle_create_segments(na_class, na_segments,
                na_segment_count, flags, &hg_bulk->na_mem_handles[i]);
            if (na_ret != NA_SUCCESS) {
                HG_LOG_ERROR("NA_Mem_handle_create_segments failed");
                ret = HG_NA_ERROR;
                goto done;
            }
        } else {
            na_ret = NA_Mem_handle_create(na_class,
                (void *) hg_bulk->segments[i].address,
                hg_bulk->segments[i].size, flags, &hg_bulk->na_mem_handles[i]);
            if (na_ret != NA_SUCCESS) {
                HG_LOG_ERROR("NA_Mem_handle_create failed");
                ret = HG_NA_ERROR;
                goto done;
            }
        }
        /* Register segment */
        na_ret = NA_Mem_register(na_class, hg_bulk->na_mem_handles[i]);
        if (na_ret != NA_SUCCESS) {
            HG_LOG_ERROR("NA_Mem_register failed");
            ret = HG_NA_ERROR;
            goto done;
        }
    }

    *hg_bulk_ptr = hg_bulk;

done:
    if (ret != HG_SUCCESS) {
        hg_bulk_free(hg_bulk);
    }
    return ret;
}