Exemplo n.º 1
0
/*---------------------------------------------------------------------------*/
static hg_return_t
hg_test_perf_bulk_transfer_cb(const struct hg_cb_info *hg_cb_info)
{
    struct hg_test_bulk_args *bulk_args = (struct hg_test_bulk_args *)
            hg_cb_info->arg;
    hg_return_t ret = HG_SUCCESS;

#ifdef MERCURY_TESTING_USE_LOCAL_BULK
    /* Free block handle */
    ret = HG_Bulk_free(hg_cb_info->info.bulk.local_handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not free HG bulk handle\n");
        goto done;
    }
#endif

    /* Send response back */
    ret = HG_Respond(bulk_args->handle, NULL, NULL, NULL);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not respond\n");
        goto done;
    }

done:
    HG_Destroy(bulk_args->handle);
    free(bulk_args);

    return ret;
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------*/
static hg_return_t
hg_test_posix_read_transfer_cb(const struct hg_cb_info *hg_cb_info)
{
    struct hg_test_bulk_args *bulk_args = (struct hg_test_bulk_args *)
            hg_cb_info->arg;
    hg_bulk_t local_bulk_handle = hg_cb_info->info.bulk.local_handle;
    hg_return_t ret = HG_SUCCESS;

    write_out_t out_struct;

    /* Fill output structure */
    out_struct.ret = bulk_args->ret;

    /* Free block handle */
    ret = HG_Bulk_free(local_bulk_handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not free HG bulk handle\n");
        return ret;
    }

    /* Send response back */
    ret = HG_Respond(bulk_args->handle, NULL, NULL, &out_struct);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not respond\n");
        return ret;
    }

    HG_Destroy(bulk_args->handle);
    free(bulk_args);

    return ret;
}
Exemplo n.º 3
0
static hg_return_t
snappy_push_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;
    snappy_compress_out_t snappy_compress_output;

    /* Set output parameters to inform origin */
    snappy_compress_output.ret = snappy_transfer_args->ret;
    snappy_compress_output.compressed_length = snappy_transfer_args->compressed_length;
    printf("Transferred compressed buffer of length %zu\n",
            snappy_transfer_args->compressed_length);

    printf("Sending output parameters back to origin\n");
    HG_Respond(snappy_transfer_args->handle, snappy_compress_done_cb, NULL,
            &snappy_compress_output);

    /* Free bulk handles */
    printf("Freeing resources\n");
    HG_Bulk_free(snappy_transfer_args->local_compressed_bulk_handle);
    free(snappy_transfer_args->compressed);

    /* Free input */
    HG_Free_input(snappy_transfer_args->handle,
            &snappy_transfer_args->snappy_compress_input);

    /* Destroy handle (no longer need it, safe because of reference count) */
    HG_Destroy(snappy_transfer_args->handle);
    free(snappy_transfer_args);

    return ret;
}
Exemplo n.º 4
0
/*---------------------------------------------------------------------------*/
HG_TEST_RPC_CB(hg_test_nested1, handle)
{
    hg_handle_t forward_handle;
    struct hg_info *hg_info = NULL;
    hg_return_t ret = HG_SUCCESS;

    printf("In hg_test_nested1\n");

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

    ret = HG_Create(hg_info->context, hg_addr_table[1], hg_test_nested2_id_g,
            &forward_handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not start call\n");
        goto done;
    }

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

    HG_Destroy(forward_handle);

done:
    return ret;
}
Exemplo n.º 5
0
/*---------------------------------------------------------------------------*/
static void
hg_test_finalize_rpc(void)
{
    hg_return_t hg_ret;
    hg_handle_t handle;
    hg_request_t *request_object = NULL;

    request_object = hg_request_create(HG_REQUEST_CLASS_DEFAULT);

    hg_ret = HG_Create(HG_CONTEXT_DEFAULT, hg_test_addr_g, hg_test_finalize_id_g,
            &handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not forward call\n");
    }

    /* Forward call to remote addr and get a new request */
    hg_ret = HG_Forward(handle, hg_test_finalize_rpc_cb, request_object, NULL);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not forward call\n");
    }

    hg_request_wait(request_object, HG_MAX_IDLE_TIME, NULL);

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

    hg_request_destroy(request_object);
}
Exemplo n.º 6
0
/* callback triggered upon receipt of rpc response */
static hg_return_t my_rpc_cb(const struct hg_cb_info *info)
{
    my_rpc_out_t out;
    int ret;
    struct my_rpc_state *my_rpc_state_p = info->arg;

    assert(info->ret == HG_SUCCESS);

    /* decode response */
    ret = HG_Get_output(info->info.forward.handle, &out);
    assert(ret == 0);
    (void)ret;

    printf("Got response ret: %d\n", out.ret);

    /* clean up resources consumed by this rpc */
    HG_Bulk_free(my_rpc_state_p->bulk_handle);
    HG_Free_output(info->info.forward.handle, &out);
    HG_Destroy(info->info.forward.handle);
    free(my_rpc_state_p->buffer);
    free(my_rpc_state_p);

    /* signal to main() that we are done */
    pthread_mutex_lock(&done_mutex);
    done++;
    pthread_cond_signal(&done_cond);
    pthread_mutex_unlock(&done_mutex);

    return(HG_SUCCESS);
}
Exemplo n.º 7
0
/*---------------------------------------------------------------------------*/
HG_TEST_RPC_CB(hg_test_overflow, handle)
{
    hg_return_t ret = HG_SUCCESS;

    overflow_out_t out_struct;

    hg_string_t string;
    size_t string_len = 1024 * 4;

    string = (hg_string_t) malloc(string_len + 1);
    memset(string, 'h', string_len);
    string[string_len] = '\0';

    /* Fill output structure */
    out_struct.string = string;
    out_struct.string_len = string_len;

    /* Send response back */
    ret = HG_Respond(handle, NULL, NULL, &out_struct);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not respond\n");
        return ret;
    }

    HG_Destroy(handle);
    free(string);

    return ret;
}
Exemplo n.º 8
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;
    na_addr_t addr;
    rpc_open_in_t  rpc_open_in_struct;

    hg_const_string_t rpc_open_path = MERCURY_TESTING_TEMP_DIRECTORY "/test.h5";
    rpc_handle_t rpc_open_handle;
    hg_return_t hg_ret;

    /* 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(hg_class, context, addr, hg_test_rpc_open_id_g, &handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not start call\n");
        return EXIT_FAILURE;
    }

    /* Fill input structure */
    rpc_open_handle.cookie = 12345;
    rpc_open_in_struct.path = rpc_open_path;
    rpc_open_in_struct.handle = rpc_open_handle;

    /* Forward call to remote addr and get a new request */
    printf("Forwarding rpc_open, op id: %u...\n", hg_test_rpc_open_id_g);
    hg_ret = HG_Forward(handle, hg_test_rpc_forward_cb, request,
            &rpc_open_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);

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

    return EXIT_SUCCESS;
}
Exemplo n.º 9
0
/*---------------------------------------------------------------------------*/
static hg_return_t
hg_test_bulk_transfer_cb(const struct hg_cb_info *hg_cb_info)
{
    struct hg_test_bulk_args *bulk_args = (struct hg_test_bulk_args *)
            hg_cb_info->arg;
    hg_bulk_t local_bulk_handle = hg_cb_info->info.bulk.local_handle;
    hg_return_t ret = HG_SUCCESS;

    bulk_write_out_t out_struct;

    void *buf;
    size_t write_ret;

    if (hg_cb_info->ret == HG_CANCELED) {
        printf("HG_Bulk_transfer() was successfully canceled\n");

        /* Fill output structure */
        out_struct.ret = 0;
    } else if (hg_cb_info->ret != HG_SUCCESS) {
        HG_LOG_ERROR("Error in callback");
        ret = HG_PROTOCOL_ERROR;
        goto done;
    }

    if (hg_cb_info->ret == HG_SUCCESS) {
        /* Call bulk_write */
        HG_Bulk_access(local_bulk_handle, 0, bulk_args->nbytes,
            HG_BULK_READWRITE, 1, &buf, NULL, NULL);

        write_ret = bulk_write(bulk_args->fildes, buf, 0,
            bulk_args->nbytes, 1);

        /* Fill output structure */
        out_struct.ret = write_ret;
    }

    /* Free block handle */
    ret = HG_Bulk_free(local_bulk_handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not free HG bulk handle\n");
        return ret;
    }

    /* Send response back */
    ret = HG_Respond(bulk_args->handle, NULL, NULL, &out_struct);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not respond\n");
        return ret;
    }

