Exemplo n.º 1
0
/*---------------------------------------------------------------------------*/
struct hg_atomic_queue *
hg_atomic_queue_alloc(unsigned int count)
{
    struct hg_atomic_queue *hg_atomic_queue = NULL;

    if (!powerof2(count)) {
       HG_UTIL_LOG_ERROR("atomic queue size must be power of 2");
       goto done;
    }

    hg_atomic_queue = malloc(sizeof(struct hg_atomic_queue) +
        count * HG_ATOMIC_QUEUE_ELT_SIZE);
    if (!hg_atomic_queue) {
        HG_UTIL_LOG_ERROR("Could not allocate atomic queue");
        goto done;
    }

    hg_atomic_queue->prod_size = hg_atomic_queue->cons_size = count;
    hg_atomic_queue->prod_mask = hg_atomic_queue->cons_mask = count - 1;
    hg_atomic_init32(&hg_atomic_queue->prod_head, 0);
    hg_atomic_init32(&hg_atomic_queue->cons_head, 0);
    hg_atomic_init32(&hg_atomic_queue->prod_tail, 0);
    hg_atomic_init32(&hg_atomic_queue->cons_tail, 0);

done:
    return hg_atomic_queue;
}
Exemplo n.º 2
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;
}