Exemple #1
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;
}
/*---------------------------------------------------------------------------*/
HG_TEST_RPC_CB(hg_test_bulk_write, handle)
{
    struct hg_info *hg_info = NULL;
    hg_bulk_t origin_bulk_handle = HG_BULK_NULL;
    hg_bulk_t local_bulk_handle = HG_BULK_NULL;
    struct hg_test_bulk_args *bulk_args = NULL;
    bulk_write_in_t in_struct;
    hg_return_t ret = HG_SUCCESS;
    int fildes;

    hg_op_id_t hg_bulk_op_id;

    bulk_args = (struct hg_test_bulk_args *) malloc(
            sizeof(struct hg_test_bulk_args));

    /* Keep handle to pass to callback */
    bulk_args->handle = handle;

    /* Get info from handle */
    hg_info = HG_Get_info(handle);

    /* Get input parameters and data */
    ret = HG_Get_input(handle, &in_struct);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not get input\n");
        return ret;
    }

    /* Get parameters */
    fildes = in_struct.fildes;
    origin_bulk_handle = in_struct.bulk_handle;

    bulk_args->nbytes = HG_Bulk_get_size(origin_bulk_handle);
    bulk_args->fildes = fildes;

    /* Create a new block handle to read the data */
    HG_Bulk_create(hg_info->hg_class, 1, NULL, (hg_size_t *) &bulk_args->nbytes,
        HG_BULK_READWRITE, &local_bulk_handle);

    /* Pull bulk data */
    ret = HG_Bulk_transfer(hg_info->context, hg_test_bulk_transfer_cb,
        bulk_args, HG_BULK_PULL, hg_info->addr, origin_bulk_handle, 0,
        local_bulk_handle, 0, bulk_args->nbytes, &hg_bulk_op_id);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not read bulk data\n");
        return ret;
    }

    /* Test HG_Bulk_Cancel() */
    if (fildes < 0) {
        ret = HG_Bulk_cancel(hg_bulk_op_id);
        if (ret != HG_SUCCESS){
            fprintf(stderr, "Could not cancel bulk data\n");
            return ret;
        }
    }

    HG_Free_input(handle, &in_struct);
    return ret;
}
Exemple #3
0
/**
 * The routine that sets up the routines that actually do the work.
 * This 'handle' parameter is the only value passed to this callback, but
 * Mercury routines allow us to query information about the context in which
 * we are called. */