done:
    HG_Destroy(bulk_args->handle);
    free(bulk_args);

    return ret;
}
Exemplo n.º 10
0
/*---------------------------------------------------------------------------*/
static hg_return_t
hg_test_posix_write_transfer_cb(const struct hg_cb_info *hg_cb_info)
{
    struct hg_test_bulk_args *bulk_args = (struct hg_test_bulk_args *)
            hg_cb_info->arg;
    hg_bulk_t local_bulk_handle = hg_cb_info->info.bulk.local_handle;
    hg_return_t ret = HG_SUCCESS;

    write_out_t out_struct;

    void *buf;
    ssize_t write_ret;

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

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

    /* 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 in bulk transfer, buf[%d] = %d, was expecting %d!\n", i, buf_ptr[i], i);
            break;
        }
    }

    printf("Calling write with fd: %d\n", bulk_args->fildes);
    write_ret = write(bulk_args->fildes, buf, bulk_args->nbytes);

    /* Fill output structure */
    out_struct.ret = write_ret;

    /* Free block handle */
    ret = HG_Bulk_free(local_bulk_handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not free HG bulk handle\n");
        return ret;
    }

    /* Send response back */
    ret = HG_Respond(bulk_args->handle, NULL, NULL, &out_struct);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not respond\n");
        return ret;
    }

    HG_Destroy(bulk_args->handle);
    free(bulk_args);

    return ret;
}
Exemplo n.º 11
0
static hg_return_t
cancel_rpc(hg_context_t *context, hg_request_class_t *request_class,
    hg_addr_t addr)
{
    hg_request_t *request = NULL;
    hg_handle_t handle;

    rpc_open_in_t rpc_open_in_struct;
    hg_const_string_t rpc_open_path = MERCURY_TESTING_TEMP_DIRECTORY "/test.h5";
    rpc_handle_t rpc_open_handle;
    hg_return_t ret;

    request = hg_request_create(request_class);

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

    /* Fill input structure */
    rpc_open_handle.cookie = 12345;
    rpc_open_in_struct.path = rpc_open_path;
    rpc_open_in_struct.handle = rpc_open_handle;

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

    ret = HG_Cancel(handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "HG_Cancel failed: %d\n", ret);
        goto done;
    }

    hg_request_wait(request, HG_MAX_IDLE_TIME, NULL);

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

    hg_request_destroy(request);

