Commit 6a345e9e authored by Shane Snyder's avatar Shane Snyder

update margo tests according to new iface changes

parent 972cfbb4
......@@ -7,8 +7,8 @@
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <mercury.h>
#include <abt.h>
#include <abt-snoozer.h>
#include <margo.h>
#include "my-rpc.h"
......@@ -24,8 +24,6 @@ struct run_my_rpc_args
{
int val;
margo_instance_id mid;
hg_context_t *hg_context;
hg_class_t *hg_class;
hg_addr_t svr_addr;
};
......@@ -40,11 +38,10 @@ int main(int argc, char **argv)
ABT_thread threads[4];
int i;
int ret;
hg_return_t hret;
ABT_xstream xstream;
ABT_pool pool;
margo_instance_id mid;
hg_context_t *hg_context;
hg_class_t *hg_class;
hg_addr_t svr_addr = HG_ADDR_NULL;
hg_handle_t handle;
char proto[12] = {0};
......@@ -55,42 +52,24 @@ int main(int argc, char **argv)
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];
hg_class = HG_Init(proto, HG_FALSE);
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 */
/* 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). The rpc handler pool
* is null in this example program because this is a pure client that
* will not be servicing rpc requests.
*/
/***************************************/
ret = ABT_init(argc, argv);
if(ret != 0)
mid = margo_init(proto, MARGO_CLIENT_MODE, 0, 0);
if(mid == MARGO_INSTANCE_NULL)
{
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");
fprintf(stderr, "Error: margo_init()\n");
return(-1);
}
......@@ -108,31 +87,20 @@ int main(int argc, char **argv)
return(-1);
}
/* actually start margo */
/* Use main process to drive progress (it will relinquish control to
* Mercury during blocking communication calls). The rpc handler pool
* is null in this example program because this is a pure client that
* will not be servicing rpc requests.
*/
/***************************************/
mid = margo_init_pool(pool, ABT_POOL_NULL, hg_context);
/* register RPC */
my_rpc_hang_id = MERCURY_REGISTER(hg_class, "my_rpc_hang", my_rpc_hang_in_t, my_rpc_hang_out_t,
/* register RPCs */
my_rpc_hang_id = MARGO_REGISTER(mid, "my_rpc_hang", my_rpc_hang_in_t, my_rpc_hang_out_t,
NULL);
my_rpc_shutdown_id = MERCURY_REGISTER(hg_class, "my_shutdown_rpc", void, void,
my_rpc_shutdown_id = MARGO_REGISTER(mid, "my_shutdown_rpc", void, void,
NULL);
/* find addr for server */
ret = margo_addr_lookup(mid, argv[1], &svr_addr);
assert(ret == 0);
hret = margo_addr_lookup(mid, argv[1], &svr_addr);
assert(hret == HG_SUCCESS);
for(i=0; i<4; i++)
{
args[i].val = i;
args[i].mid = mid;
args[i].hg_class = hg_class;
args[i].hg_context = hg_context;
args[i].svr_addr = svr_addr;
/* Each ult gets a pointer to an element of the array to use
......@@ -167,22 +135,21 @@ int main(int argc, char **argv)
}
}
/* send one rpc to server to shut it down */
/* create handle */
ret = HG_Create(hg_context, svr_addr, my_rpc_shutdown_id, &handle);
assert(ret == 0);
hret = margo_create(mid, svr_addr, my_rpc_shutdown_id, &handle);
assert(hret == HG_SUCCESS);
margo_forward_timed(mid, handle, NULL, 2000.0);
HG_Addr_free(hg_class, svr_addr);
hret = margo_forward_timed(mid, handle, NULL, 2000.0);
assert(hret == HG_SUCCESS);
margo_destroy(handle);
margo_addr_free(mid, svr_addr);
/* shut down everything */
margo_finalize(mid);
ABT_finalize();
HG_Context_destroy(hg_context);
HG_Finalize(hg_class);
return(0);
}
......@@ -192,10 +159,9 @@ static void run_my_rpc(void *_arg)
hg_handle_t handle;
my_rpc_hang_in_t in;
my_rpc_hang_out_t out;
int ret;
hg_return_t hret;
hg_size_t size;
void* buffer;
const struct hg_info *hgi;
printf("ULT [%d] running.\n", arg->val);
......@@ -206,42 +172,39 @@ static void run_my_rpc(void *_arg)
sprintf((char*)buffer, "Hello world!\n");
/* create handle */
ret = HG_Create(arg->hg_context, arg->svr_addr, my_rpc_hang_id, &handle);
assert(ret == 0);
hret = margo_create(arg->mid, arg->svr_addr, my_rpc_hang_id, &handle);
assert(hret == HG_SUCCESS);
/* register buffer for rdma/bulk access by server */
hgi = HG_Get_info(handle);
assert(hgi);
ret = HG_Bulk_create(hgi->hg_class, 1, &buffer, &size,
hret = margo_bulk_create(arg->mid, 1, &buffer, &size,
HG_BULK_READ_ONLY, &in.bulk_handle);
assert(ret == 0);
assert(hret == HG_SUCCESS);
/* Send rpc. Note that we are also transmitting the bulk handle in the
* input struct. It was set above.
*/
in.input_val = arg->val;
/* call with 2 second timeout */
ret = margo_forward_timed(arg->mid, handle, &in, 2000.0);
hret = margo_forward_timed(arg->mid, handle, &in, 2000.0);
if(ret == 0)
if(hret == HG_SUCCESS)
{
/* decode response */
ret = HG_Get_output(handle, &out);
assert(ret == 0);
hret = margo_get_output(handle, &out);
assert(hret == HG_SUCCESS);
printf("Got response ret: %d\n", out.ret);
HG_Free_output(handle, &out);
margo_free_output(handle, &out);
}
else
{
printf("margo_forward returned %d\n", ret);
printf("margo_forward returned %d\n", hret);
}
/* clean up resources consumed by this rpc */
HG_Bulk_free(in.bulk_handle);
HG_Destroy(handle);
margo_bulk_free(in.bulk_handle);
margo_destroy(handle);
free(buffer);
printf("ULT [%d] done.\n", arg->val);
return;
}
......@@ -7,8 +7,8 @@
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <mercury.h>
#include <abt.h>
#include <abt-snoozer.h>
#include <margo.h>
#include "my-rpc.h"
......@@ -24,8 +24,6 @@ struct run_my_rpc_args
{
int val;
margo_instance_id mid;
hg_context_t *hg_context;
hg_class_t *hg_class;
hg_addr_t svr_addr;
};
......@@ -40,11 +38,10 @@ int main(int argc, char **argv)
ABT_thread threads[4];
int i;
int ret;
hg_return_t hret;
ABT_xstream xstream;
ABT_pool pool;
margo_instance_id mid;
hg_context_t *hg_context;
hg_class_t *hg_class;
hg_addr_t svr_addr = HG_ADDR_NULL;
hg_handle_t handle;
char proto[12] = {0};
......@@ -55,42 +52,24 @@ int main(int argc, char **argv)
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];
hg_class = HG_Init(proto, HG_FALSE);
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 */
/* 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). The rpc handler pool
* is null in this example program because this is a pure client that
* will not be servicing rpc requests.
*/
/***************************************/
ret = ABT_init(argc, argv);
if(ret != 0)
mid = margo_init(proto, MARGO_CLIENT_MODE, 0, 0);
if(mid == MARGO_INSTANCE_NULL)
{
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");
fprintf(stderr, "Error: margo_init()\n");
return(-1);
}
......@@ -100,38 +79,26 @@ int main(int argc, char **argv)
{
fprintf(stderr, "Error: ABT_xstream_self()\n");
return(-1);
} ret = ABT_xstream_get_main_pools(xstream, 1, &pool);
}
ret = ABT_xstream_get_main_pools(xstream, 1, &pool);
if(ret != 0)
{
fprintf(stderr, "Error: ABT_xstream_get_main_pools()\n");
return(-1);
}
/* actually start margo */
/* Use main process to drive progress (it will relinquish control to
* Mercury during blocking communication calls). The rpc handler pool
* is null in this example program because this is a pure client that
* will not be servicing rpc requests.
*/
/***************************************/
mid = margo_init_pool(pool, ABT_POOL_NULL, hg_context);
/* register RPC */
my_rpc_id = MERCURY_REGISTER(hg_class, "my_rpc", my_rpc_in_t, my_rpc_out_t,
NULL);
my_rpc_shutdown_id = MERCURY_REGISTER(hg_class, "my_shutdown_rpc", void, void,
NULL);
/* register RPCs */
my_rpc_id = MARGO_REGISTER(mid, "my_rpc", my_rpc_in_t, my_rpc_out_t, NULL);
my_rpc_shutdown_id = MARGO_REGISTER(mid, "my_shutdown_rpc", void, void, NULL);
/* find addr for server */
ret = margo_addr_lookup(mid, argv[1], &svr_addr);
assert(ret == 0);
hret = margo_addr_lookup(mid, argv[1], &svr_addr);
assert(hret == HG_SUCCESS);
for(i=0; i<4; i++)
{
args[i].val = i;
args[i].mid = mid;
args[i].hg_class = hg_class;
args[i].hg_context = hg_context;
args[i].svr_addr = svr_addr;
/* Each ult gets a pointer to an element of the array to use
......@@ -169,21 +136,18 @@ int main(int argc, char **argv)
/* send one rpc to server to shut it down */
/* create handle */
ret = HG_Create(hg_context, svr_addr, my_rpc_shutdown_id, &handle);
assert(ret == 0);
hret = margo_create(mid, svr_addr, my_rpc_shutdown_id, &handle);
assert(hret == HG_SUCCESS);
margo_forward(mid, handle, NULL);
hret = margo_forward(mid, handle, NULL);
assert(hret == HG_SUCCESS);
HG_Addr_free(hg_class, svr_addr);
margo_destroy(handle);
margo_addr_free(mid, svr_addr);
/* shut down everything */
margo_finalize(mid);
ABT_finalize();
HG_Context_destroy(hg_context);
HG_Finalize(hg_class);
return(0);
}
......@@ -193,10 +157,9 @@ static void run_my_rpc(void *_arg)
hg_handle_t handle;
my_rpc_in_t in;
my_rpc_out_t out;
int ret;
hg_return_t hret;
hg_size_t size;
void* buffer;
const struct hg_info *hgi;
printf("ULT [%d] running.\n", arg->val);
......@@ -207,35 +170,33 @@ static void run_my_rpc(void *_arg)
sprintf((char*)buffer, "Hello world!\n");
/* create handle */
ret = HG_Create(arg->hg_context, arg->svr_addr, my_rpc_id, &handle);
assert(ret == 0);
hret = margo_create(arg->mid, arg->svr_addr, my_rpc_id, &handle);
assert(hret == HG_SUCCESS);
/* register buffer for rdma/bulk access by server */
hgi = HG_Get_info(handle);
assert(hgi);
ret = HG_Bulk_create(hgi->hg_class, 1, &buffer, &size,
hret = margo_bulk_create(arg->mid, 1, &buffer, &size,
HG_BULK_READ_ONLY, &in.bulk_handle);
assert(ret == 0);
assert(hret == HG_SUCCESS);
/* Send rpc. Note that we are also transmitting the bulk handle in the
* input struct. It was set above.
*/
in.input_val = arg->val;
margo_forward(arg->mid, handle, &in);
hret = margo_forward(arg->mid, handle, &in);
assert(hret == HG_SUCCESS);
/* decode response */
ret = HG_Get_output(handle, &out);
assert(ret == 0);
hret = margo_get_output(handle, &out);
assert(hret == HG_SUCCESS);
printf("Got response ret: %d\n", out.ret);
/* clean up resources consumed by this rpc */
HG_Bulk_free(in.bulk_handle);
HG_Free_output(handle, &out);
HG_Destroy(handle);
margo_bulk_free(in.bulk_handle);
margo_free_output(handle, &out);
margo_destroy(handle);
free(buffer);
printf("ULT [%d] done.\n", arg->val);
return;
}
......@@ -7,13 +7,13 @@
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <mercury.h>
#include <abt.h>
#include <abt-snoozer.h>
#include <margo.h>
#include "my-rpc.h"
/* example server program. Starts HG engine, registers the example RPC type,
/* example server program. Starts margo, registers the example RPC type,
* and then executes indefinitely.
*/
......@@ -28,31 +28,26 @@ static void parse_args(int argc, char **argv, struct options *opts);
int main(int argc, char **argv)
{
int ret;
hg_return_t hret;
margo_instance_id mid;
ABT_xstream handler_xstream;
ABT_pool handler_pool;
ABT_xstream progress_xstream;
ABT_pool progress_pool;
hg_context_t *hg_context;
hg_class_t *hg_class;
struct options opts;
parse_args(argc, argv, &opts);
/* boilerplate HG initialization steps */
/* actually start margo -- this step encapsulates the Mercury and
* Argobots initialization and must precede their use */
/* If single pool mode, use the calling xstream to drive progress and
* execute handlers. If not, use a dedicated progress xstream and
* run handlers directly on the calling xstream
*/
/***************************************/
hg_class = HG_Init(opts.listen_addr, HG_TRUE);
if(!hg_class)
{
fprintf(stderr, "Error: HG_Init()\n");
return(-1);
}
hg_context = HG_Context_create(hg_class);
if(!hg_context)
if(opts.single_pool_mode)
mid = margo_init(opts.listen_addr, MARGO_SERVER_MODE, 0, -1);
else
mid = margo_init(opts.listen_addr, MARGO_SERVER_MODE, 1, 0);
if(mid == MARGO_INSTANCE_NULL)
{
fprintf(stderr, "Error: HG_Context_create()\n");
HG_Finalize(hg_class);
fprintf(stderr, "Error: margo_init()\n");
return(-1);
}
......@@ -64,32 +59,28 @@ int main(int argc, char **argv)
hg_size_t addr_self_string_sz = 128;
/* figure out what address this server is listening on */
ret = HG_Addr_self(hg_class, &addr_self);
if(ret != HG_SUCCESS)
hret = margo_addr_self(mid, &addr_self);
if(hret != HG_SUCCESS)
{
fprintf(stderr, "Error: HG_Addr_self()\n");
HG_Context_destroy(hg_context);
HG_Finalize(hg_class);
fprintf(stderr, "Error: margo_addr_self()\n");
margo_finalize(mid);
return(-1);
}
ret = HG_Addr_to_string(hg_class, addr_self_string, &addr_self_string_sz, addr_self);
if(ret != HG_SUCCESS)
hret = margo_addr_to_string(mid, addr_self_string, &addr_self_string_sz, addr_self);
if(hret != HG_SUCCESS)
{
fprintf(stderr, "Error: HG_Addr_self()\n");
HG_Context_destroy(hg_context);
HG_Finalize(hg_class);
HG_Addr_free(hg_class, addr_self);
fprintf(stderr, "Error: margo_addr_self()\n");
margo_addr_free(mid, addr_self);
margo_finalize(mid);
return(-1);
}
HG_Addr_free(hg_class, addr_self);
margo_addr_free(mid, addr_self);
fp = fopen(opts.hostfile, "w");
if(!fp)
{
perror("fopen");
HG_Context_destroy(hg_context);
HG_Finalize(hg_class);
HG_Addr_free(hg_class, addr_self);
margo_finalize(mid);
return(-1);
}
......@@ -97,67 +88,13 @@ int main(int argc, char **argv)
fclose(fp);
}
/* 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);
}
/* Find primary pool to use for running rpc handlers */
ret = ABT_xstream_self(&handler_xstream);
if(ret != 0)
{
fprintf(stderr, "Error: ABT_xstream_self()\n");
return(-1);
}
ret = ABT_xstream_get_main_pools(handler_xstream, 1, &handler_pool);
if(ret != 0)
{
fprintf(stderr, "Error: ABT_xstream_get_main_pools()\n");
return(-1);
}
if(!opts.single_pool_mode)
{
/* create a dedicated ES drive Mercury progress */
ret = ABT_snoozer_xstream_create(1, &progress_pool, &progress_xstream);
if(ret != 0)
{
fprintf(stderr, "Error: ABT_snoozer_xstream_create()\n");
return(-1);
}
}
/* actually start margo */
/* provide argobots pools for driving communication progress and
* executing rpc handlers as well as class and context for Mercury
* communication.
*/
/***************************************/
if(opts.single_pool_mode)
mid = margo_init_pool(handler_pool, handler_pool, hg_context);
else
mid = margo_init_pool(progress_pool, handler_pool, hg_context);
assert(mid);
/* register RPC */
MERCURY_REGISTER(hg_class, "my_rpc", my_rpc_in_t, my_rpc_out_t,
my_rpc_ult_handler);
MERCURY_REGISTER(hg_class, "my_rpc_hang", my_rpc_hang_in_t, my_rpc_hang_out_t,
my_rpc_hang_ult_handler);
MERCURY_REGISTER(hg_class, "my_shutdown_rpc", void, void,
my_rpc_shutdown_ult_handler);
MARGO_REGISTER(mid, "my_rpc", my_rpc_in_t, my_rpc_out_t,
my_rpc_ult);
MARGO_REGISTER(mid, "my_rpc_hang", my_rpc_hang_in_t, my_rpc_hang_out_t,
my_rpc_hang_ult);
MARGO_REGISTER(mid, "my_shutdown_rpc", void, void,
my_rpc_shutdown_ult);
/* NOTE: at this point this server ULT has two options. It can wait on
* whatever mechanism it wants to (however long the daemon should run and
......@@ -175,17 +112,6 @@ int main(int argc, char **argv)
*/
margo_wait_for_finalize(mid);
if(!opts.single_pool_mode)
{
ABT_xstream_join(progress_xstream);
ABT_xstream_free(&progress_xstream);
}
ABT_finalize();
HG_Context_destroy(hg_context);
HG_Finalize(hg_class);
return(0);
}
......
......@@ -10,7 +10,6 @@
#include <stdlib.h>
#include <ctype.h>
#include <abt.h>
#include <abt-snoozer.h>
#include <margo.h>
static int use_abt_sleep = 0;
......@@ -27,8 +26,6 @@ int main(int argc, char **argv)
int ret;
ABT_xstream xstream;
ABT_pool pool;
hg_context_t *hg_context;
hg_class_t *hg_class;
int arg_ndx = 1;
if(argc > 1)
......@@ -52,43 +49,22 @@ int main(int argc, char **argv)
}
}
/* boilerplate HG initialization steps */
/* actually start margo -- this step encapsulates the Mercury and
* Argobots initialization and must precede their use */
/* use a single pool for progress and sleeper threads */
/* NOTE: we don't use RPC handlers, so no need for an RPC pool */
/***************************************/
hg_class = HG_Init("tcp", HG_FALSE);
if(!hg_class)
mid = margo_init("tcp", MARGO_CLIENT_MODE, 0, 0);
if(mid == MARGO_INSTANCE_NULL)
{
/* if tcp didn't work, try sm */
hg_class = HG_Init("sm", HG_FALSE);
if(!hg_class)
mid = margo_init("sm", MARGO_CLIENT_MODE, 0, 0);
if(mid == MARGO_INSTANCE_NULL)
{
fprintf(stderr, "Error: HG_Init()\n");
fprintf(stderr, "Error: margo_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);
}
/* retrieve current pool to use for ULT creation */
ret = ABT_xstream_self(&xstream);
......@@ -104,11 +80,6 @@ int main(int argc, char **argv)
return(-1);
}
/* actually start margo */
/* use a single pool for progress and sleeper threads */
/* NOTE: we don't use RPC handlers, so no need for an RPC pool */
/***************************************/
mid = margo_init_pool(pool, ABT_POOL_NULL, hg_context);
for(i=0; i<4; i++)
{
t_ids[i] = i;
......@@ -146,11 +117,6 @@ int main(int argc, char **argv)
/* shut down everything */
margo_finalize(mid);
ABT_finalize();
HG_Context_destroy(hg_context);
HG_Finalize(hg_class);
return(0);
}
......
......@@ -23,19 +23,19 @@ static void my_rpc_ult(hg_handle_t handle)
hg_return_t hret;
my_rpc_out_t out;
my_rpc_in_t in;
int ret;
hg_size_t size;
void *buffer;
hg_bulk_t bulk_handle;
const struct hg_info *hgi;
#if 0
int ret;
int fd;
char filename[256];
#endif
margo_instance_id mid;
ret = HG_Get_input(handle, &in);
assert(ret == HG_SUCCESS);
hret = margo_get_input(handle, &in);
assert(hret == HG_SUCCESS);