static hg_return_t
snappy_compress_cb(hg_handle_t handle)
{
    struct snappy_transfer_args *snappy_transfer_args;
    size_t input_length;

    snappy_transfer_args = (struct snappy_transfer_args *)
            malloc(sizeof(struct snappy_transfer_args));
    snappy_transfer_args->handle = handle;

    /* Get input parameters sent on origin through on HG_Forward() */
    HG_Get_input(handle, &snappy_transfer_args->snappy_compress_input);

    /* Now set up the bulk transfer and get the input length */
    input_length = HG_Bulk_get_size(
            snappy_transfer_args->snappy_compress_input.input_bulk_handle);

    /* The bulk 'handle' is basically a pointer, with the addition that 'handle'
     * could refer to more than one memory region. */
    HG_Bulk_create(HG_Get_info(handle)->hg_bulk_class, 1, NULL, &input_length,
	    HG_BULK_READWRITE, &snappy_transfer_args->local_input_bulk_handle);

    /* Pull data from origin's memory into our own */
    /* Another way to do this is via HG_Bulk_access, which would allow mercury,
     * if "co-resident" to avoid a copy of data */
    HG_Bulk_transfer(HG_Get_info(handle)->bulk_context,
            snappy_pull_cb, snappy_transfer_args,
            HG_BULK_PULL, HG_Get_info(handle)->addr,
            snappy_transfer_args->snappy_compress_input.input_bulk_handle, 0, /* origin */
            snappy_transfer_args->local_input_bulk_handle, 0, /* local */
            input_length, HG_OP_ID_IGNORE);

    return HG_SUCCESS;
}
Exemple #4
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;
}
Exemple #5
0
static hg_return_t
snappy_pull_cb(const struct hg_bulk_cb_info *hg_bulk_cb_info)
{
    struct snappy_transfer_args *snappy_transfer_args =
            (struct snappy_transfer_args *) hg_bulk_cb_info->arg;
    hg_return_t ret = HG_SUCCESS;
    void *input;
    size_t input_length;
    size_t source_length = HG_Bulk_get_size(snappy_transfer_args->local_input_bulk_handle);

    /* Get pointer to input buffer from local handle */
    HG_Bulk_access(hg_bulk_cb_info->local_handle, 0, source_length,
            HG_BULK_READ_ONLY, 1, &input, &input_length, NULL);
    printf("Transferred input buffer of length: %zu\n", input_length);
    print_buf(20, (int *) input);

    /* Allocate compressed buffer for compressing input data */
    snappy_transfer_args->compressed_length = snappy_max_compressed_length(input_length);
    snappy_transfer_args->compressed = malloc(snappy_transfer_args->compressed_length);

    /* Compress data */
    printf("Compressing buffer...\n");
    snappy_transfer_args->ret = snappy_compress(input, input_length,
            snappy_transfer_args->compressed, &snappy_transfer_args->compressed_length);
    printf("Return value of snappy_compress is: %d\n", snappy_transfer_args->ret);
    printf("Compressed buffer length is: %zu\n", snappy_transfer_args->compressed_length);
    print_buf(5, (int *) snappy_transfer_args->compressed);

    /* Free bulk handles */
    HG_Bulk_free(snappy_transfer_args->local_input_bulk_handle);

    if (snappy_validate_compressed_buffer(snappy_transfer_args->compressed,
            snappy_transfer_args->compressed_length) == SNAPPY_OK) {
        printf("Compressed buffer validated: compressed successfully\n");
    }

    /* Now set up bulk transfer for "push to origin" callback */
    HG_Bulk_create(HG_Get_info(snappy_transfer_args->handle)->hg_bulk_class, 1,
            &snappy_transfer_args->compressed, &snappy_transfer_args->compressed_length,
            HG_BULK_WRITE_ONLY, &snappy_transfer_args->local_compressed_bulk_handle);

    HG_Bulk_transfer(HG_Get_info(snappy_transfer_args->handle)->bulk_context,
            snappy_push_cb, snappy_transfer_args,
            HG_BULK_PUSH, HG_Get_info(snappy_transfer_args->handle)->addr,
            snappy_transfer_args->snappy_compress_input.compressed_bulk_handle, 0, /* origin */
            snappy_transfer_args->local_compressed_bulk_handle, 0, /* local */
            snappy_transfer_args->compressed_length, HG_OP_ID_IGNORE);

    return ret;
}
/*---------------------------------------------------------------------------*/
HG_TEST_RPC_CB(hg_test_posix_write, handle)
{
    hg_return_t ret = HG_SUCCESS;

    struct hg_info *hg_info = NULL;
    hg_bulk_t origin_bulk_handle = HG_BULK_NULL;
    hg_bulk_t local_bulk_handle = HG_BULK_NULL;
    struct hg_test_bulk_args *bulk_args = NULL;
    bulk_write_in_t in_struct;

    bulk_args = (struct hg_test_bulk_args *) malloc(
            sizeof(struct hg_test_bulk_args));

    /* Keep handle to pass to callback */
    bulk_args->handle = handle;

    /* Get info from handle */
    hg_info = HG_Get_info(handle);

    /* Get input struct */
    ret = HG_Get_input(handle, &in_struct);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not get input struct\n");
        return ret;
    }

    origin_bulk_handle = in_struct.bulk_handle;

    /* Create a new block handle to read the data */
    bulk_args->nbytes = HG_Bulk_get_size(origin_bulk_handle);
    bulk_args->fildes = in_struct.fildes;

    /* Create a new bulk handle to read the data */
    HG_Bulk_create(hg_info->hg_class, 1, NULL, (hg_size_t *) &bulk_args->nbytes,
            HG_BULK_READWRITE, &local_bulk_handle);

    /* Pull bulk data */
    ret = HG_Bulk_transfer(hg_info->context, hg_test_posix_write_transfer_cb,
            bulk_args, HG_BULK_PULL, hg_info->addr, origin_bulk_handle, 0,
            local_bulk_handle, 0, bulk_args->nbytes, HG_OP_ID_IGNORE);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not read bulk data\n");
        return ret;
    }

    HG_Free_input(handle, &in_struct);
    return ret;
}
static hg_return_t lookup_cb(const struct hg_cb_info *callback_info)
{
    na_addr_t svr_addr = callback_info->info.lookup.addr;
    my_rpc_in_t in;
    struct hg_info *hgi;
    int ret;
    struct my_rpc_state *my_rpc_state_p;

    assert(callback_info->ret == 0);

    /* set up state structure */
    my_rpc_state_p = malloc(sizeof(*my_rpc_state_p));
    my_rpc_state_p->size = 512;
    /* This includes allocating a src buffer for bulk transfer */
    my_rpc_state_p->buffer = calloc(1, 512);
    assert(my_rpc_state_p->buffer);
    sprintf((char*)my_rpc_state_p->buffer, "Hello world!\n");
    my_rpc_state_p->value = *((int*)callback_info->arg);
    free(callback_info->arg);

    /* create create handle to represent this rpc operation */
    hg_engine_create_handle(svr_addr, my_rpc_id, &my_rpc_state_p->handle);

    /* register buffer for rdma/bulk access by server */
    hgi = HG_Get_info(my_rpc_state_p->handle);
    assert(hgi);
    ret = HG_Bulk_create(hgi->hg_class, 1, &my_rpc_state_p->buffer, &my_rpc_state_p->size,
        HG_BULK_READ_ONLY, &in.bulk_handle);
    my_rpc_state_p->bulk_handle = in.bulk_handle;
    assert(ret == 0);

    /* Send rpc. Note that we are also transmitting the bulk handle in the
     * input struct.  It was set above. 
     */ 
    in.input_val = my_rpc_state_p->value;
    ret = HG_Forward(my_rpc_state_p->handle, my_rpc_cb, my_rpc_state_p, &in);
    assert(ret == 0);
    (void)ret;

    return(NA_SUCCESS);
}
/* HG_svrec_add_ult() -- handler
 */
