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

#ifndef __MARGO
#define __MARGO

#include <mercury_bulk.h>
#include <mercury.h>
#include <mercury_macros.h>
#include <abt.h>
#include <ev.h>

16 17 18 19

struct margo_instance;
typedef struct margo_instance* margo_instance_id;

20 21 22
/**
 * Initializes margo library, including initializing underlying libevfibers
 *    and Mercury instances.
Philip Carns's avatar
Philip Carns committed
23 24 25 26
 * @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
 * @param [in] hg_class Mercury class
27
 * @returns margo instance id on success, NULL upon error
28
 */
29 30
margo_instance_id margo_init(ABT_pool progress_pool, ABT_pool handler_pool,
    hg_context_t *hg_context, hg_class_t *hg_class);
31 32 33

/**
 * Shuts down margo library and its underlying evfibers and mercury resources
Philip Carns's avatar
Philip Carns committed
34
 * @param [in] mid Margo instance
35
 */
36
void margo_finalize(margo_instance_id mid);
37 38

/**
Philip Carns's avatar
Philip Carns committed
39 40 41
 * Retrieve the abt_handler pool that was associated with the instance at 
 *    initialization time
 * @param [in] mid Margo instance
42
 */
43
ABT_pool* margo_get_handler_pool(margo_instance_id mid);
44 45 46

/**
 * Forward an RPC request to a remote host
Philip Carns's avatar
Philip Carns committed
47
 * @param [in] mid Margo instance
48 49 50 51 52
 * @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
 */
hg_return_t margo_forward(
53
    margo_instance_id mid,
54 55 56 57 58
    hg_handle_t handle,
    void *in_struct);

/** 
 * Perform a bulk transfer
Philip Carns's avatar
Philip Carns committed
59
 * @param [in] mid Margo instance
60 61 62 63 64 65 66 67 68 69 70
 * @param [in] context Mercury bulk context
 * @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(
71
    margo_instance_id mid,
72 73 74 75 76 77 78 79 80
    hg_bulk_context_t *context,
    hg_bulk_op_t op,
    na_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);

Philip Carns's avatar
Philip Carns committed
81 82 83 84
/**
 * Retrive the Margo instance that has been associated with a Mercury class
 * @param [in] class Mercury class
 * @returns Margo instance on success, NULL on error
85 86 87
 */
margo_instance_id margo_hg_class_to_instance(hg_class_t *class);

88 89 90 91 92
/**
 * macro that defines a function to glue an RPC handler to a fiber
 * @param [in] __name name of handler function
 */
#define DEFINE_ARGO_RPC_HANDLER(__name) \
93
hg_return_t __name##_handler(hg_handle_t handle) { \
94 95
    int __ret; \
    ABT_pool* __pool; \
96 97
    margo_instance_id __mid; \
    struct hg_info *__hgi; \
98 99 100
    hg_handle_t* __handle = malloc(sizeof(*__handle)); \
    if(!__handle) return(HG_NOMEM_ERROR); \
    *__handle = handle; \
101 102
    __hgi = HG_Get_info(handle); \
    __mid = margo_hg_class_to_instance(__hgi->hg_class); \
103
    __pool = margo_get_handler_pool(__mid); \
104 105 106 107 108 109 110
    __ret = ABT_thread_create(*__pool, __name, __handle, ABT_THREAD_ATTR_NULL, NULL); \
    if(__ret != 0) { \
        return(HG_NOMEM_ERROR); \
    } \
    return(HG_SUCCESS); \
}

Philip Carns's avatar
Philip Carns committed
111 112 113 114 115
/**
 * macro that declares the prototype for a function to glue an RPC 
 * handler to a fiber
 * @param [in] __name name of handler function
 */
116 117
#define DECLARE_ARGO_RPC_HANDLER(__name) hg_return_t __name##_handler(hg_handle_t handle);

118
#endif /* __MARGO */