done:
    return ret;
}
Exemplo n.º 12
0
/*---------------------------------------------------------------------------*/
HG_TEST_RPC_CB(hg_test_perf_rpc, handle)
{
    hg_return_t ret = HG_SUCCESS;

    /* Send response back */
    ret = HG_Respond(handle, NULL, NULL, NULL);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not respond\n");
        return ret;
    }

    HG_Destroy(handle);

    return ret;
}
Exemplo n.º 13
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;
    hg_return_t hg_ret;

    /* 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_overflow_id_g, &handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not start call\n");
        return EXIT_FAILURE;
    }

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

    hg_request_wait(request, HG_MAX_IDLE_TIME, NULL);

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

    return EXIT_SUCCESS;
}
Exemplo n.º 14
0
/*---------------------------------------------------------------------------*/
static hg_return_t
hg_test_bulk_seg_transfer_cb(const struct hg_cb_info *hg_cb_info)
{
    struct hg_test_bulk_args *bulk_args = (struct hg_test_bulk_args *)
            hg_cb_info->arg;
    hg_bulk_t local_bulk_handle = hg_cb_info->info.bulk.local_handle;
    hg_return_t ret = HG_SUCCESS;

    bulk_write_out_t out_struct;

    void *buf;
    size_t write_ret;

    if (hg_atomic_incr32(&bulk_args->completed_transfers) != 2)
        goto done;

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

    write_ret = bulk_write(bulk_args->fildes, buf, 0,
        bulk_args->nbytes, 1);

    /* Fill output structure */
    out_struct.ret = write_ret;

    /* Free block handle */
    ret = HG_Bulk_free(local_bulk_handle);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not free HG bulk handle\n");
        return ret;
    }

    /* Send response back */
    ret = HG_Respond(bulk_args->handle, NULL, NULL, &out_struct);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not respond\n");
        return ret;
    }

    HG_Destroy(bulk_args->handle);
    free(bulk_args);

