ssg.h 3.77 KB
Newer Older
Jonathan Jenkins's avatar
Jonathan Jenkins committed
1
2
3
4
5
6
7
8
/*
 * Copyright (c) 2016 UChicago Argonne, LLC
 *
 * See COPYRIGHT in top-level directory.
 */

#pragma once

Jonathan Jenkins's avatar
Jonathan Jenkins committed
9
// "simple static group" interface
Jonathan Jenkins's avatar
Jonathan Jenkins committed
10
11
12
13
14
15
16
17
18
//
// Contains trivial wireup and connection management functionality, with a
// model of a static (at startup) member list.

#ifdef __cplusplus
extern "C" {
#endif

#include <mercury.h>
Shane Snyder's avatar
Shane Snyder committed
19
20
21
22
23
#include <margo.h>

#ifdef HAVE_MPI
#include <mpi.h>
#endif
Jonathan Jenkins's avatar
Jonathan Jenkins committed
24

Jonathan Jenkins's avatar
Jonathan Jenkins committed
25
// using pointer so that we can use proc (proc has to allocate in this case)
Jonathan Jenkins's avatar
Jonathan Jenkins committed
26
27
28
29
30
31
32
33
34
35
36
37
38
typedef struct ssg *ssg_t;

// some defines
// null pointer shim
#define SSG_NULL ((ssg_t)NULL)
// after init, rank is possibly unknown
#define SSG_RANK_UNKNOWN (-1)
// if ssg_t is gotten from another process (RPC output), then, by definition,
// the receiving entity is not part of the group
#define SSG_EXTERNAL_RANK (-2)

/// participant initialization

39
// config file based - load up the given config file
Jonathan Jenkins's avatar
Jonathan Jenkins committed
40
// containing a set of hostnames
41
42
43
// is_member - nonzero if caller is expected to be in the group, zero otherwise
//           - ssg_lookup fails if caller is unable to identify with one of the
//             config entries
Shane Snyder's avatar
Shane Snyder committed
44
ssg_t ssg_init_config(hg_class_t *hgcl, const char * fname, int is_member);
Jonathan Jenkins's avatar
Jonathan Jenkins committed
45

Shane Snyder's avatar
Shane Snyder committed
46
47
48
49
50
51
52
#ifdef HAVE_MPI
// mpi based (no config file) - all participants (defined by the input
// communicator) do a global address exchange
// in this case, the caller has already initialized HG with its address
ssg_t ssg_init_mpi(hg_class_t *hgcl, MPI_Comm comm);
#endif

53
54
55
56
57
58
59
60
61
62
63
64
// in the config-file initialization, rank determination is deferred until
// lookup. In the case where the rank is needed but you don't want to
// necessarily look up everyone, this call will resolve the rank. In the MPI
// bootstrap mode, or if the rank has already been resolved, this operation
// is a no-op
//
// the ssg_lookup functions implicitly call this
//
// this function works by using string comparison of HG_Addr_to_string against
// the entries in the config file
hg_return_t ssg_resolve_rank(ssg_t s, hg_class_t *hgcl);

Jonathan Jenkins's avatar
Jonathan Jenkins committed
65
// once the ssg has been initialized, wireup (a collection of HG_Addr_lookups)
Jonathan Jenkins's avatar
Jonathan Jenkins committed
66
// note that this is a simple blocking implementation - no margo/etc here
67
hg_return_t ssg_lookup(ssg_t s, hg_context_t *hgctx);
Jonathan Jenkins's avatar
Jonathan Jenkins committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

/// finalization

// teardown all connections associated with the given ssg
void ssg_finalize(ssg_t s);

/// accessors

// get my rank
int ssg_get_rank(const ssg_t s);

// get the number of participants
int ssg_get_count(const ssg_t s);

// get the address for the group member at the given rank
Jonathan Jenkins's avatar
Jonathan Jenkins committed
83
hg_addr_t ssg_get_addr(const ssg_t s, int rank);
Jonathan Jenkins's avatar
Jonathan Jenkins committed
84
85
86
87
88
89
90
91
92

// get the string hostname for the group member at the given rank
const char * ssg_get_addr_str(const ssg_t s, int rank);

/// mercury support

// group serialization mechanism
hg_return_t hg_proc_ssg_t(hg_proc_t proc, ssg_t *s);

93
94
95
96
97
98
99
/// utility functions

// dump address list to the given file
// returns -1 on error, corresponding to the return code of open/write/close,
// and sets errno
int ssg_dump(const ssg_t s, const char *fname);

Shane Snyder's avatar
Shane Snyder committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// set up barrier data structures. Separate call to resolve the margo -> barrier
// race condition - call this before kicking off the progress loop with margo
void ssg_register_barrier(ssg_t s, hg_class_t *hgcl);

// set/get the margo instance id used in margo communication calls
void ssg_set_margo_id(ssg_t s, margo_instance_id mid);
margo_instance_id ssg_get_margo_id(ssg_t s);

// a "margo-aware" version of hg_lookup - still looks up everyone in one go.
// requires ssg_set_margo_id to have been called.
hg_return_t ssg_lookup_margo(ssg_t s);

// perform a naive N-1 barrier using margo.
// requires ssg_set_margo_id to have been called.
// NOTE: rank must be set on all ranks prior to calling this. I.e. should init
// the rank prior to starting up margo
hg_return_t ssg_barrier_margo(ssg_t s);

Jonathan Jenkins's avatar
Jonathan Jenkins committed
118
119
120
121
122
123
124
#ifdef __cplusplus
}
#endif

/**
 * vim: ft=c sw=4 ts=4 sts=4 tw=80 expandtab
 */