void HG_svrec_add_ult(hg_handle_t h) {
    int ret;
    sv_rec_remove_in_t in;
    sv_rec_remove_out_t out;
    struct hg_info *hgi;
    margo_instance_id mid;
    hg_size_t sz;
    hg_bulk_t lbh; /* local bulk handle */
    void *p;

    ret = HG_Get_input(h, &in);
    assert(ret == HG_SUCCESS);

    hgi = HG_Get_info(h);
    mid = margo_hg_class_to_instance(hgi->hg_class);

    assert(rec_list != NULL);
    assert(rec_ct < rec_list_sz);
    p = &rec_list[rec_ct];
    sz = sizeof(hg_sv_rec_t);
    ret = HG_Bulk_create(hgi->hg_class, 1, (void **) &p, &sz,
			 HG_BULK_READWRITE, &lbh);
    assert(ret == HG_SUCCESS);

    ret = margo_bulk_transfer(mid, HG_BULK_PULL, hgi->addr, in.b, 0,
			      lbh, 0, sz);
    assert(!ret);

    printf("  added %s\n", rec_list[rec_ct].addr);
    rec_ct++;

    out.ret = 0;
    ret = margo_respond(mid, h, &out);
    assert(!ret);

    ret = HG_Destroy(h);
    assert(ret == HG_SUCCESS);

    return;
}
Exemple #9
0
int main(int argc, char *argv[])
{
    hg_class_t *hg_class = NULL;
    hg_context_t *context = NULL;
    hg_request_class_t *request_class = NULL;
    hg_request_t *request = NULL;
    hg_handle_t handle;
    hg_addr_t addr;

    bulk_write_in_t bulk_write_in_struct;

    int fildes = 12345;
    int *bulk_buf = NULL;
    void *buf_ptr[1];
    size_t count =  (1024 * 1024 * MERCURY_TESTING_BUFFER_SIZE) / sizeof(int);
    size_t bulk_size = count * sizeof(int);
    hg_bulk_t bulk_handle = HG_BULK_NULL;

    hg_return_t hg_ret;
    size_t i;

    /* Prepare bulk_buf */
    bulk_buf = (int*) malloc(bulk_size);
    for (i = 0; i < count; i++) {
        bulk_buf[i] = i;
    }
    *buf_ptr = bulk_buf;

    /* Initialize the interface (for convenience, shipper_test_client_init
     * initializes the network interface with the selected plugin)
     */
    hg_class = HG_Test_client_init(argc, argv, &addr, NULL, &context,
            &request_class);

    request = hg_request_create(request_class);

    hg_ret = HG_Create(context, addr, hg_test_bulk_write_id_g, &handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not start call\n");
        return EXIT_FAILURE;
    }

    /* Register memory */
    hg_ret = HG_Bulk_create(hg_class, 1, buf_ptr, &bulk_size,
            HG_BULK_READ_ONLY, &bulk_handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not create bulk data handle\n");
        return EXIT_FAILURE;
    }

    /* Fill input structure */
    bulk_write_in_struct.fildes = fildes;
    bulk_write_in_struct.bulk_handle = bulk_handle;

    /* Forward call to remote addr and get a new request */
    printf("Forwarding bulk_write, op id: %u...\n", hg_test_bulk_write_id_g);
    hg_ret = HG_Forward(handle, hg_test_bulk_forward_cb, request,
            &bulk_write_in_struct);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not forward call\n");
        return EXIT_FAILURE;
    }

    hg_request_wait(request, HG_MAX_IDLE_TIME, NULL);

    /* Free memory handle */
    hg_ret = HG_Bulk_free(bulk_handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not free bulk data handle\n");
        return EXIT_FAILURE;
    }

    /* Complete */
    hg_ret = HG_Destroy(handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not complete\n");
        return EXIT_FAILURE;
    }

    hg_request_destroy(request);

    HG_Test_finalize(hg_class);

    /* Free bulk data */
    free(bulk_buf);

    return EXIT_SUCCESS;
}
Exemple #10
0
int main(int argc, char *argv[])
{
    hg_class_t *hg_class = NULL;
    hg_context_t *context = NULL;
    hg_request_class_t *request_class = NULL;
    hg_request_t *request = NULL;
    hg_handle_t handle;
    hg_addr_t addr;

    bulk_write_in_t bulk_write_in_struct;

    int fildes = 12345;
    void **bulk_buf;
    size_t *bulk_sizes;
    size_t bulk_size = 1024 * 1024 * MERCURY_TESTING_BUFFER_SIZE / sizeof(int);
    size_t bulk_size_x = 16;
    size_t bulk_size_y = 0;
    size_t *bulk_size_y_var = NULL;
    hg_bulk_t bulk_handle = HG_BULK_NULL;

    hg_return_t hg_ret;
    size_t i, j;

    /* Initialize the interface (for convenience, shipper_test_client_init
     * initializes the network interface with the selected plugin)
     */
    hg_class = HG_Test_client_init(argc, argv, &addr, NULL, &context,
            &request_class);

    request = hg_request_create(request_class);

    hg_ret = HG_Create(context, addr, hg_test_bulk_seg_write_id_g, &handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not start call\n");
        return EXIT_FAILURE;
    }

    /* This will create a list of variable size segments */
    if (na_test_use_variable_g) {
        printf("Using variable size segments!\n");
        /* bulk_size_x >= 2 */
        /* 524288 + 262144 + 131072 + 65536 + 32768 + 16384 + 8192 + 8192 */
        bulk_size_x = 8;
        bulk_size_y_var = (size_t*) malloc(bulk_size_x * sizeof(size_t));
        bulk_size_y_var[0] = bulk_size / 2;
        for (i = 1; i < bulk_size_x - 1; i++) {
            bulk_size_y_var[i] = bulk_size_y_var[i-1] / 2;
        }
        bulk_size_y_var[bulk_size_x - 1] = bulk_size_y_var[bulk_size_x - 2];
    }
    /* This will use an extra encoding buffer */
    else if (na_test_use_extra_g) {
        printf("Using large number of segments!\n");
        bulk_size_x = 1024;
        bulk_size_y = bulk_size / bulk_size_x;
    }
    else {
        /* This will create a list of fixed size segments */
        bulk_size_y = bulk_size / bulk_size_x;
    }

    /* Prepare bulk_buf */
    bulk_buf = (void **) malloc(bulk_size_x * sizeof(void *));
    bulk_sizes = (size_t *) malloc(bulk_size_x * sizeof(size_t));
    if (bulk_size_y_var) {
        int val = 0;
        for (i = 0; i < bulk_size_x; i++) {
            bulk_sizes[i] = bulk_size_y_var[i] * sizeof(int);
            bulk_buf[i] = malloc(bulk_sizes[i]);
            for (j = 0; j < bulk_size_y_var[i]; j++) {
                ((int **) (bulk_buf))[i][j] = val;
                val++;
            }
        }
    } else {
        for (i = 0; i < bulk_size_x; i++) {
            bulk_sizes[i] = bulk_size_y * sizeof(int);
            bulk_buf[i] = malloc(bulk_sizes[i]);
            for (j = 0; j < bulk_size_y; j++) {
                ((int **) (bulk_buf))[i][j] = i * bulk_size_y + j;
            }
        }
    }

    /* Register memory */
    hg_ret = HG_Bulk_create(hg_class, bulk_size_x, bulk_buf, bulk_sizes,
            HG_BULK_READ_ONLY, &bulk_handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not create bulk data handle\n");
        return EXIT_FAILURE;
    }

    free(bulk_sizes);
    bulk_sizes = NULL;
    if (bulk_size_y_var) free(bulk_size_y_var);
    bulk_size_y_var = NULL;

    /* Fill input structure */
    bulk_write_in_struct.fildes = fildes;
    bulk_write_in_struct.bulk_handle = bulk_handle;

    /* Forward call to remote addr and get a new request */
    printf("Forwarding bulk_write, op id: %u...\n", hg_test_bulk_seg_write_id_g);
    hg_ret = HG_Forward(handle, hg_test_bulk_seg_forward_cb, request,
            &bulk_write_in_struct);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not forward call\n");
        return EXIT_FAILURE;
    }

    hg_request_wait(request, HG_MAX_IDLE_TIME, NULL);

    /* Free memory handle */
    hg_ret = HG_Bulk_free(bulk_handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not free bulk data handle\n");
        return EXIT_FAILURE;
    }

    /* Complete */
    hg_ret = HG_Destroy(handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not complete\n");
        return EXIT_FAILURE;
    }

    hg_request_destroy(request);

    HG_Test_finalize(hg_class);

    /* Free bulk_buf */
    for (i = 0; i < bulk_size_x; i++) {
        free(bulk_buf[i]);
        bulk_buf[i] = NULL;
    }
    free(bulk_buf);
    bulk_buf = NULL;

    return EXIT_SUCCESS;
}
Exemple #11
0
/*---------------------------------------------------------------------------*/
HG_TEST_RPC_CB(hg_test_posix_read, handle)
{
    hg_return_t ret = HG_SUCCESS;

    struct hg_info *hg_info = NULL;
    hg_bulk_t origin_bulk_handle = HG_BULK_NULL;
    hg_bulk_t local_bulk_handle = HG_BULK_NULL;
    struct hg_test_bulk_args *bulk_args = NULL;
    bulk_write_in_t in_struct;

    void *buf;
    ssize_t read_ret;

    /* for debug */
    int i;
    const int *buf_ptr;

    bulk_args = (struct hg_test_bulk_args *) malloc(
            sizeof(struct hg_test_bulk_args));

    /* Keep handle to pass to callback */
    bulk_args->handle = handle;

    /* Get info from handle */
    hg_info = HG_Get_info(handle);

    /* Get input struct */
    ret = HG_Get_input(handle, &in_struct);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not get input struct\n");
        return ret;
    }

    origin_bulk_handle = in_struct.bulk_handle;

    /* Create a new block handle to read the data */
    bulk_args->nbytes = HG_Bulk_get_size(origin_bulk_handle);
    bulk_args->fildes = in_struct.fildes;

    /* Create a new bulk handle to read the data */
    HG_Bulk_create(hg_info->hg_class, 1, NULL, (hg_size_t *) &bulk_args->nbytes,
            HG_BULK_READ_ONLY, &local_bulk_handle);

    /* Call bulk_write */
    HG_Bulk_access(local_bulk_handle, 0, bulk_args->nbytes, HG_BULK_READWRITE,
            1, &buf, NULL, NULL);

    printf("Calling read with fd: %d\n", in_struct.fildes);
    read_ret = read(in_struct.fildes, buf, bulk_args->nbytes);

    /* Check bulk buf */
    buf_ptr = (const int*) buf;
    for (i = 0; i < (int)(bulk_args->nbytes / sizeof(int)); i++) {
        if (buf_ptr[i] != i) {
            printf("Error detected after read, buf[%d] = %d, was expecting %d!\n", i, buf_ptr[i], i);
            break;
        }
    }

    /* Fill output structure */
    bulk_args->ret = read_ret;

    /* Push bulk data */
    ret = HG_Bulk_transfer(hg_info->context, hg_test_posix_read_transfer_cb,
            bulk_args, HG_BULK_PUSH, hg_info->addr, origin_bulk_handle, 0,
            local_bulk_handle, 0, bulk_args->nbytes, HG_OP_ID_IGNORE);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not read bulk data\n");
        return ret;
    }

    HG_Free_input(handle, &in_struct);
    return ret;
}
Exemple #12
0
/*---------------------------------------------------------------------------*/
HG_TEST_RPC_CB(hg_test_bulk_seg_write, handle)
{
    struct hg_info *hg_info = NULL;
    hg_bulk_t origin_bulk_handle = HG_BULK_NULL;
    hg_bulk_t local_bulk_handle = HG_BULK_NULL;
    struct hg_test_bulk_args *bulk_args = NULL;
    size_t nbytes_read;
    size_t offset;
    hg_return_t ret = HG_SUCCESS;
    bulk_write_in_t in_struct;

    bulk_args = (struct hg_test_bulk_args *) malloc(
            sizeof(struct hg_test_bulk_args));

    /* Keep handle to pass to callback */
    bulk_args->handle = handle;

    /* Get info from handle */
    hg_info = HG_Get_info(handle);

    /* Get input parameters and data */
    ret = HG_Get_input(handle, &in_struct);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not get input\n");
        return ret;
    }

    /* Get parameters */
    origin_bulk_handle = in_struct.bulk_handle;
    hg_atomic_set32(&bulk_args->completed_transfers, 0);

    /* Create a new block handle to read the data */
    bulk_args->nbytes = HG_Bulk_get_size(origin_bulk_handle);
    bulk_args->fildes = in_struct.fildes;

    /* For testing purposes try to read the data in two blocks of different sizes */
    nbytes_read = bulk_args->nbytes / 2 + 16;

    printf("Start reading first chunk of %lu bytes...\n", nbytes_read);

    /* Create a new bulk handle to read the data */
    HG_Bulk_create(hg_info->hg_class, 1, NULL, (hg_size_t *) &bulk_args->nbytes,
            HG_BULK_READWRITE, &local_bulk_handle);

    /* Pull bulk data */
    ret = HG_Bulk_transfer(hg_info->context, hg_test_bulk_seg_transfer_cb,
            bulk_args, HG_BULK_PULL, hg_info->addr, origin_bulk_handle, 0,
            local_bulk_handle, 0, nbytes_read, HG_OP_ID_IGNORE);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not read bulk data\n");
        return ret;
    }

    offset = nbytes_read;
    nbytes_read = bulk_args->nbytes - nbytes_read;

    printf("Start reading second chunk of %lu bytes...\n", nbytes_read);

    ret = HG_Bulk_transfer(hg_info->context, hg_test_bulk_seg_transfer_cb,
            bulk_args, HG_BULK_PULL, hg_info->addr, origin_bulk_handle, offset,
            local_bulk_handle, offset, nbytes_read, HG_OP_ID_IGNORE);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not read bulk data\n");
        return ret;
    }

    HG_Free_input(handle, &in_struct);
    return ret;
}
Exemple #13
0
static hg_return_t
measure_bulk_transfer(struct hg_test_info *hg_test_info, size_t total_size,
    unsigned int nhandles)
{
    bulk_write_in_t in_struct;
    char *bulk_buf;
    void **buf_ptrs;
    size_t *buf_sizes;
    hg_bulk_t bulk_handle = HG_BULK_NULL;
    size_t nbytes = total_size;
    double nmbytes = (double) total_size / (1024 * 1024);
    size_t loop = (total_size > LARGE_SIZE) ? MERCURY_TESTING_MAX_LOOP :
        MERCURY_TESTING_MAX_LOOP * 10;
    size_t skip = (total_size > LARGE_SIZE) ? LARGE_SKIP : SMALL_SKIP;
    hg_handle_t *handles = NULL;
    hg_request_t *request;
    struct hg_test_perf_args args;
    size_t avg_iter;
    double time_read = 0, read_bandwidth;
    hg_return_t ret = HG_SUCCESS;
    size_t i;

    /* Prepare bulk_buf */
    bulk_buf = malloc(nbytes);
    for (i = 0; i < nbytes; i++)
        bulk_buf[i] = 1;
    buf_ptrs = (void **) &bulk_buf;
    buf_sizes = &nbytes;

    /* Create handles */
    handles = malloc(nhandles * sizeof(hg_handle_t));
    for (i = 0; i < nhandles; i++) {
        ret = HG_Create(hg_test_info->context, hg_test_info->target_addr,
            hg_test_perf_bulk_read_id_g, &handles[i]);
        if (ret != HG_SUCCESS) {
            fprintf(stderr, "Could not start call\n");
            goto done;
        }
    }

    request = hg_request_create(hg_test_info->request_class);
    hg_atomic_init32(&args.op_completed_count, 0);
    args.op_count = nhandles;
    args.request = request;

    /* Register memory */
    ret = HG_Bulk_create(hg_test_info->hg_class, 1, buf_ptrs,
        (hg_size_t *) buf_sizes, HG_BULK_READWRITE, &bulk_handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not create bulk data handle\n");
        goto done;
    }

    /* Fill input structure */
    in_struct.fildes = 0;
    in_struct.bulk_handle = bulk_handle;

    /* Warm up for bulk data */
    for (i = 0; i < skip; i++) {
        unsigned int j;

        for (j = 0; j < nhandles; j++) {
            ret = HG_Forward(handles[j], hg_test_perf_forward_cb, &args, &in_struct);
            if (ret != HG_SUCCESS) {
                fprintf(stderr, "Could not forward call\n");
                goto done;
            }
        }

        hg_request_wait(request, HG_MAX_IDLE_TIME, NULL);
        hg_request_reset(request);
        hg_atomic_set32(&args.op_completed_count, 0);
    }

    NA_Test_barrier(&hg_test_info->na_test_info);

    /* Bulk data benchmark */
    for (avg_iter = 0; avg_iter < loop; avg_iter++) {
        hg_time_t t1, t2;
        unsigned int j;

        hg_time_get_current(&t1);

        for (j = 0; j < nhandles; j++) {
            ret = HG_Forward(handles[j], hg_test_perf_forward_cb, &args, &in_struct);
            if (ret != HG_SUCCESS) {
                fprintf(stderr, "Could not forward call\n");
                goto done;
            }
        }

        hg_request_wait(request, HG_MAX_IDLE_TIME, NULL);
        NA_Test_barrier(&hg_test_info->na_test_info);
        hg_time_get_current(&t2);
        time_read += hg_time_to_double(hg_time_subtract(t2, t1));

        hg_request_reset(request);
        hg_atomic_set32(&args.op_completed_count, 0);

#ifdef MERCURY_TESTING_PRINT_PARTIAL
        read_bandwidth = nmbytes
            * (double) (nhandles * (avg_iter + 1) *
                (unsigned int) hg_test_info->na_test_info.mpi_comm_size)
            / time_read;

        /* At this point we have received everything so work out the bandwidth */
        if (hg_test_info->na_test_info.mpi_comm_rank == 0)
            fprintf(stdout, "%-*d%*.*f\r", 10, (int) nbytes, NWIDTH,
                NDIGITS, read_bandwidth);
#endif
#ifdef MERCURY_TESTING_HAS_VERIFY_DATA
        for (i = 0; i < nbytes; i++) {
            if (bulk_buf[i] != (char) i) {
                printf("Error detected in bulk transfer, buf[%d] = %d, "
                    "was expecting %d!\n", (int) i, (char) bulk_buf[i],
                    (char) i);
                break;
            }
        }
#endif
    }
#ifndef MERCURY_TESTING_PRINT_PARTIAL
    read_bandwidth = nmbytes
        * (double) (nhandles * loop *
            (unsigned int) hg_test_info->na_test_info.mpi_comm_size)
        / time_read;

    /* At this point we have received everything so work out the bandwidth */
    if (hg_test_info->na_test_info.mpi_comm_rank == 0)
        fprintf(stdout, "%-*d%*.*f", 10, (int) nbytes, NWIDTH, NDIGITS,
            read_bandwidth);
#endif
    if (hg_test_info->na_test_info.mpi_comm_rank == 0) fprintf(stdout, "\n");

    /* Free memory handle */
    ret = HG_Bulk_free(bulk_handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not free bulk data handle\n");
        goto done;
    }

    /* Complete */
    hg_request_destroy(request);
    for (i = 0; i < nhandles; i++) {
        ret = HG_Destroy(handles[i]);
        if (ret != HG_SUCCESS) {
            fprintf(stderr, "Could not complete\n");
            goto done;
        }
    }

done:
    free(bulk_buf);
    free(handles);
    return ret;
}
Exemple #14
0
static hg_return_t
measure_bulk_transfer(hg_class_t *hg_class, hg_context_t *context,
        na_addr_t addr, hg_request_class_t *request_class)
{
    bulk_write_in_t in_struct;

    int *bulk_buf;
    void *buf_ptr[1];
    size_t count = (1024 * 1024 * MERCURY_TESTING_BUFFER_SIZE) / sizeof(int);
    hg_bulk_t bulk_handle = HG_BULK_NULL;
    size_t nbytes;
    double nmbytes;
    hg_handle_t handle;

    int avg_iter;
    double time_read = 0, min_time_read = 0, max_time_read = 0;

    struct hg_info *hg_info = NULL;

    hg_return_t ret = HG_SUCCESS;
    size_t i;

    /* Prepare bulk_buf */
    nbytes = count * sizeof(int);
    nmbytes = (double) nbytes / (1024 * 1024);
    if (na_test_comm_rank_g == 0) {
        printf("# Reading Bulk Data (%f MB) with %d client(s) -- loop %d time(s)\n",
                nmbytes, na_test_comm_size_g, MERCURY_TESTING_MAX_LOOP);
    }

    bulk_buf = (int *) malloc(nbytes);
    for (i = 0; i < count; i++) {
        bulk_buf[i] = (int) i;
    }
    *buf_ptr = bulk_buf;

    ret = HG_Create(hg_class, context, addr, hg_test_perf_bulk_id_g,
            &handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not start call\n");
        goto done;
    }

    /* Must get info to retrieve bulk class if not provided by user */
    hg_info = HG_Get_info(handle);

    /* Register memory */
    ret = HG_Bulk_create(hg_info->hg_bulk_class, 1, buf_ptr, &nbytes,
            HG_BULK_READ_ONLY, &bulk_handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not create bulk data handle\n");
        goto done;
    }

    /* Fill input structure */
    in_struct.fildes = 0;
    in_struct.bulk_handle = bulk_handle;

    if (na_test_comm_rank_g == 0) printf("# Warming up...\n");

    /* Warm up for bulk data */
    for (i = 0; i < BULK_SKIP; i++) {
        hg_request_t *request;

        request = hg_request_create(request_class);

        ret = HG_Forward(handle, hg_test_perf_forward_cb, request, &in_struct);
        if (ret != HG_SUCCESS) {
            fprintf(stderr, "Could not forward call\n");
            goto done;
        }

        hg_request_wait(request, HG_MAX_IDLE_TIME, NULL);

        hg_request_destroy(request);
    }

    NA_Test_barrier();

    if (na_test_comm_rank_g == 0) printf("%*s%*s%*s%*s%*s%*s",
            10, "# Time (s)", 10, "Min (s)", 10, "Max (s)",
            12, "BW (MB/s)", 12, "Min (MB/s)", 12, "Max (MB/s)");
    if (na_test_comm_rank_g == 0) printf("\n");

    /* Bulk data benchmark */
    for (avg_iter = 0; avg_iter < MERCURY_TESTING_MAX_LOOP; avg_iter++) {
        hg_request_t *request;
        hg_time_t t1, t2;
        double td, part_time_read;
        double read_bandwidth, min_read_bandwidth, max_read_bandwidth;

        request = hg_request_create(request_class);

        hg_time_get_current(&t1);

        ret = HG_Forward(handle, hg_test_perf_forward_cb, request, &in_struct);
        if (ret != HG_SUCCESS) {
            fprintf(stderr, "Could not forward call\n");
            goto done;
        }

        hg_request_wait(request, HG_MAX_IDLE_TIME, NULL);

        NA_Test_barrier();

        hg_time_get_current(&t2);
        td = hg_time_to_double(hg_time_subtract(t2, t1));

        time_read += td;
        if (!min_time_read) min_time_read = time_read;
        min_time_read = (td < min_time_read) ? td : min_time_read;
        max_time_read = (td > max_time_read) ? td : max_time_read;

        hg_request_destroy(request);

        part_time_read = time_read / (avg_iter + 1);
        read_bandwidth = nmbytes * na_test_comm_size_g / part_time_read;
        min_read_bandwidth = nmbytes * na_test_comm_size_g / max_time_read;
        max_read_bandwidth = nmbytes * na_test_comm_size_g / min_time_read;

        /* At this point we have received everything so work out the bandwidth */
        if (na_test_comm_rank_g == 0) {
            printf("%*f%*f%*f%*.*f%*.*f%*.*f\r",
                10, part_time_read, 10, min_time_read, 10, max_time_read,
                12, 2, read_bandwidth, 12, 2, min_read_bandwidth, 12, 2,
                max_read_bandwidth);
        }
    }
    if (na_test_comm_rank_g == 0) printf("\n");

    /* Free memory handle */
    ret = HG_Bulk_free(bulk_handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not free bulk data handle\n");
        goto done;
    }

    /* Free bulk data */
    free(bulk_buf);

    /* Complete */
    ret = HG_Destroy(handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not complete\n");
        goto done;
    }

done:
    return ret;
}
Exemple #15
0
int main(int argc, char *argv[])
{
    struct hg_test_info hg_test_info = { 0 };
    hg_request_t *request = NULL;
    hg_handle_t handle;

    bulk_write_in_t bulk_write_in_struct;

    int fildes = 12345;
    int *bulk_buf = NULL;
    void *buf_ptrs[2];
    size_t buf_sizes[2];
    size_t count =  (1024 * 1024 * MERCURY_TESTING_BUFFER_SIZE) / sizeof(int);
    size_t bulk_size = count * sizeof(int);
    hg_bulk_t bulk_handle = HG_BULK_NULL;

    hg_return_t hg_ret;
    size_t i;

    /* Prepare bulk_buf */
    bulk_buf = (int *) malloc(bulk_size);
    for (i = 0; i < count; i++) {
        bulk_buf[i] = (int) i;
    }
    buf_ptrs[0] = bulk_buf;
    buf_sizes[0] = bulk_size;
    buf_ptrs[1] = NULL;
    buf_sizes[1] = 0;

    /* Initialize the interface */
    HG_Test_init(argc, argv, &hg_test_info);

    request = hg_request_create(hg_test_info.request_class);

    hg_ret = HG_Create(hg_test_info.context, hg_test_info.target_addr,
        hg_test_bulk_write_id_g, &handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not start call\n");
        return EXIT_FAILURE;
    }

    /* Register memory */
    hg_ret = HG_Bulk_create(hg_test_info.hg_class, 2, buf_ptrs,
        (hg_size_t *) buf_sizes, HG_BULK_READ_ONLY, &bulk_handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not create bulk data handle\n");
        return EXIT_FAILURE;
    }

    /* Fill input structure */
    bulk_write_in_struct.fildes = fildes;
    bulk_write_in_struct.bulk_handle = bulk_handle;

    /* Forward call to remote addr and get a new request */
    printf("Forwarding bulk_write, op id: %u...\n", hg_test_bulk_write_id_g);
    hg_ret = HG_Forward(handle, hg_test_bulk_forward_cb, request,
            &bulk_write_in_struct);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not forward call\n");
        return EXIT_FAILURE;
    }

    hg_request_wait(request, HG_MAX_IDLE_TIME, NULL);

    /* Free memory handle */
    hg_ret = HG_Bulk_free(bulk_handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not free bulk data handle\n");
        return EXIT_FAILURE;
    }

    /* Complete */
    hg_ret = HG_Destroy(handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not complete\n");
        return EXIT_FAILURE;
    }

    hg_request_destroy(request);

    HG_Test_finalize(&hg_test_info);

    /* Free bulk data */
    free(bulk_buf);

    return EXIT_SUCCESS;
}
Exemple #16
0
static hg_return_t
cancel_bulk_transfer(hg_class_t *hg_class, hg_context_t *context,
    hg_request_class_t *request_class, hg_addr_t addr)
{
    hg_request_t *request = NULL;
    hg_handle_t handle;
    bulk_write_in_t bulk_write_in_struct;
    int *bulk_buf = NULL;
    void *buf_ptr[1];
    size_t count =  (1024 * 1024 * MERCURY_TESTING_BUFFER_SIZE) / sizeof(int);
    size_t bulk_size = count * sizeof(int);
    hg_bulk_t bulk_handle = HG_BULK_NULL;
    hg_return_t ret;
    size_t i;

    /* Prepare bulk_buf */
    bulk_buf = (int*) malloc(bulk_size);
    for (i = 0; i < count; i++) {
        bulk_buf[i] = (int) i;
    }
    *buf_ptr = bulk_buf;

    request = hg_request_create(request_class);

    ret = HG_Create(context, addr, hg_test_bulk_write_id_g, &handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not start call\n");
        goto done;
    }

    /* Register memory */
    ret = HG_Bulk_create(hg_class, 1, buf_ptr, (hg_size_t *) &bulk_size,
            HG_BULK_READ_ONLY, &bulk_handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not create bulk data handle\n");
        goto done;
    }

    /* Fill input structure */
    bulk_write_in_struct.fildes = -1; /* To tell target to cancel bulk transfer */
    bulk_write_in_struct.bulk_handle = bulk_handle;

    /* Forward call to remote addr and get a new request */
    printf("Forwarding bulk_write, op id: %u...\n", hg_test_bulk_write_id_g);
    ret = HG_Forward(handle, hg_test_bulk_forward_cb, request,
            &bulk_write_in_struct);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not forward call\n");
        goto done;
    }

    hg_request_wait(request, HG_MAX_IDLE_TIME, NULL);

    /* Free memory handle */
    ret = HG_Bulk_free(bulk_handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not free bulk data handle\n");
        goto done;
    }

    /* Complete */
    ret = HG_Destroy(handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not complete\n");
        goto done;
    }

    hg_request_destroy(request);

