composed-benchmark.c 3.6 KB
Newer Older
Philip Carns's avatar
Philip Carns committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * (C) 2015 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <abt.h>
#include <abt-snoozer.h>
#include <margo.h>

#include "composed-client-lib.h"

static hg_id_t my_rpc_shutdown_id;
static void* buffer;
static hg_size_t buffer_sz = 8*1024*1024;

int main(int argc, char **argv) 
{
    int i;
    int ret;
    margo_instance_id mid;
    hg_context_t *hg_context;
    hg_class_t *hg_class;
27 28
    hg_addr_t delegator_svr_addr = HG_ADDR_NULL;
    hg_addr_t data_xfer_svr_addr = HG_ADDR_NULL;
Philip Carns's avatar
Philip Carns committed
29 30 31
    hg_handle_t handle;
    char proto[12] = {0};
  
32
    if(argc != 3)
Philip Carns's avatar
Philip Carns committed
33
    {
34
        fprintf(stderr, "Usage: ./client <delegator_svr_addr> <data_xfer_svr_addr>\n");
Philip Carns's avatar
Philip Carns committed
35 36 37 38 39 40 41 42 43 44 45
        return(-1);
    }
       
    /* boilerplate HG initialization steps */
    /***************************************/

    /* initialize Mercury using the transport portion of the destination
     * address (i.e., the part before the first : character if present)
     */
    for(i=0; i<11 && argv[1][i] != '\0' && argv[1][i] != ':'; i++)
        proto[i] = argv[1][i];
46 47 48 49
    /* TODO: this is a hack for now; I don't really want this to operate in server mode,
     * but it seems like it needs to for now for sub-service to be able to get back to it
     */
    hg_class = HG_Init(proto, HG_TRUE);
Philip Carns's avatar
Philip Carns committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    if(!hg_class)
    {
        fprintf(stderr, "Error: HG_Init()\n");
        return(-1);
    }
    hg_context = HG_Context_create(hg_class);
    if(!hg_context)
    {
        fprintf(stderr, "Error: HG_Context_create()\n");
        HG_Finalize(hg_class);
        return(-1);
    }

    /* set up argobots */
    /***************************************/
    ret = ABT_init(argc, argv);
    if(ret != 0)
    {
        fprintf(stderr, "Error: ABT_init()\n");
        return(-1);
    }

    /* set primary ES to idle without polling */
    ret = ABT_snoozer_xstream_self_set();
    if(ret != 0)
    {
        fprintf(stderr, "Error: ABT_snoozer_xstream_self_set()\n");
        return(-1);
    }

    /* actually start margo */
    /***************************************/
    mid = margo_init(0, 0, hg_context);

    /* register core RPC */
    my_rpc_shutdown_id = MERCURY_REGISTER(hg_class, "my_shutdown_rpc", void, void, 
        NULL);
    /* register service APIs */
    data_xfer_register_client(mid);
Philip Carns's avatar
Philip Carns committed
89
    composed_register_client(mid);
Philip Carns's avatar
Philip Carns committed
90

91 92 93 94
    /* find addrs for servers */
    ret = margo_addr_lookup(mid, argv[2], &data_xfer_svr_addr);
    assert(ret == 0);
    ret = margo_addr_lookup(mid, argv[1], &delegator_svr_addr);
Philip Carns's avatar
Philip Carns committed
95 96 97 98 99
    assert(ret == 0);

    buffer = calloc(1, buffer_sz);
    assert(buffer);

Philip Carns's avatar
bug fix  
Philip Carns committed
100
    printf("DBG: calling data_xfer_read.\n");
101
    data_xfer_read(mid, data_xfer_svr_addr, buffer, buffer_sz);
Philip Carns's avatar
bug fix  
Philip Carns committed
102 103 104
    printf("DBG:    ... DONE.\n");
    
    printf("DBG: calling composed_read.\n");
105
    composed_read(mid, delegator_svr_addr, buffer, buffer_sz, argv[2]);
Philip Carns's avatar
bug fix  
Philip Carns committed
106
    printf("DBG:    ... DONE.\n");
Philip Carns's avatar
Philip Carns committed
107

108 109
    /* send rpc(s) to shut down server(s) */
    ret = HG_Create(hg_context, delegator_svr_addr, my_rpc_shutdown_id, &handle);
Philip Carns's avatar
Philip Carns committed
110 111
    assert(ret == 0);
    margo_forward(mid, handle, NULL);
112 113 114 115 116 117 118 119
    HG_Destroy(handle);
    if(strcmp(argv[1], argv[2]))
    {
        ret = HG_Create(hg_context, data_xfer_svr_addr, my_rpc_shutdown_id, &handle);
        assert(ret == 0);
        margo_forward(mid, handle, NULL);
        HG_Destroy(handle);
    }
Philip Carns's avatar
Philip Carns committed
120

121 122
    HG_Addr_free(hg_class, delegator_svr_addr);
    HG_Addr_free(hg_class, data_xfer_svr_addr);
Philip Carns's avatar
Philip Carns committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136

    /* shut down everything */
    margo_finalize(mid);
    
    ABT_finalize();

    HG_Context_destroy(hg_context);
    HG_Finalize(hg_class);
    free(buffer);

    return(0);
}