done:
    return ret;
}
Exemplo n.º 15
0
/*---------------------------------------------------------------------------*/
static hg_return_t
hg_test_finalize2_cb(hg_handle_t handle)
{
    hg_return_t ret = HG_SUCCESS;

    hg_atomic_incr32(&hg_test_finalizing_count_g);

    /* Free handle and send response back */
    ret = HG_Respond(handle, NULL, NULL, NULL);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not respond\n");
        return ret;
    }

    HG_Destroy(handle);

    return ret;
}
Exemplo n.º 16
0
/*---------------------------------------------------------------------------*/
static hg_return_t
hg_test_nested1_forward_cb(const struct hg_cb_info *callback_info)
{
    hg_handle_t handle = (hg_handle_t) callback_info->arg;
    hg_return_t ret = HG_SUCCESS;

    printf("In hg_test_nested1_forward_cb\n");

    /* Send response back */
    ret = HG_Respond(handle, NULL, NULL, NULL);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not respond\n");
        return ret;
    }

    HG_Destroy(handle);

    return ret;
}
Exemplo n.º 17
0
/*---------------------------------------------------------------------------*/
HG_TEST_RPC_CB(hg_test_rpc_open, handle)
{
    hg_return_t ret = HG_SUCCESS;

    rpc_open_in_t  in_struct;
    rpc_open_out_t out_struct;

    hg_const_string_t path;
    rpc_handle_t rpc_handle;
    int event_id;
    int open_ret;

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

    /* Get parameters */
    path = in_struct.path;
    rpc_handle = in_struct.handle;

    /* Call rpc_open */
    open_ret = rpc_open(path, rpc_handle, &event_id);

    /* Fill output structure */
    out_struct.event_id = event_id;
    out_struct.ret = open_ret;

    /* Send response back */
    ret = HG_Respond(handle, NULL, NULL, &out_struct);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not respond\n");
        return ret;
    }

    HG_Free_input(handle, &in_struct);
    HG_Destroy(handle);

    return ret;
}
Exemplo n.º 18
0
HG_TEST_RPC_CB(hg_test_posix_open, handle)
{
    hg_return_t ret = HG_SUCCESS;

    open_in_t in_struct;
    open_out_t out_struct;

    const char *path;
    int flags;
    mode_t mode;
    int open_ret;

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

    path = in_struct.path;
    flags = in_struct.flags;
    mode = in_struct.mode;

    /* Call open */
    printf("Calling open with path: %s\n", path);
    open_ret = open(path, flags, mode);

    /* Fill output structure */
    out_struct.ret = open_ret;

    /* Send response back */
    ret = HG_Respond(handle, NULL, NULL, &out_struct);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not respond\n");
        return ret;
    }

    HG_Free_input(handle, &in_struct);
    HG_Destroy(handle);

    return ret;
}
Exemplo n.º 19
0
/* 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;
}
Exemplo n.º 20
0
/*---------------------------------------------------------------------------*/
static hg_return_t
hg_test_overflow(hg_context_t *context, hg_request_class_t *request_class,
    hg_addr_t addr, hg_id_t rpc_id, hg_cb_t callback)
{
    hg_request_t *request = NULL;
    hg_handle_t handle;
    hg_return_t hg_ret = HG_SUCCESS;

    request = hg_request_create(request_class);

    /* Create RPC request */
    hg_ret = HG_Create(context, addr, rpc_id, &handle);
    if (hg_ret != HG_SUCCESS) {
        HG_TEST_LOG_ERROR("Could not create handle");
        goto done;
    }

    /* Forward call to remote addr and get a new request */
    HG_TEST_LOG_DEBUG("Forwarding RPC, op id: %u...", rpc_id);
    hg_ret = HG_Forward(handle, callback, request, NULL);
    if (hg_ret != HG_SUCCESS) {
        HG_TEST_LOG_ERROR("Could not forward call");
        goto done;
    }

    hg_request_wait(request, HG_MAX_IDLE_TIME, NULL);

    /* Complete */
    hg_ret = HG_Destroy(handle);
    if (hg_ret != HG_SUCCESS) {
        HG_TEST_LOG_ERROR("Could not destroy handle");
        goto done;
    }

done:
    hg_request_destroy(request);
    return hg_ret;
}
Exemplo n.º 21
0
/*---------------------------------------------------------------------------*/
HG_TEST_RPC_CB(hg_test_posix_close, handle)
{
    hg_return_t ret = HG_SUCCESS;

    close_in_t in_struct;
    close_out_t out_struct;

    int fd;
    int close_ret;

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

    fd = in_struct.fd;

    /* Call close */
    printf("Calling close with fd: %d\n", fd);
    close_ret = close(fd);

    /* Fill output structure */
    out_struct.ret = close_ret;

    /* Send response back */
    ret = HG_Respond(handle, NULL, NULL, &out_struct);
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not respond\n");
        return ret;
    }

    HG_Free_input(handle, &in_struct);
    HG_Destroy(handle);

    return ret;
}
Exemplo n.º 22
0
/*---------------------------------------------------------------------------*/
static void
hg_test_finalize_rpc2(hg_addr_t addr)
{
    hg_return_t hg_ret;
    hg_handle_t handle;

    hg_ret = HG_Create(HG_CONTEXT_DEFAULT, addr, hg_test_finalize2_id_g, &handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not forward call\n");
    }

    /* Forward call to remote addr and get a new request */
    hg_ret = HG_Forward(handle, hg_test_finalize_rpc_cb, NULL, NULL);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not forward call\n");
    }

    /* Complete */
    hg_ret = HG_Destroy(handle);
    if (hg_ret != HG_SUCCESS) {
        fprintf(stderr, "Could not complete\n");
    }
}
Exemplo n.º 23
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;
}
Exemplo n.º 24
0
static hg_return_t
measure_rpc(hg_class_t *hg_class, hg_context_t *context, na_addr_t addr,
        hg_request_class_t *request_class)
{
    int avg_iter;
    double time_read = 0, min_time_read = 0, max_time_read = 0;
    hg_return_t ret = HG_SUCCESS;

    size_t i;

    if (na_test_comm_rank_g == 0) {
        printf("# Executing RPC with %d client(s) -- loop %d time(s)\n",
                na_test_comm_size_g, MERCURY_TESTING_MAX_LOOP);
    }

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

    /* Warm up for RPC */
    for (i = 0; i < RPC_SKIP; i++) {
        hg_request_t *request;
        hg_handle_t handle;

        request = hg_request_create(request_class);

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

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

        hg_request_wait(request, HG_MAX_IDLE_TIME, NULL);

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

        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, "Calls (c/s)", 12, "Min (c/s)", 12, "Max (c/s)");
    if (na_test_comm_rank_g == 0) printf("\n");

    /* RPC benchmark */
    for (avg_iter = 0; avg_iter < MERCURY_TESTING_MAX_LOOP; avg_iter++) {
        hg_request_t *request;
        hg_handle_t handle;
        hg_time_t t1, t2;
        double td, part_time_read;
        double calls_per_sec, min_calls_per_sec, max_calls_per_sec;

        request = hg_request_create(request_class);

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

        hg_time_get_current(&t1);

        ret = HG_Forward(handle, hg_test_perf_forward_cb, request, NULL);
        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;

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

        hg_request_destroy(request);

        part_time_read = time_read / (avg_iter + 1);
        calls_per_sec = na_test_comm_size_g / part_time_read;
        min_calls_per_sec = na_test_comm_size_g / max_time_read;
        max_calls_per_sec = 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, calls_per_sec, 12, 2, min_calls_per_sec, 12, 2,
                max_calls_per_sec);
        }
    }
    if (na_test_comm_rank_g == 0) printf("\n");