done:
    return ret;
}
Exemple #17
0
static int
snappy_compress_rpc(hg_class_t *hg_class, hg_context_t *hg_context,
        na_addr_t na_target_addr)
{
    int *input;
    size_t source_length = NR_ITEMS * sizeof(int);
    hg_bulk_t input_bulk_handle;

    void *compressed;
    size_t max_compressed_length;
    hg_bulk_t compressed_bulk_handle;

    snappy_compress_in_t snappy_compress_input;
    struct snappy_compress_rpc_args *snappy_compress_rpc_args;
    hg_handle_t handle;
    int i;

    /**
     * We are going to take a buffer and send it to the server for compression.
     * Mercury works better when you know how much (or an uppper bound on) data
     * to expect.
     */
    max_compressed_length = snappy_max_compressed_length(source_length);
    printf("Input buffer length is: %zu\n", source_length);
    printf("Max compressed length is: %zu\n", max_compressed_length);

    /* Generate input buffer */
    input = (int *) malloc(source_length);
    for (i = 0; i < NR_ITEMS; i++) {
        input[i] = rand() % 10;
    }
    print_buf(20, input);

    /* Allocate compressed buffer */
    compressed = malloc(max_compressed_length);
    memset(compressed, '\0', max_compressed_length);

    /* Create HG handle bound to target */
    HG_Create(hg_context, na_target_addr, snappy_compress_id_g, &handle);

    /**
     * Associate 'handle' with a region of memory. Mercury's bulk transfer is
     * going to get/put data from this region.
     */
    HG_Bulk_create(hg_class, 1, (void **) &input,
            &source_length, HG_BULK_READ_ONLY, &input_bulk_handle);
    HG_Bulk_create(hg_class, 1, &compressed,
            &max_compressed_length, HG_BULK_READWRITE, &compressed_bulk_handle);

    /* Create struct to keep arguments as the call will be executed
     * asynchronously */
    snappy_compress_rpc_args = (struct snappy_compress_rpc_args *) malloc(
            sizeof(struct snappy_compress_rpc_args));
    snappy_compress_rpc_args->input = input;
    snappy_compress_rpc_args->input_length = source_length;
    snappy_compress_rpc_args->input_bulk_handle = input_bulk_handle;
    snappy_compress_rpc_args->compressed = compressed;
    snappy_compress_rpc_args->compressed_bulk_handle = compressed_bulk_handle;

    /* Set input arguments that will be passed to HG_Forward */
    snappy_compress_input.input_bulk_handle = input_bulk_handle;
    snappy_compress_input.compressed_bulk_handle = compressed_bulk_handle;

    /* Forward the call */
    printf("Sending input to target\n");
    HG_Forward(handle, snappy_compress_rpc_cb, snappy_compress_rpc_args,
            &snappy_compress_input);

    /* Handle will be destroyed when call completes (reference count) */
    HG_Destroy(handle);

    return 0;
}
Exemple #18
0
/*---------------------------------------------------------------------------*/
HG_TEST_RPC_CB(hg_test_perf_bulk, handle)
{
    hg_return_t ret = HG_SUCCESS;

    struct hg_info *hg_info = NULL;
    hg_bulk_t origin_bulk_handle = HG_BULK_NULL;
    hg_bulk_t local_bulk_handle = HG_BULK_NULL;
    struct hg_test_bulk_args *bulk_args = NULL;
    bulk_write_in_t in_struct;

    bulk_args = (struct hg_test_bulk_args *) malloc(
            sizeof(struct hg_test_bulk_args));

    /* Keep handle to pass to callback */
    bulk_args->handle = handle;

    /* Get info from handle */
    hg_info = HG_Get_info(handle);

    /* Get input struct */
    ret = HG_Get_input(handle, &in_struct);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not get input struct\n");
        return ret;
    }

    origin_bulk_handle = in_struct.bulk_handle;
    hg_atomic_set32(&bulk_args->completed_transfers, 0);

    /* Create a new block handle to read the data */
    bulk_args->nbytes = HG_Bulk_get_size(origin_bulk_handle);
    bulk_args->fildes = in_struct.fildes;

#ifdef MERCURY_TESTING_USE_LOCAL_BULK
    /* Create a new bulk handle to read the data */
    HG_Bulk_create(hg_info->hg_class, 1, NULL, &bulk_args->nbytes,
            HG_BULK_READWRITE, &local_bulk_handle);
#else
#ifdef MERCURY_TESTING_HAS_THREAD_POOL
    hg_thread_mutex_lock(&hg_test_local_bulk_handle_mutex_g);
#endif
    local_bulk_handle = hg_test_local_bulk_handle_g;
#endif

    /* Pull bulk data */
    ret = HG_Bulk_transfer(hg_info->context, hg_test_perf_bulk_transfer_cb,
            bulk_args, HG_BULK_PULL, hg_info->addr, origin_bulk_handle, 0,
            local_bulk_handle, 0, bulk_args->nbytes, HG_OP_ID_IGNORE);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not read bulk data\n");
        return ret;
    }

#ifndef MERCURY_TESTING_USE_LOCAL_BULK
#ifdef MERCURY_TESTING_HAS_THREAD_POOL
    hg_thread_mutex_unlock(&hg_test_local_bulk_handle_mutex_g);
#endif
#endif

    HG_Free_input(handle, &in_struct);
    return ret;
}