KMR
kmrspawn.h
Go to the documentation of this file.
1 /* kmrspawn.h (2016-09-04) -*-Coding: us-ascii;-*- */
2 /* Copyright (C) 2012-2018 RIKEN R-CCS */
3 
4 /** \file kmrspawn.h Static-Spawning API. */
5 
6 /* Parameters for Spawning. KMR_SPAWN_MAGIC is a protocol version.
7  KMR_SPAWN_SUBWORLDS is the maximum number of subworlds which are
8  used as a world of spawning. Subworlds need to be registered
9  beforehand and one is selected at spawning. KMR_SPAWN_ARGS_SIZE is
10  the limit length of a sum of the strings of argv.
11  KMR_SPAWN_RPC_TAG and KMR_SPAWN_ICOMM_TAG are message tags. */
12 
13 #define KMR_SPAWN_MAGIC (20160904)
14 #define KMR_SPAWN_SUBWORLDS (20)
15 #define KMR_SPAWN_ARGS_SIZE (8 * 1024)
16 #define KMR_SPAWN_RPC_TAG (600)
17 #define KMR_SPAWN_ICOMM_TAG (601)
18 
19 /* RPC Message Types. */
20 
21 enum kmr_spawn_req {
22  KMR_SPAWN_NONE, KMR_SPAWN_WORK, KMR_SPAWN_NEXT
23 };
24 
25 /* RPC Message. KMR_SPAWN_NEXT (worker-to-master) is a message to
26  notify a finish of a work-item and to ask for a next one. It is
27  also initially sent as to notify a worker is ready. */
28 
30  enum kmr_spawn_req req;
31  int protocol_version;
32  int initial_message;
33  int status;
34 };
35 
36 /* RPC Message to Send a Work. KMR_SPAWN_WORK (master-to-worker) is a
37  message to start a work-item. Note that the structure of a message
38  is truncated by the size of the argument string. The length set in
39  MESSAGE_SIZE includes the whole structure. SUBWORLD is an index to
40  the vector of subworlds previously registered. NPROCS is the
41  number of ranks used. It is just used to check the size of a
42  communicator. COLOR is a check code of a SUBWORLD index. A color
43  is compared to a value previously registered. */
44 
46  enum kmr_spawn_req req;
47  int protocol_version;
48  int message_size;
49  int subworld;
50  unsigned long color;
51  int nprocs;
52  int print_trace;
53  char args[64 /*KMR_SPAWN_ARGS_SIZE*/];
54 };
55 
56 /* RPC Message. KMR_SPAWN_NONE (master-to-worker) is a message to
57  finish a worker. */
58 
60  enum kmr_spawn_req req;
61  int protocol_version;
62 };
63 
64 /* RPC Message between a Master and Workers. RPC messages are sent by
65  point-to-point because it does not yet established the
66  inter-communicator used for spawning. */
67 
69  enum kmr_spawn_req req;
70  struct kmr_spawn_next m0;
71  struct kmr_spawn_work m1;
72  struct kmr_spawn_none m2;
73 };
74 
75 /* State of MPI Hooks and Spawner. MPI_COMM_WORLD is a pointer to the
76  world communicator (as being Open-MPI); SAVED_GENUINE_WORLD is a
77  copy of the contents of the old world. Note the world reference
78  moves at link time, because it is a variable of static allocation
79  in Open-MPI and thus it is of a copy-relocation. */
80 
82  /* State of Spawner. */
83 
84  struct {
85  /* State of Spawning API. */
86 
87  int master_rank;
88  int base_rank;
89  MPI_Comm base_comm;
90  struct {
91  MPI_Comm comm;
92  unsigned long color;
93  } subworlds[KMR_SPAWN_SUBWORLDS];
94  int (*exec_fn)(struct kmr_spawn_hooks *, int, char **);
95 
96  void /*KMR*/ *mr;
97  union kmr_spawn_rpc *rpc_buffer;
98  size_t rpc_size;
99  int service_count;
100  _Bool print_trace;
101 
102  /* State of Running MPI. */
103 
104  MPI_Comm spawn_world;
105  MPI_Comm spawn_parent;
106  struct kmr_spawn_work *running_work;
107  _Bool mpi_initialized;
108  _Bool abort_when_mpi_abort;
109  } s;
110 
111  /* State for KMR-LD. */
112 
113  struct {
114  char **initial_argv;
115  long options_flags;
116  char *options_heap_bottom;
117  } d;
118 
119  /* Hooks of MPI Library. */
120 
121  struct {
122  void *saved_genuine_world;
123  size_t size_of_comm_data;
124 
125  void (*exit)(int status);
126  void (*raw_exit)(int status);
127  int (*execve)(const char *file, char *const argv[],
128  char *const envp[]);
129 
130  int (*PMPI_Init)(int *argc, char ***argv);
131  int (*PMPI_Init_thread)(int *argc, char ***argv, int required,
132  int *provided);
133  int (*PMPI_Finalize)(void);
134  int (*PMPI_Abort)(MPI_Comm comm, int errorcode);
135  int (*PMPI_Query_thread)(int *provided);
136 
137  /* (Used in this hook). */
138 
139  void *mpi_comm_world; /*ompi_mpi_comm_world*/
140  void *mpi_byte; /*ompi_mpi_byte*/
141  void *mpi_comm_null; /*ompi_mpi_comm_null*/
142 
143  int (*PMPI_Comm_get_parent)(MPI_Comm *parent);
144  int (*PMPI_Comm_get_name)(MPI_Comm comm, char *name, int *len);
145  int (*PMPI_Comm_set_name)(MPI_Comm comm, char *name);
146  int (*PMPI_Comm_size)(MPI_Comm comm, int *size);
147  int (*PMPI_Comm_rank)(MPI_Comm comm, int *rank);
148  int (*PMPI_Comm_remote_size)(MPI_Comm comm, int *size);
149 
150  int (*PMPI_Intercomm_create)(MPI_Comm lcomm, int lleader,
151  MPI_Comm pcomm, int pleader,
152  int tag, MPI_Comm *newcomm);
153  int (*PMPI_Comm_dup)(MPI_Comm comm, MPI_Comm *newcomm);
154  int (*PMPI_Comm_free)(MPI_Comm *comm);
155  int (*PMPI_Send)(void *buf, int count, MPI_Datatype dty,
156  int dst, int tag, MPI_Comm comm);
157  int (*PMPI_Recv)(void *buf, int count, MPI_Datatype dty,
158  int src, int tag, MPI_Comm comm,
159  MPI_Status *status);
160  int (*PMPI_Get_count)(MPI_Status *status, MPI_Datatype dty,
161  int *count);
162 
163  char world_name[MPI_MAX_OBJECT_NAME];
164  } h;
165 };
166 
167 /* API of Wokers. */
168 
169 extern int kmr_spawn_hookup(struct kmr_spawn_hooks *hooks);
170 extern int kmr_spawn_setup(struct kmr_spawn_hooks *hooks,
171  MPI_Comm basecomm, int masterrank,
172  int (*execfn)(struct kmr_spawn_hooks *,
173  int, char **),
174  int nsubworlds,
175  MPI_Comm subworlds[], unsigned long colors[],
176  size_t argssize);
177 extern void kmr_spawn_set_verbosity(struct kmr_spawn_hooks *hooks, int level);
178 extern void kmr_spawn_service(struct kmr_spawn_hooks *hooks, int status);
179 
180 /* (API of Wokers for dummy). */
181 
182 extern int kmr_spawn_hookup_standin(struct kmr_spawn_hooks *hooks);
183 extern int kmr_spawn_setup_standin(struct kmr_spawn_hooks *hooks,
184  MPI_Comm basecomm, int masterrank,
185  int (*execfn)(struct kmr_spawn_hooks *,
186  int, char **),
187  int nsubworlds,
188  MPI_Comm subworlds[],
189  unsigned long colors[],
190  size_t argssize);
191 extern void kmr_spawn_set_verbosity_standin(struct kmr_spawn_hooks *hooks,
192  int level);
193 extern void kmr_spawn_service_standin(struct kmr_spawn_hooks *hooks,
194  int status);
195 
196 /* Calling Unhooked Routines. */
197 
198 extern void kmr_spawn_true_exit(int status);
199 extern int kmr_spawn_true_execve(const char *file, char *const argv[],
200  char *const envp[]);
201 extern int kmr_spawn_true_mpi_finalize(void);
202 extern int kmr_spawn_true_mpi_abort(MPI_Comm comm, int code);
203 
204 /* Calling MPI Routines. */
205 
206 extern int kmr_spawn_mpi_comm_size(MPI_Comm comm, int *size);
207 extern int kmr_spawn_mpi_comm_rank(MPI_Comm comm, int *rank);
208 extern int kmr_spawn_mpi_comm_remote_size(MPI_Comm comm, int *size);
209 extern int kmr_spawn_mpi_comm_get_name(MPI_Comm comm, char *name, int *len);
210 extern int kmr_spawn_mpi_comm_set_name(MPI_Comm comm, char *name);
211 extern int kmr_spawn_mpi_intercomm_create(MPI_Comm lcomm, int lleader,
212  MPI_Comm pcomm, int pleader,
213  int tag, MPI_Comm *icomm);
214 extern int kmr_spawn_mpi_comm_dup(MPI_Comm comm, MPI_Comm *newcomm);
215 extern int kmr_spawn_mpi_comm_free(MPI_Comm *comm);
216 extern int kmr_spawn_mpi_send(void *buf, int count, MPI_Datatype dty,
217  int dst, int tag, MPI_Comm comm);
218 extern int kmr_spawn_mpi_recv(void *buf, int count, MPI_Datatype dty,
219  int src, int tag, MPI_Comm comm,
220  MPI_Status *status);
221 extern int kmr_spawn_mpi_get_count(MPI_Status *status, MPI_Datatype dty,
222  int *count);
223 
224 /*
225 Copyright (C) 2012-2018 RIKEN R-CCS
226 This library is distributed WITHOUT ANY WARRANTY. This library can be
227 redistributed and/or modified under the terms of the BSD 2-Clause License.
228 */