Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
margo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
17
Issues
17
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
sds
margo
Commits
69c34459
Commit
69c34459
authored
Aug 24, 2017
by
Shane Snyder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get basic examples code building
parent
370769d2
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
83 additions
and
156 deletions
+83
-156
Makefile.am
Makefile.am
+1
-1
examples/margo-example-client.c
examples/margo-example-client.c
+35
-70
examples/margo-example-server.c
examples/margo-example-server.c
+21
-59
examples/my-rpc.c
examples/my-rpc.c
+23
-19
tests/margo-test-client.c
tests/margo-test-client.c
+0
-1
tests/margo-test-server.c
tests/margo-test-server.c
+0
-1
tests/my-rpc.c
tests/my-rpc.c
+3
-5
No files found.
Makefile.am
View file @
69c34459
...
...
@@ -38,7 +38,7 @@ pkgconfig_DATA = maint/margo.pc
include
Make.rules
include
$(top_srcdir)/src/Makefile.subdir
#
include $(top_srcdir)/examples/Makefile.subdir
include
$(top_srcdir)/examples/Makefile.subdir
#include $(top_srcdir)/examples/multiplex/Makefile.subdir
#include $(top_srcdir)/examples/composition/Makefile.subdir
include
$(top_srcdir)/tests/Makefile.subdir
...
...
examples/margo-example-client.c
View file @
69c34459
...
...
@@ -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,44 +52,26 @@ 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 */
/***************************************/
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
)
/* 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.
*/
mid
=
margo_init
(
proto
,
MARGO_CLIENT_MODE
,
0
,
0
);
if
(
mid
==
MARGO_INSTANCE_NULL
)
{
fprintf
(
stderr
,
"Error:
ABT_snoozer_xstream_self_se
t()
\n
"
);
fprintf
(
stderr
,
"Error:
margo_ini
t()
\n
"
);
return
(
-
1
);
}
margo_diag_start
(
mid
);
/* retrieve current pool to use for ULT creation */
ret
=
ABT_xstream_self
(
&
xstream
);
...
...
@@ -108,26 +87,18 @@ int main(int argc, char **argv)
return
(
-
1
);
}
/* actually start margo */
/***************************************/
mid
=
margo_init
(
0
,
0
,
hg_context
);
assert
(
mid
);
margo_diag_start
(
mid
);
/* register RPC */
MARGO_REGISTER
(
mid
,
"my_rpc"
,
my_rpc_in_t
,
my_rpc_out_t
,
NULL
,
&
my_rpc_id
);
MARGO_REGISTER
(
mid
,
"my_shutdown_rpc"
,
void
,
void
,
NULL
,
&
my_rpc_shutdown_id
);
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
);
h
ret
=
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
...
...
@@ -165,22 +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_D
estroy
(
handle
);
HG_Addr_free
(
hg_class
,
svr_addr
);
margo_d
estroy
(
handle
);
margo_addr_free
(
mid
,
svr_addr
);
/* shut down everything */
margo_diag_dump
(
mid
,
"-"
,
0
);
margo_finalize
(
mid
);
ABT_finalize
();
HG_Context_destroy
(
hg_context
);
HG_Finalize
(
hg_class
);
return
(
0
);
}
...
...
@@ -191,10 +158,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
h
ret
;
hg_size_t
size
;
void
*
buffer
;
const
struct
hg_info
*
hgi
;
printf
(
"ULT [%d] running.
\n
"
,
arg
->
val
);
...
...
@@ -205,32 +171,31 @@ 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_G
et_output
(
handle
,
&
out
);
assert
(
ret
==
0
);
hret
=
margo_g
et_output
(
handle
,
&
out
);
assert
(
hret
==
HG_SUCCESS
);
printf
(
"Got response ret: %d
\n
"
,
out
.
ret
);
/* clean up resources consumed by this rpc */
HG_B
ulk_free
(
in
.
bulk_handle
);
HG_F
ree_output
(
handle
,
&
out
);
HG_D
estroy
(
handle
);
margo_b
ulk_free
(
in
.
bulk_handle
);
margo_f
ree_output
(
handle
,
&
out
);
margo_d
estroy
(
handle
);
free
(
buffer
);
printf
(
"ULT [%d] done.
\n
"
,
arg
->
val
);
...
...
examples/margo-example-server.c
View file @
69c34459
...
...
@@ -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"
...
...
@@ -19,10 +19,8 @@
int
main
(
int
argc
,
char
**
argv
)
{
int
ret
;
hg_return_t
h
ret
;
margo_instance_id
mid
;
hg_context_t
*
hg_context
;
hg_class_t
*
hg_class
;
hg_addr_t
addr_self
;
char
addr_self_string
[
128
];
hg_size_t
addr_self_string_sz
=
128
;
...
...
@@ -34,70 +32,40 @@ int main(int argc, char **argv)
return
(
-
1
);
}
/* boilerplate HG initialization steps */
/***************************************/
hg_class
=
HG_Init
(
argv
[
1
],
HG_TRUE
);
if
(
!
hg_class
)
/* actually start margo -- this step encapsulates the Mercury and
* Argobots initialization and must precede their use */
/* Use the calling xstream to drive progress and execute handlers. */
mid
=
margo_init
(
argv
[
1
],
MARGO_SERVER_MODE
,
0
,
-
1
);
if
(
mid
==
MARGO_INSTANCE_NULL
)
{
fprintf
(
stderr
,
"Error:
HG_I
nit()
\n
"
);
fprintf
(
stderr
,
"Error:
margo_i
nit()
\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
);
}
margo_diag_start
(
mid
);
/* 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
(
h
ret
!=
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
(
h
ret
!=
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
);
printf
(
"# accepting RPCs on address
\"
%s
\"\n
"
,
addr_self_string
);
/* 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
);
assert
(
mid
);
margo_diag_start
(
mid
);
/* register RPC */
MARGO_REGISTER
(
mid
,
"my_rpc"
,
my_rpc_in_t
,
my_rpc_out_t
,
my_rpc_ult
,
MARGO_RPC_ID_IGNORE
);
MARGO_REGISTER
(
mid
,
"my_shutdown_rpc"
,
void
,
void
,
my_rpc_shutdown_ult
,
MARGO_RPC_ID_IGNORE
);
MARGO_REGISTER
(
mid
,
"my_rpc"
,
my_rpc_in_t
,
my_rpc_out_t
,
my_rpc_ult
);
MARGO_REGISTER
(
mid
,
"my_shutdown_rpc"
,
void
,
void
,
my_rpc_shutdown_ult
);
/* NOTE: there isn't anything else for the server to do at this point
* except wait for itself to be shut down. The
...
...
@@ -106,11 +74,5 @@ int main(int argc, char **argv)
*/
margo_wait_for_finalize
(
mid
);
ABT_finalize
();
HG_Context_destroy
(
hg_context
);
HG_Finalize
(
hg_class
);
return
(
0
);
}
examples/my-rpc.c
View file @
69c34459
...
...
@@ -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_G
et_input
(
handle
,
&
in
);
assert
(
ret
==
HG_SUCCESS
);
hret
=
margo_g
et_input
(
handle
,
&
in
);
assert
(
h
ret
==
HG_SUCCESS
);
printf
(
"Got RPC request with input_val: %d
\n
"
,
in
.
input_val
);
out
.
ret
=
0
;
...
...
@@ -45,20 +45,22 @@ static void my_rpc_ult(hg_handle_t handle)
buffer
=
calloc
(
1
,
512
);
assert
(
buffer
);
/*
register local target buffer for bulk access
*/
hgi
=
HG_G
et_info
(
handle
);
/*
get handle info and margo instance
*/
hgi
=
margo_g
et_info
(
handle
);
assert
(
hgi
);
ret
=
HG_Bulk_create
(
hgi
->
hg_class
,
1
,
&
buffer
,
&
size
,
HG_BULK_WRITE_ONLY
,
&
bulk_handle
);
assert
(
ret
==
0
);
mid
=
margo_hg_info_get_instance
(
hgi
);
assert
(
mid
!=
MARGO_INSTANCE_NULL
);
mid
=
margo_hg_handle_get_instance
(
handle
);
/* register local target buffer for bulk access */
hret
=
margo_bulk_create
(
mid
,
1
,
&
buffer
,
&
size
,
HG_BULK_WRITE_ONLY
,
&
bulk_handle
);
assert
(
hret
==
HG_SUCCESS
);
/* do bulk transfer from client to server */
ret
=
margo_bulk_transfer
(
mid
,
HG_BULK_PULL
,
h
ret
=
margo_bulk_transfer
(
mid
,
HG_BULK_PULL
,
hgi
->
addr
,
in
.
bulk_handle
,
0
,
bulk_handle
,
0
,
size
);
assert
(
ret
==
0
);
bulk_handle
,
0
,
size
,
HG_OP_ID_IGNORE
);
assert
(
hret
==
HG_SUCCESS
);
/* write to a file; would be done with abt-io if we enabled it */
#if 0
...
...
@@ -72,13 +74,13 @@ static void my_rpc_ult(hg_handle_t handle)
abt_io_close(aid, fd);
#endif
HG_F
ree_input
(
handle
,
&
in
);
margo_f
ree_input
(
handle
,
&
in
);
hret
=
HG_Respond
(
handle
,
NULL
,
NULL
,
&
out
);
hret
=
margo_respond
(
mid
,
handle
,
&
out
);
assert
(
hret
==
HG_SUCCESS
);
HG_B
ulk_free
(
bulk_handle
);
HG_D
estroy
(
handle
);
margo_b
ulk_free
(
bulk_handle
);
margo_d
estroy
(
handle
);
free
(
buffer
);
return
;
...
...
@@ -93,14 +95,16 @@ static void my_rpc_shutdown_ult(hg_handle_t handle)
printf
(
"Got RPC request to shutdown
\n
"
);
hgi
=
HG_Get_info
(
handle
);
/* get handle info and margo instance */
hgi
=
margo_get_info
(
handle
);
assert
(
hgi
);
mid
=
margo_hg_handle_get_instance
(
handle
);
mid
=
margo_hg_info_get_instance
(
hgi
);
assert
(
mid
!=
MARGO_INSTANCE_NULL
);
hret
=
margo_respond
(
mid
,
handle
,
NULL
);
assert
(
hret
==
HG_SUCCESS
);
HG_D
estroy
(
handle
);
margo_d
estroy
(
handle
);
margo_diag_dump
(
mid
,
"-"
,
0
);
...
...
tests/margo-test-client.c
View file @
69c34459
...
...
@@ -65,7 +65,6 @@ int main(int argc, char **argv)
* is null in this example program because this is a pure client that
* will not be servicing rpc requests.
*/
/***************************************/
mid
=
margo_init
(
proto
,
MARGO_CLIENT_MODE
,
0
,
0
);
if
(
mid
==
MARGO_INSTANCE_NULL
)
{
...
...
tests/margo-test-server.c
View file @
69c34459
...
...
@@ -40,7 +40,6 @@ int main(int argc, char **argv)
* execute handlers. If not, use a dedicated progress xstream and
* run handlers directly on the calling xstream
*/
/***************************************/
if
(
opts
.
single_pool_mode
)
mid
=
margo_init
(
opts
.
listen_addr
,
MARGO_SERVER_MODE
,
0
,
-
1
);
else
...
...
tests/my-rpc.c
View file @
69c34459
...
...
@@ -62,8 +62,6 @@ static void my_rpc_ult(hg_handle_t handle)
bulk_handle
,
0
,
size
,
HG_OP_ID_IGNORE
);
assert
(
hret
==
HG_SUCCESS
);
margo_free_input
(
handle
,
&
in
);
/* write to a file; would be done with abt-io if we enabled it */
#if 0
sprintf(filename, "/tmp/margo-%d.txt", in.input_val);
...
...
@@ -76,6 +74,8 @@ static void my_rpc_ult(hg_handle_t handle)
abt_io_close(aid, fd);
#endif
margo_free_input
(
handle
,
&
in
);
hret
=
margo_respond
(
mid
,
handle
,
&
out
);
assert
(
hret
==
HG_SUCCESS
);
...
...
@@ -104,7 +104,7 @@ static void my_rpc_shutdown_ult(hg_handle_t handle)
hret
=
margo_respond
(
mid
,
handle
,
NULL
);
assert
(
hret
==
HG_SUCCESS
);
HG_D
estroy
(
handle
);
margo_d
estroy
(
handle
);
/* NOTE: we assume that the server daemon is using
* margo_wait_for_finalize() to suspend until this RPC executes, so there
...
...
@@ -170,5 +170,3 @@ static void my_rpc_hang_ult(hg_handle_t handle)
return
;
}
DEFINE_MARGO_RPC_HANDLER
(
my_rpc_hang_ult
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment