margo-example-mp-client.c 2.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * (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 <margo.h>

#include "svc1-client.h"
14
#include "svc2-client.h"
15 16 17 18 19 20 21

static hg_id_t my_rpc_shutdown_id;

int main(int argc, char **argv) 
{
    int i;
    margo_instance_id mid;
22
    hg_return_t hret;
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
    hg_addr_t svr_addr = HG_ADDR_NULL;
    hg_handle_t handle;
    char proto[12] = {0};
  
    if(argc != 2)
    {
        fprintf(stderr, "Usage: ./client <server_addr>\n");
        return(-1);
    }
       
    /* 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];

39 40 41 42 43 44 45
    /* actually start margo -- margo_init() encapsulates the Mercury &
     * Argobots initialization, so this step must precede their use. */
    /* Use main process to drive progress (it will relinquish control to
     * Mercury during blocking communication calls). No RPC threads are
     * used because this is a pure client that will not be servicing
     * rpc requests.
     */
46
    /***************************************/
47 48
    mid = margo_init(proto, MARGO_CLIENT_MODE, 0, 0);
    if(mid == MARGO_INSTANCE_NULL)
49
    {
50
        fprintf(stderr, "Error: margo_init()\n");
51 52 53 54
        return(-1);
    }

    /* register core RPC */
55
    my_rpc_shutdown_id = MARGO_REGISTER(mid, "my_shutdown_rpc", void, void, NULL);
Philip Carns's avatar
Philip Carns committed
56 57
    /* register service APIs */
    svc1_register_client(mid);
58
    svc2_register_client(mid);
59 60

    /* find addr for server */
61 62
    hret = margo_addr_lookup(mid, argv[1], &svr_addr);
    assert(hret == HG_SUCCESS);
63 64

    svc1_do_thing(mid, svr_addr, 1);
65 66 67 68 69
    svc1_do_other_thing(mid, svr_addr, 1);
    svc1_do_thing(mid, svr_addr, 2);
    svc1_do_other_thing(mid, svr_addr, 2);
    svc2_do_thing(mid, svr_addr, 3);
    svc2_do_other_thing(mid, svr_addr, 3);
70 71 72

    /* send one rpc to server to shut it down */
    /* create handle */
73 74
    hret = margo_create(mid, svr_addr, my_rpc_shutdown_id, &handle);
    assert(hret == HG_SUCCESS);
75

76
    hret = margo_forward(handle, NULL);
77
    assert(hret == HG_SUCCESS);
78

79
    margo_destroy(handle);
80
    margo_addr_free(mid, svr_addr);
81 82 83 84 85 86

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

    return(0);
}