Molssi Driver Interface Library
mdi_global.h
Go to the documentation of this file.
1 
6 #ifndef MDI_GLOBAL
7 #define MDI_GLOBAL
8 
9 #include <mpi.h>
10 
11 #ifdef _WIN32
12  #include <winsock2.h>
13  #define sock_t SOCKET
14 #else
15  #define sock_t int
16 #endif
17 
18 #ifdef _WIN32
19  #define mdi_strdup _strdup
20 #else
21  #define mdi_strdup strdup
22 #endif
23 
24 // Hard-coded values
25 #define PLUGIN_PATH_LENGTH 2048
26 
27 // Defined languages
28 #define MDI_LANGUAGE_C 1
29 #define MDI_LANGUAGE_FORTRAN 2
30 #define MDI_LANGUAGE_PYTHON 3
31 
32 // MDI version numbers
33 #define MDI_MAJOR_VERSION_ 1
34 #define MDI_MINOR_VERSION_ 4
35 #define MDI_PATCH_VERSION_ 1
36 
37 // length of an MDI command in characters
38 #define MDI_COMMAND_LENGTH_ 256
39 
40 // length of an MDI name in characters
41 #define MDI_NAME_LENGTH_ 256
42 
43 // length of an MDI label in characters
44 #define MDI_LABEL_LENGTH_ 64
45 
46 // value of a null communicator
47 #define MDI_COMM_NULL_ 0
48 
49 // MDI data types
50 #define MDI_INT_ 1
51 #define MDI_INT8_T_ 7
52 #define MDI_INT16_T_ 8
53 #define MDI_INT32_T_ 9
54 #define MDI_INT64_T_ 10
55 #define MDI_UINT8_T_ 11
56 #define MDI_UINT16_T_ 12
57 #define MDI_UINT32_T_ 13
58 #define MDI_UINT64_T_ 14
59 #define MDI_DOUBLE_ 2
60 #define MDI_CHAR_ 3
61 #define MDI_FLOAT_ 4
62 #define MDI_BYTE_ 6
63 
64 // MDI communication types
65 #define MDI_TCP_ 1
66 #define MDI_MPI_ 2
67 #define MDI_LINK_ 3
68 #define MDI_TEST_ 4
69 
70 // MDI role types
71 #define MDI_DRIVER_ 1
72 #define MDI_ENGINE_ 2
73 
74 // MDI Typedefs
75 typedef int MDI_Comm_Type;
76 typedef int MDI_Datatype_Type;
77 
78 typedef struct dynamic_array_struct {
80  unsigned char* data;
82  size_t stride;
84  size_t capacity;
86  size_t size; //number of elements actually stored
87 } vector;
88 
89 typedef struct method_struct {
91  int id;
93  int method_id;
95  int (*on_selection)();
96  int (*on_accept_communicator)();
97  int (*on_send_command)(const char*, MDI_Comm_Type, int* skip_flag);
98  int (*after_send_command)(const char*, MDI_Comm_Type);
99  int (*on_recv_command)(MDI_Comm_Type);
100 } method;
101 
102 typedef struct communicator_struct {
106  MDI_Comm_Type id;
110  int code_id;
112  sock_t sockfd;
118  int mdi_version[3];
122  void* method_data;
124  int (*send)(const void*, int, MDI_Datatype_Type, MDI_Comm_Type, int);
126  int (*recv)(void*, int, MDI_Datatype_Type, MDI_Comm_Type, int);
128  int (*delete)(void*);
129 } communicator;
130 
131 typedef struct node_struct {
133  char name[MDI_COMMAND_LENGTH_];
138 } node;
139 
140 typedef struct code_struct {
142  char name[MDI_NAME_LENGTH_];
144  char role[MDI_NAME_LENGTH_];
146  int id;
152  int language;
158  MPI_Comm intra_MPI_comm;
164  char* plugin_path;
166  int (*execute_command)(const char*, MDI_Comm_Type, void*);
174 } code;
175 
178 extern vector codes;
179 
181 extern vector methods;
182 
184 extern int selected_method_id;
185 
187 extern int current_code;
188 
190 extern int ipi_compatibility;
191 
193 extern int is_initialized;
194 
196 extern int initialized_mpi;
197 
199 extern int plugin_mode;
200 
202 extern MPI_Comm mdi_mpi_comm_world;
203 
206 extern void* python_plugin_mpi_world_ptr;
207 
209 extern char* plugin_unedited_options;
210 
212 extern char* plugin_options;
213 
215 extern int plugin_argc;
216 
218 extern char** plugin_argv;
219 
221 extern int (*mpi4py_recv_callback)(void*, int, int, int, MDI_Comm_Type);
222 
224 extern int (*mpi4py_send_callback)(void*, int, int, int, MDI_Comm_Type);
225 
227 extern int (*mpi4py_allgather_callback)(void*, void*);
228 
230 extern int (*mpi4py_gather_names_callback)(void*, void*, int*, int*);
231 
233 extern int (*mpi4py_split_callback)(int, int, MDI_Comm_Type, int);
234 
236 extern int (*mpi4py_rank_callback)(int);
237 
239 extern int (*mpi4py_size_callback)(int);
240 
242 extern int (*mpi4py_barrier_callback)(int);
243 
245 extern int world_size;
246 
248 extern int world_rank;
249 
250 int vector_init(vector* v, size_t stride);
251 int vector_push_back(vector* v, void* element);
252 void* vector_get(vector* v, int index);
253 int vector_delete(vector* v, int index);
254 int vector_free(vector* v);
255 
256 int get_node_index(vector* v, const char* node_name);
257 int get_command_index(node* n, const char* command_name);
258 int get_callback_index(node* n, const char* callback_name);
259 int free_node_vector(vector* v);
260 
261 int new_communicator(int code_id, int method);
262 communicator* get_communicator(int code_id, MDI_Comm_Type comm_id);
263 int delete_communicator(int code_id, MDI_Comm_Type comm_id);
264 
265 int new_code();
266 code* get_code(int code_id);
267 int delete_code(int code_id);
268 
269 int new_method(int method_id);
270 method* get_method(int method_id);
271 int delete_method(int method_id);
272 
274 int file_exists(const char* file_name);
275 
277 int communicator_delete(void* comm);
278 
279 void mdi_error(const char* message);
280 void mdi_warning(const char* message);
281 
283 int datatype_info(MDI_Datatype_Type datatype, size_t* size, MDI_Datatype_Type* base);
284 
286 int datatype_mpitype(MDI_Datatype_Type datatype, MPI_Datatype* mpitype);
287 
289 int convert_buf_datatype(void* recvbuf_in, MDI_Datatype_Type recvtype,
290  void* sendbuf_in, MDI_Datatype_Type sendtype,
291  int count);
292 
293 #endif
communicator_delete
int communicator_delete(void *comm)
Dummy function for method-specific deletion operations for communicator deletion.
Definition: mdi_global.c:554
vector_get
void * vector_get(vector *v, int index)
Return a pointer to an element of a vector.
Definition: mdi_global.c:192
vector_free
int vector_free(vector *v)
Free all data associated with a vector.
Definition: mdi_global.c:179
mpi4py_gather_names_callback
int(* mpi4py_gather_names_callback)(void *, void *, int *, int *)
Python callback pointer for gathering names.
Definition: mdi_global.c:73
dynamic_array_struct::capacity
size_t capacity
Total number of elements that can be stored by this vector.
Definition: mdi_global.h:84
code_struct::role
char role[MDI_NAME_LENGTH_]
Role of the driver/engine.
Definition: mdi_global.h:144
get_callback_index
int get_callback_index(node *n, const char *callback_name)
Determine the index of a callback within a node.
Definition: mdi_global.c:244
node_struct::commands
vector * commands
Vector containing all the commands supported at this node.
Definition: mdi_global.h:135
code_struct::returned_comms
int returned_comms
The number of communicator handles that have been returned by MDI_Accept_Connection()
Definition: mdi_global.h:148
communicator_struct
Definition: mdi_global.h:102
communicator_struct::sockfd
sock_t sockfd
For communicators using the TCP communicatiom method, the socket descriptor (WINDOWS)
Definition: mdi_global.h:112
free_node_vector
int free_node_vector(vector *v)
Determine the index of a callback within a node.
Definition: mdi_global.c:258
mpi4py_send_callback
int(* mpi4py_send_callback)(void *, int, int, int, MDI_Comm_Type)
Python callback pointer for MPI_Send.
Definition: mdi_global.c:67
communicator_struct::method_data
void * method_data
Method-specific information for this communicator.
Definition: mdi_global.h:122
get_method
method * get_method(int method_id)
Get a method from a method handle Returns a pointer to the method.
Definition: mdi_global.c:411
mdi_error
void mdi_error(const char *message)
Print error message.
Definition: mdi_global.c:589
delete_code
int delete_code(int code_id)
Delete a code Returns 0 on success.
Definition: mdi_global.c:350
code_struct::name
char name[MDI_NAME_LENGTH_]
Name of the driver/engine.
Definition: mdi_global.h:142
communicator_struct::send
int(* send)(const void *, int, MDI_Datatype_Type, MDI_Comm_Type, int)
Function pointer for method-specific send operations.
Definition: mdi_global.h:124
code_struct::comms
vector * comms
Vector containing all communicators associated with this code.
Definition: mdi_global.h:162
get_code
code * get_code(int code_id)
Get a code from a code handle Returns a pointer to the code.
Definition: mdi_global.c:333
communicator_struct::recv
int(* recv)(void *, int, MDI_Datatype_Type, MDI_Comm_Type, int)
Function pointer for method-specific receive operations.
Definition: mdi_global.h:126
mpi4py_size_callback
int(* mpi4py_size_callback)(int)
Python callback pointer for MPI_Comm_size.
Definition: mdi_global.c:82
plugin_argv
char ** plugin_argv
Argument vector for plugin command-line options.
Definition: mdi_global.c:61
ipi_compatibility
int ipi_compatibility
Flag for whether MDI is running in i-PI compatibility mode.
Definition: mdi_global.c:33
code_struct::intra_MPI_comm
MPI_Comm intra_MPI_comm
MPI intra-communicator that spans all ranks associated with this code.
Definition: mdi_global.h:158
mpi4py_allgather_callback
int(* mpi4py_allgather_callback)(void *, void *)
Python callback pointer for the initial MPI allgather.
Definition: mdi_global.c:70
plugin_mode
int plugin_mode
Flag for whether MDI is currently operating in plugin mode.
Definition: mdi_global.c:42
file_exists
int file_exists(const char *file_name)
Check whether a file exists.
Definition: mdi_global.c:564
method_struct::id
int id
ID of this method.
Definition: mdi_global.h:91
communicator_struct::name_length
int name_length
The value of MDI_NAME_LENGTH for the connected code.
Definition: mdi_global.h:114
vector_delete
int vector_delete(vector *v, int index)
Remove an element from a vector.
Definition: mdi_global.c:153
code_struct::language
int language
Native language of this code.
Definition: mdi_global.h:152
communicator_struct::command_length
int command_length
The value of MDI_COMMAND_LENGTH for the connected code.
Definition: mdi_global.h:116
methods
vector methods
Vector containing all supported methods.
Definition: mdi_global.c:24
current_code
int current_code
Index of the active code.
Definition: mdi_global.c:30
dynamic_array_struct::stride
size_t stride
Size of each element.
Definition: mdi_global.h:82
mpi4py_barrier_callback
int(* mpi4py_barrier_callback)(int)
Python callback pointer for MPI_Comm_barrier.
Definition: mdi_global.c:85
dynamic_array_struct::data
unsigned char * data
The elements stored by this vector.
Definition: mdi_global.h:80
communicator_struct::id
MDI_Comm_Type id
MDI_Comm handle that corresponds to this communicator.
Definition: mdi_global.h:106
communicator_struct::is_accepted
int is_accepted
Indicate whether this communicator has been accepted yet.
Definition: mdi_global.h:108
plugin_argc
int plugin_argc
Argument count for plugin command-line options.
Definition: mdi_global.c:58
dynamic_array_struct::size
size_t size
Number of elements actually stored.
Definition: mdi_global.h:86
new_code
int new_code()
Create a new code structure and add it to the list of codes Returns the index of the new code.
Definition: mdi_global.c:279
vector_push_back
int vector_push_back(vector *v, void *element)
Append a new element to the end of the vector.
Definition: mdi_global.c:122
node_struct::name
char name[MDI_COMMAND_LENGTH_]
Name of the node.
Definition: mdi_global.h:133
code_struct::execute_command_obj
void * execute_command_obj
Pointer to the class object that is passed to any call to execute_command.
Definition: mdi_global.h:168
code_struct::intra_rank
int intra_rank
Rank of this process within its associated code.
Definition: mdi_global.h:154
method_struct::on_selection
int(* on_selection)()
Function pointer for method initialization work.
Definition: mdi_global.h:95
python_plugin_mpi_world_ptr
void * python_plugin_mpi_world_ptr
Pointer to the MPI_Comm over which a Python plugin should run. Only used for Python plugins.
Definition: mdi_global.c:49
communicator_struct::nodes
vector * nodes
The nodes supported by the connected code.
Definition: mdi_global.h:120
initialized_mpi
int initialized_mpi
Flag for whether MDI called MPI_Init.
Definition: mdi_global.c:39
selected_method_id
int selected_method_id
ID of the method being used for inter-code communication.
Definition: mdi_global.c:27
code_struct::is_library
int is_library
Flag whether this code is being used as a library 0: Not a library 1: Is an ENGINE library,...
Definition: mdi_global.h:173
new_method
int new_method(int method_id)
Create a new method structure and add it to the vector of methods Returns the handle of the new metho...
Definition: mdi_global.c:397
plugin_unedited_options
char * plugin_unedited_options
Unedited command-line options for currently running plugin.
Definition: mdi_global.c:52
mpi4py_rank_callback
int(* mpi4py_rank_callback)(int)
Python callback pointer for MPI_Comm_rank.
Definition: mdi_global.c:79
mdi_warning
void mdi_warning(const char *message)
Print warning message.
Definition: mdi_global.c:599
code_struct::next_comm
int next_comm
The handle of the next communicator.
Definition: mdi_global.h:150
delete_communicator
int delete_communicator(int code_id, MDI_Comm_Type comm_id)
Delete a communicator Returns 0 on success.
Definition: mdi_global.c:512
mpi4py_split_callback
int(* mpi4py_split_callback)(int, int, MDI_Comm_Type, int)
Python callback pointer for MPI_Comm_split.
Definition: mdi_global.c:76
convert_buf_datatype
int convert_buf_datatype(void *recvbuf_in, MDI_Datatype_Type recvtype, void *sendbuf_in, MDI_Datatype_Type sendtype, int count)
Convert a buffer from one datatype to another.
Definition: mdi_global.c:730
code_struct
Definition: mdi_global.h:140
get_command_index
int get_command_index(node *n, const char *command_name)
Determine the index of a command within a node.
Definition: mdi_global.c:226
delete_method
int delete_method(int method_id)
Delete a method Returns 0 on success.
Definition: mdi_global.c:428
plugin_options
char * plugin_options
Command-line options for currently running plugin.
Definition: mdi_global.c:55
vector_init
int vector_init(vector *v, size_t stride)
Initialize memory allocation for a vector structure.
Definition: mdi_global.c:100
datatype_info
int datatype_info(MDI_Datatype_Type datatype, size_t *size, MDI_Datatype_Type *base)
Get information about an MDI_Datatype.
Definition: mdi_global.c:613
mdi_mpi_comm_world
MPI_Comm mdi_mpi_comm_world
Internal copy of MPI_COMM_WORLD, used when MDI initializes MPI.
Definition: mdi_global.c:45
code_struct::execute_command
int(* execute_command)(const char *, MDI_Comm_Type, void *)
Function pointer to the generic execute_command_function.
Definition: mdi_global.h:166
world_size
int world_size
Size of MPI_COMM_WORLD.
Definition: mdi_global.c:88
is_initialized
int is_initialized
Flag for whether MDI has been previously initialized.
Definition: mdi_global.c:36
communicator_struct::method_id
int method_id
Communication method used by this communicator.
Definition: mdi_global.h:104
dynamic_array_struct
Definition: mdi_global.h:78
code_struct::called_set_execute_command_func
int called_set_execute_command_func
Flag whether this code has called set_execute_command_func.
Definition: mdi_global.h:156
code_struct::nodes
vector * nodes
Vector containing all nodes supported by this code.
Definition: mdi_global.h:160
codes
vector codes
Vector containing all codes that have been initiailized on this rank. Typically, this will only inclu...
Definition: mdi_global.c:21
code_struct::id
int id
Handle for this code.
Definition: mdi_global.h:146
world_rank
int world_rank
Rank of this process within MPI_COMM_WORLD.
Definition: mdi_global.c:91
method_struct::method_id
int method_id
Communication method.
Definition: mdi_global.h:93
communicator_struct::code_id
int code_id
Handle for the id of the associated code.
Definition: mdi_global.h:110
new_communicator
int new_communicator(int code_id, int method)
Create a new communicator structure and add it to the list of communicators Returns the handle of the...
Definition: mdi_global.c:461
code_struct::plugin_path
char * plugin_path
Path to the plugins available to this code.
Definition: mdi_global.h:164
get_communicator
communicator * get_communicator(int code_id, MDI_Comm_Type comm_id)
Get a communicator from a communicator handle Returns a pointer to the communicator.
Definition: mdi_global.c:493
method_struct
Definition: mdi_global.h:89
mpi4py_recv_callback
int(* mpi4py_recv_callback)(void *, int, int, int, MDI_Comm_Type)
Python callback pointer for MPI_Recv.
Definition: mdi_global.c:64
get_node_index
int get_node_index(vector *v, const char *node_name)
Determine the index of a node within a vector of nodes.
Definition: mdi_global.c:207
node_struct
Definition: mdi_global.h:131
datatype_mpitype
int datatype_mpitype(MDI_Datatype_Type datatype, MPI_Datatype *mpitype)
Get the MPI datatype that corresponds to an MDI datatype.
Definition: mdi_global.c:681
node_struct::callbacks
vector * callbacks
Vector containing all the callbacks associated with this node.
Definition: mdi_global.h:137
communicator_struct::mdi_version
int mdi_version[3]
The MDI version of the connected code.
Definition: mdi_global.h:118