done:
    return ret;
}
Exemplo n.º 25
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;
}
Exemplo n.º 26
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;
}
Exemplo n.º 27
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;
}
Exemplo n.º 28
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;
}
Exemplo n.º 29
0
/*---------------------------------------------------------------------------*/
static hg_return_t
hg_test_drc_grant_cb(hg_handle_t handle)
{
    const struct hg_info *hg_info = NULL;
    struct hg_test_info *hg_test_info = NULL;
    hg_test_drc_grant_in_t in_struct;
    hg_test_drc_grant_out_t out_struct;
    hg_return_t ret = HG_SUCCESS;
#ifdef HG_TEST_DRC_USE_TOKEN
    hg_string_t token;
#endif
#ifndef HG_TEST_DRC_IGNORE
    int rc;
#endif

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

    /* Get test info */
    hg_test_info = (struct hg_test_info *) HG_Class_get_data(hg_info->hg_class);

    /* Get input buffer */
    ret = HG_Get_input(handle, &in_struct);
    if (ret != HG_SUCCESS) {
        HG_LOG_ERROR("Could not get input");
        goto done;
    }

    /* Get parameters */
    hg_test_info->wlm_id = in_struct.wlm_id;

    /* Grant access to another job */
    printf("# Granting access to wlm_id %u...\n", hg_test_info->wlm_id);
    fflush(stdout);
#ifndef HG_TEST_DRC_IGNORE
drc_grant_again:
    rc = drc_grant(hg_test_info->credential, hg_test_info->wlm_id,
        DRC_FLAGS_TARGET_WLM);
    if (rc != DRC_SUCCESS && rc != -DRC_ALREADY_GRANTED) {
        if (rc == -DRC_EINVAL) {
            sleep(1);
            goto drc_grant_again;
        }
        HG_LOG_ERROR("drc_grant() to %d failed (%d, %s)", hg_test_info->wlm_id,
            rc, drc_strerror(-rc));
        ret = HG_PROTOCOL_ERROR;
        goto done;
    }
#endif

#ifdef HG_TEST_DRC_USE_TOKEN
    /* Get the token to pass around to processes in other job */
#ifndef HG_TEST_DRC_IGNORE
    rc = drc_get_credential_token(hg_test_info->credential, &token);
    if (rc != DRC_SUCCESS) {
        HG_LOG_ERROR("drc_get_credential_token() failed (%d, %s)", rc,
            drc_strerror(-rc));
        ret = HG_PROTOCOL_ERROR;
        goto done;
    }
#else
    token = "my_test_token";
#endif

    /* Fill output structure */
    printf("# Access granted, token is %s\n", token);
    fflush(stdout);
    out_struct.token = token;
#else
    out_struct.credential = hg_test_info->credential;
#endif

    /* Free handle and send response back */
    ret = HG_Respond(handle, NULL, NULL, &out_struct);
    if (ret != HG_SUCCESS) {
        HG_LOG_ERROR("Could not respond");
        goto done;
    }

    HG_Free_input(handle, &in_struct);
    HG_Destroy(handle);

done:
    return ret;
}
Exemplo n.º 30
0
/*---------------------------------------------------------------------------*/
static hg_return_t
hg_test_drc_token_request(struct hg_test_info *hg_test_info)
{
    hg_request_t *request = NULL;
    hg_handle_t handle;
#ifdef HG_TEST_DRC_USE_TOKEN
    hg_string_t token;
#else
    hg_uint32_t credential;
#endif
    hg_test_drc_grant_in_t in_struct;
    hg_test_drc_grant_out_t out_struct;
    hg_return_t ret = HG_SUCCESS;
#ifndef HG_TEST_DRC_IGNORE
    int rc;
#endif

    /* Look up target addr using target name info */
    ret = HG_Hl_addr_lookup_wait(hg_test_info->context,
        hg_test_info->request_class, hg_test_info->na_test_info.target_name,
        &hg_test_info->target_addr, HG_MAX_IDLE_TIME);
    if (ret != HG_SUCCESS) {
        HG_LOG_ERROR("Could not find addr for target %s",
            hg_test_info->na_test_info.target_name);
        goto done;
    }

    /* Create new request */
    request = hg_request_create(hg_test_info->request_class);

    /* Create request with invalid RPC id */
    ret = HG_Create(hg_test_info->context, hg_test_info->target_addr,
        hg_test_drc_grant_id_g, &handle);
    if (ret != HG_SUCCESS) {
        HG_LOG_ERROR("Could not create handle");
        goto done;
    }

    /* Get WLM ID and set input */
#ifndef HG_TEST_DRC_IGNORE
    in_struct.wlm_id = drc_get_wlm_id();
#else
    in_struct.wlm_id = 12340;
#endif

    /* Forward call to target addr */
    printf("# %u requesting access to remote...\n", in_struct.wlm_id);
    fflush(stdout);
    ret = HG_Forward(handle, hg_test_drc_token_request_cb, request, &in_struct);
    if (ret != HG_SUCCESS) {
        HG_LOG_ERROR("Could not forward call with id=%d",
            hg_test_drc_grant_id_g);
        goto done;
    }

    /* Wait for completion */
    hg_request_wait(request, HG_MAX_IDLE_TIME, NULL);

    /* Get output */
    ret = HG_Get_output(handle, &out_struct);
    if (ret != HG_SUCCESS) {
        HG_LOG_ERROR("Could not get output");
        goto done;
    }

#ifdef HG_TEST_DRC_USE_TOKEN
    /* Get token back */
    token = out_struct.token;
    printf("# Received token %s\n", token);
    fflush(stdout);

    /* Translate token */
#ifndef HG_TEST_DRC_IGNORE
    rc = drc_access_with_token(token, 0, &hg_test_info->credential_info);
    if (rc != DRC_SUCCESS) {/* failed to grant access to the credential */
        HG_LOG_ERROR("drc_access_with_token() failed (%d, %s)", rc,
            drc_strerror(-rc));
        ret = HG_PROTOCOL_ERROR;
        goto done;
    }
#endif
#else
    /* Get credential back */
    credential = out_struct.credential;
    printf("# Received credential %u\n", credential);
    fflush(stdout);

    /* Access credential */
#ifndef HG_TEST_DRC_IGNORE
drc_access_again:
    rc = drc_access(credential, 0, &hg_test_info->credential_info);
    if (rc != DRC_SUCCESS) { /* failed to access credential */
        if (rc == -DRC_EINVAL) {
            sleep(1);
            goto drc_access_again;
        }
        HG_LOG_ERROR("drc_access() failed (%d, %s)", rc,
            drc_strerror(-rc));
        ret = HG_PROTOCOL_ERROR;
        goto done;
    }
#endif
#endif

    /* Set cookie for further use */
#ifndef HG_TEST_DRC_IGNORE
    hg_test_info->cookie = drc_get_first_cookie(hg_test_info->credential_info);
#else
    hg_test_info->cookie = 123456789;
#endif
    printf("# Cookie is %u\n", hg_test_info->cookie);
    fflush(stdout);

    /* Clean up resources */
    ret = HG_Free_output(handle, &out_struct);
    if (ret != HG_SUCCESS) {
        HG_LOG_ERROR("Could not free output");
        goto done;
    }

    ret = HG_Destroy(handle);
    if (ret != HG_SUCCESS) {
        HG_LOG_ERROR("Could not destroy handle");
        goto done;
    }

    hg_request_destroy(request);

    /* Free target addr */
    ret = HG_Addr_free(hg_test_info->hg_class, hg_test_info->target_addr);
    if (ret != HG_SUCCESS) {
        HG_LOG_ERROR("Could not free addr");
        goto done;
    }

done:
    return ret;
}