GitLab maintenance scheduled for Today, 2019-09-24, from 12:00 to 13:00 CT - Services will be unavailable during this time.

margo.h 27 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*
 * (C) 2015 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

#ifndef __MARGO
#define __MARGO

10 11 12 13
#ifdef __cplusplus
extern "C" {
#endif

14 15 16 17 18 19
/* This is to prevent the user from usin HG_Register_data
 * and HG_Registered_data, which are replaced with
 * margo_register_data and margo_registered_data
 * respecively.
 */

20
#include <mercury.h>
21 22
#include <mercury_types.h>
#include <mercury_bulk.h>
23 24 25
#include <mercury_macros.h>
#include <abt.h>

26 27 28 29
/* determine how much of the Mercury ID space to use for Margo provider IDs */
#define __MARGO_PROVIDER_ID_SIZE (sizeof(hg_id_t)/4)
#define __MARGO_RPC_HASH_SIZE (__MARGO_PROVIDER_ID_SIZE * 3)

30 31
#undef MERCURY_REGISTER

32 33
struct margo_instance;
typedef struct margo_instance* margo_instance_id;
34
typedef struct margo_data* margo_data_ptr;
35
typedef ABT_eventual margo_request;
36

37
#define MARGO_INSTANCE_NULL ((margo_instance_id)NULL)
38
#define MARGO_REQUEST_NULL ABT_EVENTUAL_NULL
39 40
#define MARGO_CLIENT_MODE 0
#define MARGO_SERVER_MODE 1
41
#define MARGO_DEFAULT_PROVIDER_ID 0
Philip Carns's avatar
Philip Carns committed
42
#define MARGO_MAX_PROVIDER_ID (1 << (8*__MARGO_PROVIDER_ID_SIZE))
43

44
#define MARGO_PARAM_PROGRESS_TIMEOUT_UB 1
45

46 47
/**
 * Initializes margo library.
48
 * @param [in] addr_str            Mercury host address with port number
49 50 51
 * @param [in] mode                Mode to run Margo in:
 *                                     - MARGO_CLIENT_MODE
 *                                     - MARGO_SERVER_MODE
52 53
 * @param [in] use_progress_thread Boolean flag to use a dedicated thread for
 *                                 running Mercury's progress loop. If false,
54
 *                                 it will run in the caller's thread context.
55 56
 * @param [in] rpc_thread_count    Number of threads to use for running RPC
 *                                 calls. A value of 0 directs Margo to execute
57 58 59 60 61 62
 *                                 RPCs in the caller's thread context.
 *                                 Clients (i.e processes that will *not* 
 *                                 service incoming RPCs) should use a value 
 *                                 of 0. A value of -1 directs Margo to use 
 *                                 the same execution context as that used 
 *                                 for Mercury progress.
63
 * @returns margo instance id on success, MARGO_INSTANCE_NULL upon error
64 65 66 67 68
 *
 * NOTE: Servers (processes expecting to service incoming RPC requests) must
 * specify non-zero values for use_progress_thread and rpc_thread_count *or*
 * call margo_wait_for_finalize() after margo_init() to relinguish control to 
 * Margo.
69
 */
70 71
margo_instance_id margo_init(
    const char *addr_str,
72
    int mode,
73 74
    int use_progress_thread,
    int rpc_thread_count);
75

76
/**
Jonathan Jenkins's avatar
Jonathan Jenkins committed
77
 * Initializes margo library from given argobots and Mercury instances.
Philip Carns's avatar
Philip Carns committed
78 79 80
 * @param [in] progress_pool Argobots pool to drive communication
 * @param [in] handler_pool Argobots pool to service RPC handlers
 * @param [in] hg_context Mercury context
Jonathan Jenkins's avatar
Jonathan Jenkins committed
81
 * @returns margo instance id on success, MARGO_INSTANCE_NULL upon error
82 83 84 85 86 87 88 89 90 91
 *
 * NOTE: if you are configuring Argobots pools yourself before
 * passing them into this function, please consider setting
 * ABT_MEM_MAX_NUM_STACKS to a low value (like 8) either in your
 * environment or programmatically with putenv() in your code before
 * creating the pools to prevent excess memory consumption under
 * load from producer/consumer patterns across execution streams that
 * fail to utilize per-execution stream stack caches.  See
 * https://xgitlab.cels.anl.gov/sds/margo/issues/40 for details.
 * The margo_init() function does this automatically.
92
 */
93 94 95
margo_instance_id margo_init_pool(
    ABT_pool progress_pool,
    ABT_pool handler_pool,
96
    hg_context_t *hg_context);
97 98

/**
Philip Carns's avatar
Philip Carns committed
99
 * Shuts down margo library and its underlying abt and mercury resources
Philip Carns's avatar
Philip Carns committed
100
 * @param [in] mid Margo instance
101
 */
102 103
void margo_finalize(
    margo_instance_id mid);
104 105 106 107 108 109 110 111 112 113 114

/**
 * Suspends the caller until some other entity (e.g. an RPC, thread, or
 * signal handler) invokes margo_finalize().
 *
 * NOTE: This informs Margo that the calling thread no longer needs to be 
 * scheduled for execution if it is sharing an Argobots pool with the
 * progress engine.
 *
 * @param [in] mid Margo instance
 */
115 116
void margo_wait_for_finalize(
    margo_instance_id mid);
117

118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
/**
 * Installs a callback to be called before the margo instance is finalize.
 * Callbacks installed will be called in reverse ordered than they have been
 * pushed, and with the user-provider pointer as argument.
 *
 * Note that callbacks may not be called within margo_finalize. They are called
 * when the margo instance is cleaned up, which may happen in margo_wait_for_finalize.
 *
 * @param mid The margo instance
 * @param cb Callback to install
 * @param uargs User-provider argument to pass to the callback when called
 */
void margo_push_finalize_callback(
    margo_instance_id mid,
    void(*cb)(void*), 
    void* uargs);

Matthieu Dorier's avatar
Matthieu Dorier committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
/**
 * Allows the passed Margo instance to be shut down remotely
 * using margo_shutdown_remote_instance().
 * 
 * @param mid Margo instance
 */
void margo_enable_remote_shutdown(margo_instance_id mid);

/**
 * Trigger the shutdown of the Margo instance running
 * at remote_addr.
 *
 * @param mid Local Margo instance
 * @param remote_addr Address of the Margo instance to shut down.
 *
 * @return 0 on success, -1 on failure.
 */
int margo_shutdown_remote_instance(
        margo_instance_id mid, 
        hg_addr_t remote_addr);

156 157
/** 
 * Registers an RPC with margo
158 159 160 161 162 163 164 165
 *
 * \param [in] mid Margo instance
 * \param [in] func_name unique function name for RPC
 * \param [in] in_proc_cb pointer to input proc callback
 * \param [in] out_proc_cb pointer to output proc callback
 * \param [in] rpc_cb RPC callback
 *
 * \return unique ID associated to the registered function
166
 */
167 168 169 170 171 172
hg_id_t margo_register_name(
    margo_instance_id mid,
    const char *func_name,
    hg_proc_cb_t in_proc_cb,
    hg_proc_cb_t out_proc_cb,
    hg_rpc_cb_t rpc_cb);
173

174
/** 
175
 * Registers an RPC with margo that is associated with a provider instance
176 177 178 179 180 181
 *
 * \param [in] mid Margo instance
 * \param [in] func_name unique function name for RPC
 * \param [in] in_proc_cb pointer to input proc callback
 * \param [in] out_proc_cb pointer to output proc callback
 * \param [in] rpc_cb RPC callback
182
 * \param [in] provider_id provider identifier
183 184 185
 * \param [in] pool Argobots pool the handler will execute in
 *
 * \return unique ID associated to the registered function
186
 */
187
hg_id_t margo_register_name_provider(
188 189 190 191 192
    margo_instance_id mid,
    const char *func_name,
    hg_proc_cb_t in_proc_cb,
    hg_proc_cb_t out_proc_cb,
    hg_rpc_cb_t rpc_cb,
193
    uint16_t provider_id,
194
    ABT_pool pool);
195

196
/*
197
 * Indicate whether margo_register_name() has been called for the RPC specified by
198 199
 * func_name.
 *
200 201 202 203
 * \param [in] mid Margo instance
 * \param [in] func_name function name
 * \param [out] id registered RPC ID
 * \param [out] flag pointer to boolean
204 205
 *
 * \return HG_SUCCESS or corresponding HG error code
206
 */
207 208 209 210 211
hg_return_t margo_registered_name(
    margo_instance_id mid,
    const char *func_name,
    hg_id_t *id,
    hg_bool_t *flag);
212

213
/**
214
 * Indicate whether the given RPC name has been registered with the given provider id.
215 216 217
 *
 * @param [in] mid Margo instance
 * @param [in] func_name function name
218
 * @param [in] provider_id provider id
219 220 221 222 223
 * @param [out] id registered RPC ID
 * @param [out] flag pointer to boolean
 *
 * @return HG_SUCCESS or corresponding HG error code
 */
224
hg_return_t margo_registered_name_provider(
225 226
    margo_instance_id mid,
    const char *func_name,
227
    uint16_t provider_id,
228 229 230
    hg_id_t *id,
    hg_bool_t *flag);

231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
/**
 * Register and associate user data to registered function.
 * When HG_Finalize() is called free_callback (if defined) is called 
 * to free the registered data.
 *
 * \param [in] mid            Margo instance
 * \param [in] id             registered function ID
 * \param [in] data           pointer to data
 * \param [in] free_callback  pointer to free function
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
hg_return_t margo_register_data(
    margo_instance_id mid,
    hg_id_t id,
    void *data,
    void (*free_callback)(void *));

/**
 * Indicate whether margo_register_data() has been called and return associated
 * data.
 *
 * \param [in] mid        Margo instance 
 * \param [in] id         registered function ID
 *
 * \return Pointer to data or NULL
 */
258 259 260
void* margo_registered_data(
    margo_instance_id mid,
    hg_id_t id);
261

262 263
/**
 * Register and associate user data to registered function for
264
 * a given provider id.
265 266 267 268 269
 * When HG_Finalize() is called free_callback (if defined) is called 
 * to free the registered data.
 *
 * \param [in] mid            Margo instance
 * \param [in] id             registered function ID
270
 * \param [in] provider_id    Margo provider ID
271 272 273 274 275
 * \param [in] data           pointer to data
 * \param [in] free_callback  pointer to free function
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
276
int margo_register_data_provider(
277 278
    margo_instance_id mid,
    hg_id_t id,
279
    uint16_t provider_id,
280 281 282 283
    void* data,
    void (*free_callback)(void *));

/**
284
 * Indicate whether margo_register_data_provider() has been called 
285 286 287 288
 * and return associated data.
 *
 * \param [in] mid        Margo instance 
 * \param [in] id         registered function ID
289
 * \param [in] provider_id Margo provider ID
290 291 292
 *
 * \return Pointer to data or NULL
 */
293
void* margo_registered_data_provider(
294 295
    margo_instance_id mid,
    hg_id_t id,
296
    uint16_t provider_id);
297

298
/**
299
 * Disable response for a given RPC ID.
300
 *
301 302 303
 * \param [in] mid          Margo instance 
 * \param [in] id           registered function ID
 * \param [in] disable_flag flag to disable (1) or re-enable (0) responses
304 305
 *
 * \return HG_SUCCESS or corresponding HG error code
306
 */
307 308 309 310
hg_return_t margo_registered_disable_response(
    margo_instance_id mid,
    hg_id_t id,
    int disable_flag);
311 312 313

/**
 * Lookup an addr from a peer address/name.
314 315 316 317
 * \param [in] name     lookup name
 * \param [out] addr    return address
 *
 * \return HG_SUCCESS or corresponding HG error code
318 319 320
 */
hg_return_t margo_addr_lookup(
    margo_instance_id mid,
321 322
    const char *name,
    hg_addr_t *addr);
323 324

/**
325
 * Free the given Mercury addr.
326
 *
327 328
 * \param [in] mid  Margo instance 
 * \param [in] addr Mercury address
329 330 331
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
332 333 334
hg_return_t margo_addr_free(
    margo_instance_id mid,
    hg_addr_t addr);
335 336

/**
337
 * Access self address. Address must be freed with margo_addr_free().
338
 *
339 340
 * \param [in] mid  Margo instance 
 * \param [in] addr pointer to abstract Mercury address
341 342 343
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
344 345 346
hg_return_t margo_addr_self(
    margo_instance_id mid,
    hg_addr_t *addr);
347 348

/**
349
 * Duplicate an existing Mercury address. 
350
 *
351 352 353
 * \param [in] mid      Margo instance 
 * \param [in] addr     abstract Mercury address to duplicate
 * \param [in] new_addr pointer to newly allocated abstract Mercury address
354 355 356
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
357 358 359 360
hg_return_t margo_addr_dup(
    margo_instance_id mid,
    hg_addr_t addr,
    hg_addr_t *new_addr);
361 362

/**
363 364 365 366 367
 * Convert a Mercury addr to a string (returned string includes the
 * terminating null byte '\0'). If buf is NULL, the address is not
 * converted and only the required size of the buffer is returned.
 * If the input value passed through buf_size is too small, HG_SIZE_ERROR
 * is returned and the buf_size output is set to the minimum size required.
368
 *
369 370 371 372
 * \param [in] mid          Margo instance 
 * \param [in/out] buf      pointer to destination buffer
 * \param [in/out] buf_size pointer to buffer size
 * \param [in] addr         abstract Mercury address
373 374 375
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
376 377 378 379 380
hg_return_t margo_addr_to_string(
    margo_instance_id mid,
    char *buf,
    hg_size_t *buf_size,
    hg_addr_t addr);
381 382

/**
383 384 385 386
 * Initiate a new Mercury RPC using the specified function ID and the
 * local/remote target defined by addr. The handle created can be used to
 * query input and output, as well as issuing the RPC by calling
 * HG_Forward(). After completion the handle must be freed using HG_Destroy().
387
 *
388 389 390 391
 * \param [in] mid      Margo instance 
 * \param [in] addr     abstract Mercury address of destination
 * \param [in] id       registered function ID
 * \param [out] handle  pointer to HG handle
392 393 394
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
395 396 397 398 399
hg_return_t margo_create(
    margo_instance_id mid,
    hg_addr_t addr,
    hg_id_t id,
    hg_handle_t *handle);
400 401

/**
402
 * Destroy Mercury handle.
403
 *
Shane Snyder's avatar
Shane Snyder committed
404
 * \param [in] handle   Mercury handle
405 406 407
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
408 409
hg_return_t margo_destroy(
    hg_handle_t handle);
410 411

/**
412
 * Increment ref count on a Mercury handle.
413
 *
414
 * \param [in] handle Mercury handle
415 416 417
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
418
#define margo_ref_incr HG_Ref_incr
419 420 421 422

/**
 * Get info from handle.
 *
423
 * \param [in] handle Mercury handle
424 425 426
 *
 * \return Pointer to info or NULL in case of failure
 */
427
#define margo_get_info HG_Get_info
428 429 430

/**
 * Get input from handle (requires registration of input proc to deserialize
431
 * parameters). Input must be freed using margo_free_input().
432
 *
433 434
 * \param [in] handle           Mercury handle
 * \param [in/out] in_struct    pointer to input structure
435 436 437
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
438
#define margo_get_input HG_Get_input
439 440 441 442

/**
 * Free resources allocated when deserializing the input.
 *
443 444
 * \param [in] handle           Mercury handle
 * \param [in/out] in_struct    pointer to input structure
445 446 447
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
448
#define margo_free_input HG_Free_input
449 450 451

/**
 * Get output from handle (requires registration of output proc to deserialize
452
 * parameters). Output must be freed using margo_free_output().
453
 *
454 455
 * \param [in] handle           Mercury handle
 * \param [in/out] out_struct   pointer to output structure
456 457 458
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
459
#define margo_get_output HG_Get_output
460 461 462 463

/**
 * Free resources allocated when deserializing the output.
 *
464 465
 * \param [in] handle           Mercury handle
 * \param [in/out] out_struct   pointer to output structure
466 467 468
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
469
#define margo_free_output HG_Free_output
470

471 472
/**
 * Forward an RPC request to a remote host
473
 * @param [in] provider ID (may be MARGO_DEFAULT_PROVIDER_ID)
474 475 476 477
 * @param [in] handle identifier for the RPC to be sent
 * @param [in] in_struct input argument struct for RPC
 * @returns 0 on success, hg_return_t values on error
 */
478
hg_return_t margo_forward_provider_id(
479
    uint16_t provider_id,
480 481 482
    hg_handle_t handle,
    void *in_struct);

483 484 485
#define margo_forward(__handle, __in_struct)\
    margo_forward_provider_id(MARGO_DEFAULT_PROVIDER_ID, __handle, __in_struct)

486 487
/**
 * Forward (without blocking) an RPC request to a remote host
488
 * @param [in] provider ID (may be MARGO_DEFAULT_PROVIDER_ID)
489 490 491 492 493
 * @param [in] handle identifier for the RPC to be sent
 * @param [in] in_struct input argument struct for RPC
 * @param [out] req request to wait on using margo_wait
 * @returns 0 on success, hg_return_t values on error
 */
494
hg_return_t margo_iforward_provider_id(
495
    uint16_t provider_id,
496 497 498 499
    hg_handle_t handle,
    void* in_struct,
    margo_request* req);

500 501 502
#define margo_iforward(__handle, __in_struct, __req)\
    margo_forward_provider_id(MARGO_DEFAULT_PROVIDER_ID, __handle, __in_struct, __req)

503 504 505 506 507 508 509 510 511
/**
 * Wait for an operation initiated by a non-blocking
 * margo function (margo_iforward, margo_irespond, etc.)
 * @param [in] req request to wait on
 * @returns 0 on success, hg_return_t values on error
 */
hg_return_t margo_wait(
    margo_request req);

Matthieu Dorier's avatar
Matthieu Dorier committed
512 513 514 515 516 517 518 519 520 521 522 523 524

/**
 * Test if an operation initiated by a non-blocking
 * margo function (margo_iforward, margo_irespond, etc.)
 * has completed.
 *
 * @param [in] req request created by the non-blocking call
 * @param [out] flag 1 if request is completed, 0 otherwise
 *
 * @return 0 on success, ABT error code otherwise
 */
int margo_test(margo_request req, int* flag);

525 526 527 528 529 530 531 532 533 534 535 536
/**
 * Forward an RPC request to a remote host with a user-defined timeout
 * @param [in] handle identifier for the RPC to be sent
 * @param [in] in_struct input argument struct for RPC
 * @param [in] timeout_ms timeout in milliseconds
 * @returns 0 on success, hg_return_t values on error
 */
hg_return_t margo_forward_timed(
    hg_handle_t handle,
    void *in_struct,
    double timeout_ms);

Jonathan Jenkins's avatar
Jonathan Jenkins committed
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
/**
 * Send an RPC response, waiting for completion before returning
 * control to the calling ULT.
 * Note: this call is typically not needed as RPC listeners need not concern
 * themselves with what happens after an RPC finishes. However, there are cases
 * when this is useful (deferring resource cleanup, calling margo_finalize()
 * for e.g. a shutdown RPC).
 * @param [in] handle identifier for the RPC for which a response is being
 * sent
 * @param [in] out_struct output argument struct for response
 * @return HG_SUCCESS on success, hg_return_t values on error. See HG_Respond.
 */
hg_return_t margo_respond(
    hg_handle_t handle,
    void *out_struct);

553 554 555 556 557 558 559 560 561 562 563 564 565
/**
 * Send an RPC response without blocking.
 * @param [in] handle identifier for the RPC for which a response is being
 * sent
 * @param [in] out_struct output argument struct for response
 * @param [out] req request on which to wait using margo_wait
 * @return HG_SUCCESS on success, hg_return_t values on error. See HG_Respond.
 */
hg_return_t margo_irespond(
    hg_handle_t handle,
    void *out_struct,
    margo_request* req);

566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
/**
 * Create an abstract bulk handle from specified memory segments.
 * Memory allocated is then freed when margo_bulk_free() is called.
 * \remark If NULL is passed to buf_ptrs, i.e.,
 * \verbatim margo_bulk_create(mid, count, NULL, buf_sizes, flags, &handle) \endverbatim
 * memory for the missing buf_ptrs array will be internally allocated.
 *
 * \param [in] mid          Margo instance 
 * \param [in] count        number of segments
 * \param [in] buf_ptrs     array of pointers
 * \param [in] buf_sizes    array of sizes
 * \param [in] flags        permission flag:
 *                             - HG_BULK_READWRITE
 *                             - HG_BULK_READ_ONLY
 *                             - HG_BULK_WRITE_ONLY
 * \param [out] handle      pointer to returned abstract bulk handle
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
hg_return_t margo_bulk_create(
    margo_instance_id mid,
    hg_uint32_t count,
    void **buf_ptrs,
    const hg_size_t *buf_sizes,
    hg_uint8_t flags,
    hg_bulk_t *handle);

/**
 * Free bulk handle.
 *
 * \param [in/out] handle   abstract bulk handle
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
hg_return_t margo_bulk_free(
    hg_bulk_t handle);

/**
 * Increment ref count on bulk handle.
 *
 * \param handle [IN]           abstract bulk handle
607 608 609
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
610
#define margo_bulk_ref_incr HG_Bulk_ref_incr
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627

/**
 * Access bulk handle to retrieve memory segments abstracted by handle.
 *
 * \param [in] handle           abstract bulk handle
 * \param [in] offset           bulk offset
 * \param [in] size             bulk size
 * \param [in] flags            permission flag:
 *                                 - HG_BULK_READWRITE
 *                                 - HG_BULK_READ_ONLY
 * \param [in] max_count        maximum number of segments to be returned
 * \param [in/out] buf_ptrs     array of buffer pointers
 * \param [in/out] buf_sizes    array of buffer sizes
 * \param [out] actual_count    actual number of segments returned
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
628
#define margo_bulk_access HG_Bulk_access
629 630 631 632 633 634 635 636

/**
 * Get total size of data abstracted by bulk handle.
 *
 * \param [in] handle   abstract bulk handle
 *
 * \return Non-negative value
 */
637
#define margo_bulk_get_size HG_Bulk_get_size
638 639 640 641 642 643 644 645

/**
 * Get total number of segments abstracted by bulk handle.
 *
 * \param [in] handle   abstract bulk handle
 *
 * \return Non-negative value
 */
646
#define margo_bulk_get_segment_count HG_Bulk_get_segment_count
647 648 649 650 651 652 653 654 655 656 657

/**
 * Get size required to serialize bulk handle.
 *
 * \param [in] handle           abstract bulk handle
 * \param [in] request_eager    boolean (passing HG_TRUE adds size of encoding
 *                              actual data along the handle if handle meets
 *                              HG_BULK_READ_ONLY flag condition)
 *
 * \return Non-negative value
 */
658
#define margo_bulk_get_serialize_size HG_Bulk_get_serialize_size
659 660 661 662 663 664 665 666 667 668 669 670 671 672

/**
 * Serialize bulk handle into a buffer.
 *
 * \param [in/out] buf          pointer to buffer
 * \param [in] buf_size         buffer size
 * \param [in] request_eager    boolean (passing HG_TRUE encodes actual data
 *                              along the handle, which is more efficient for
 *                              small data, this is only valid if bulk handle
 *                              has HG_BULK_READ_ONLY permission)
 * \param [in] handle           abstract bulk handle
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
673
#define margo_bulk_serialize HG_Bulk_serialize
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689

/**
 * Deserialize bulk handle from an existing buffer.
 *
 * \param [in] mid      Margo instance 
 * \param [out] handle  abstract bulk handle
 * \param [in] buf      pointer to buffer
 * \param [in] buf_size buffer size
 *
 * \return HG_SUCCESS or corresponding HG error code
 */
hg_return_t margo_bulk_deserialize(
    margo_instance_id mid,
    hg_bulk_t *handle,
    const void *buf,
    hg_size_t buf_size);
690

691 692
/** 
 * Perform a bulk transfer
Philip Carns's avatar
Philip Carns committed
693
 * @param [in] mid Margo instance
694 695 696 697 698 699 700 701 702 703
 * @param [in] op type of operation to perform
 * @param [in] origin_addr remote Mercury address
 * @param [in] origin_handle remote Mercury bulk memory handle
 * @param [in] origin_offset offset into remote bulk memory to access
 * @param [in] local_handle local bulk memory handle
 * @param [in] local_offset offset into local bulk memory to access
 * @param [in] size size (in bytes) of transfer
 * @returns 0 on success, hg_return_t values on error
 */
hg_return_t margo_bulk_transfer(
704
    margo_instance_id mid,
705
    hg_bulk_op_t op,
706
    hg_addr_t origin_addr,
707 708 709 710
    hg_bulk_t origin_handle,
    size_t origin_offset,
    hg_bulk_t local_handle,
    size_t local_offset,
711
    size_t size);
712

713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
/** 
 * Asynchronously performs a bulk transfer
 * @param [in] mid Margo instance
 * @param [in] op type of operation to perform
 * @param [in] origin_addr remote Mercury address
 * @param [in] origin_handle remote Mercury bulk memory handle
 * @param [in] origin_offset offset into remote bulk memory to access
 * @param [in] local_handle local bulk memory handle
 * @param [in] local_offset offset into local bulk memory to access
 * @param [in] size size (in bytes) of transfer
 * @param [out] req request to wait on using margo_wait
 * @returns 0 on success, hg_return_t values on error
 */
hg_return_t margo_bulk_itransfer(
    margo_instance_id mid,
    hg_bulk_op_t op,
    hg_addr_t origin_addr,
    hg_bulk_t origin_handle,
    size_t origin_offset,
    hg_bulk_t local_handle,
    size_t local_offset,
    size_t size,
    margo_request* req);

737 738 739 740 741 742 743 744
/**
 * Suspends the calling ULT for a specified time duration
 * @param [in] mid Margo instance
 * @param [in] timeout_ms timeout duration in milliseconds
 */
void margo_thread_sleep(
    margo_instance_id mid,
    double timeout_ms);
745

746
/**
747 748 749
 * Retrieve the abt_handler pool that was associated with the instance at 
 *    initialization time
 * @param [in] mid Margo instance
750 751
 * @param [out] pool handler pool
 * @return 0 on success, error code on failure
752
 */
753
int margo_get_handler_pool(margo_instance_id mid, ABT_pool* pool);
754

755 756 757 758 759 760 761
/**
 * Retrieve the rpc handler abt pool that is associated with this handle
 * @param [in] h handle
 * @return pool
 */
ABT_pool margo_hg_handle_get_handler_pool(hg_handle_t h);

762
/**
763 764
 * Retrieve the Mercury context that was associated with this instance at
 *    initialization time
765
 * @param [in] mid Margo instance
766
 * @return the Mercury context used in margo_init
767
 */
768
hg_context_t* margo_get_context(margo_instance_id mid);
769

770 771 772
/**
 * Retrieve the Mercury class that was associated with this instance at
 *    initialization time
773
 * @param [in] mid Margo instance
774
 * @return the Mercury class used in margo_init
775
 */
776
hg_class_t* margo_get_class(margo_instance_id mid);
777

778 779 780 781 782 783 784 785 786
/**
 * Get the margo_instance_id from a received RPC handle.
 *
 * \param [in] h          RPC handle
 * 
 * \return Margo instance
 */
margo_instance_id margo_hg_handle_get_instance(hg_handle_t h);

787 788 789 790 791 792 793 794 795
/**
 * Get the margo_instance_id from an hg_info struct 
 *
 * \param [in] info       hg_info struct 
 * 
 * \return Margo instance
 */
margo_instance_id margo_hg_info_get_instance(const struct hg_info *info);

Philip Carns's avatar
Philip Carns committed
796 797 798 799 800 801 802 803 804 805 806 807 808 809
/**
 * Enables diagnostic collection on specified Margo instance
 *
 * @param [in] mid Margo instance
 * @returns void
 */
void margo_diag_start(margo_instance_id mid);

/**
 * Appends diagnostic statistics (enabled via margo_diag_start()) to specified 
 * output file.
 *
 * @param [in] mid Margo instance
 * @param [in] file output file ("-" for stdout)
810 811
 * @param [in] uniquify flag indicating if file name should have additional
 *   information added to it to make output from different processes unique
Philip Carns's avatar
Philip Carns committed
812 813
 * @returns void
 */
814
void margo_diag_dump(margo_instance_id mid, const char* file, int uniquify);
815

816 817 818 819 820 821 822 823
/**
 * Sets configurable parameters/hints
 *
 * @param [in] mid Margo instance
 * @param [in] option numerical option number
 * @param [out] inout_param used to pass in values
 * @returns void
 */
824
void margo_set_param(margo_instance_id mid, int option, const void *param);
825 826 827 828 829 830 831 832 833

/**
 * Retrieves configurable parameters/hints
 *
 * @param [in] mid Margo instance
 * @param [in] option numerical option number
 * @param [out] param used to pass out values
 * @returns void
 */
834
void margo_get_param(margo_instance_id mid, int option, void *param);
835 836


837 838 839
/**
 * macro that registers a function as an RPC.
 */
840
#define MARGO_REGISTER(__mid, __func_name, __in_t, __out_t, __handler) \
841
    margo_register_name_provider(__mid, __func_name, \
842 843
        BOOST_PP_CAT(hg_proc_, __in_t), \
        BOOST_PP_CAT(hg_proc_, __out_t), \
844 845
        __handler##_handler, \
        MARGO_DEFAULT_PROVIDER_ID, ABT_POOL_NULL);
846

847 848
#define MARGO_REGISTER_PROVIDER(__mid, __func_name, __in_t, __out_t, __handler, __provider_id, __pool) \
    margo_register_name_provider(__mid, __func_name, \
849 850 851
        BOOST_PP_CAT(hg_proc_, __in_t), \
        BOOST_PP_CAT(hg_proc_, __out_t), \
        __handler##_handler, \
852
        __provider_id, __pool);
853

854 855
#define NULL_handler NULL

856
/**
Philip Carns's avatar
Philip Carns committed
857
 * macro that defines a function to glue an RPC handler to a ult handler
858 859
 * @param [in] __name name of handler function
 */
860
#define DEFINE_MARGO_RPC_HANDLER(__name) \
861
hg_return_t __name##_handler(hg_handle_t handle) { \
862
    int __ret; \
863
    ABT_pool __pool; \
864
    margo_instance_id __mid; \
865 866 867
    __mid = margo_hg_handle_get_instance(handle); \
    if(__mid == MARGO_INSTANCE_NULL) { return(HG_OTHER_ERROR); } \
    __pool = margo_hg_handle_get_handler_pool(handle); \
868
    __ret = ABT_thread_create(__pool, (void (*)(void *))__name, handle, ABT_THREAD_ATTR_NULL, NULL); \
869 870 871 872 873 874
    if(__ret != 0) { \
        return(HG_NOMEM_ERROR); \
    } \
    return(HG_SUCCESS); \
}

Philip Carns's avatar
Philip Carns committed
875 876
/**
 * macro that declares the prototype for a function to glue an RPC 
Philip Carns's avatar
Philip Carns committed
877
 * handler to a ult
Philip Carns's avatar
Philip Carns committed
878 879
 * @param [in] __name name of handler function
 */
880
#define DECLARE_MARGO_RPC_HANDLER(__name) hg_return_t __name##_handler(hg_handle_t handle);
881

882 883 884 885
#ifdef __cplusplus
}
#endif

886
#endif /* __MARGO */