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 COMMAND_LENGTH 12
26 #define NAME_LENGTH 12
27 #define PLUGIN_PATH_LENGTH 2048
28 
29 // Defined languages
30 #define MDI_LANGUAGE_C 1
31 #define MDI_LANGUAGE_FORTRAN 2
32 #define MDI_LANGUAGE_PYTHON 3
33 
34 // MDI version numbers
35 #define MDI_MAJOR_VERSION_ 1
36 #define MDI_MINOR_VERSION_ 2
37 #define MDI_PATCH_VERSION_ 15
38 
39 // length of an MDI command in characters
40 #define MDI_COMMAND_LENGTH_ 12
41 
42 // length of an MDI name in characters
43 #define MDI_NAME_LENGTH_ 12
44 
45 // length of an MDI label in characters
46 #define MDI_LABEL_LENGTH_ 64
47 
48 // value of a null communicator
49 #define MDI_COMM_NULL_ 0
50 
51 // MDI data types
52 #define MDI_INT_ 1
53 #define MDI_INT8_T_ 7
54 #define MDI_INT16_T_ 8
55 #define MDI_INT32_T_ 9
56 #define MDI_INT64_T_ 10
57 #define MDI_UINT8_T_ 11
58 #define MDI_UINT16_T_ 12
59 #define MDI_UINT32_T_ 13
60 #define MDI_UINT64_T_ 14
61 #define MDI_DOUBLE_ 2
62 #define MDI_CHAR_ 3
63 #define MDI_FLOAT_ 4
64 #define MDI_BYTE_ 6
65 
66 // MDI communication types
67 #define MDI_TCP_ 1
68 #define MDI_MPI_ 2
69 #define MDI_LINK_ 3
70 #define MDI_TEST_ 4
71 
72 // MDI role types
73 #define MDI_DRIVER_ 1
74 #define MDI_ENGINE_ 2
75 
76 // MDI Typedefs
77 typedef int MDI_Comm_Type;
78 typedef int MDI_Datatype_Type;
79 
80 typedef struct dynamic_array_struct {
82  unsigned char* data;
84  size_t stride;
86  size_t capacity;
88  size_t size; //number of elements actually stored
89 } vector;
90 
91 typedef struct method_struct {
93  int id;
95  int method_id;
97  int (*on_selection)();
98  int (*on_accept_communicator)();
99  int (*on_send_command)(const char*, MDI_Comm_Type, int* skip_flag);
100  int (*after_send_command)(const char*, MDI_Comm_Type);
101  int (*on_recv_command)(MDI_Comm_Type);
102 } method;
103 
104 typedef struct communicator_struct {
106  int method;
108  MDI_Comm_Type id;
110  int code_id;
112  sock_t sockfd;
114  int mdi_version[3];
118  void* method_data;
120  int (*send)(const void*, int, MDI_Datatype_Type, MDI_Comm_Type, int);
122  int (*recv)(void*, int, MDI_Datatype_Type, MDI_Comm_Type, int);
124  int (*delete)(void*);
125 } communicator;
126 
127 typedef struct node_struct {
129  char name[COMMAND_LENGTH];
134 } node;
135 
136 typedef struct code_struct {
138  char name[NAME_LENGTH];
140  char role[NAME_LENGTH];
142  int id;
148  int language;
154  MPI_Comm intra_MPI_comm;
160  char* plugin_path;
162  int (*execute_command)(const char*, MDI_Comm_Type, void*);
170 } code;
171 
174 extern vector codes;
175 
177 extern vector methods;
178 
180 extern int selected_method_id;
181 
183 extern int current_code;
184 
186 extern int ipi_compatibility;
187 
189 extern int is_initialized;
190 
192 extern int initialized_mpi;
193 
195 extern int plugin_mode;
196 
198 extern MPI_Comm mdi_mpi_comm_world;
199 
202 extern void* python_plugin_mpi_world_ptr;
203 
205 extern char* plugin_unedited_options;
206 
208 extern char* plugin_options;
209 
211 extern int plugin_argc;
212 
214 extern char** plugin_argv;
215 
217 extern int (*mpi4py_recv_callback)(void*, int, int, int, MDI_Comm_Type);
218 
220 extern int (*mpi4py_send_callback)(void*, int, int, int, MDI_Comm_Type);
221 
223 extern int (*mpi4py_gather_names_callback)(void*, void*);
224 
226 extern int (*mpi4py_split_callback)(int, int, MDI_Comm_Type, int);
227 
229 extern int (*mpi4py_rank_callback)(int);
230 
232 extern int (*mpi4py_size_callback)(int);
233 
235 extern int (*mpi4py_barrier_callback)(int);
236 
238 extern int world_size;
239 
241 extern int world_rank;
242 
243 int vector_init(vector* v, size_t stride);
244 int vector_push_back(vector* v, void* element);
245 void* vector_get(vector* v, int index);
246 int vector_delete(vector* v, int index);
247 int vector_free(vector* v);
248 
249 int get_node_index(vector* v, const char* node_name);
250 int get_command_index(node* n, const char* command_name);
251 int get_callback_index(node* n, const char* callback_name);
252 int free_node_vector(vector* v);
253 
254 int new_communicator(int code_id, int method);
255 communicator* get_communicator(int code_id, MDI_Comm_Type comm_id);
256 int delete_communicator(int code_id, MDI_Comm_Type comm_id);
257 
258 int new_code();
259 code* get_code(int code_id);
260 int delete_code(int code_id);
261 
262 int new_method(int method_id);
263 method* get_method(int method_id);
264 int delete_method(int method_id);
265 
267 int file_exists(const char* file_name);
268 
270 int communicator_delete(void* comm);
271 
272 void mdi_error(const char* message);
273 void mdi_warning(const char* message);
274 
276 int datatype_info(MDI_Datatype_Type datatype, size_t* size, MDI_Datatype_Type* base);
277 
279 int datatype_mpitype(MDI_Datatype_Type datatype, MPI_Datatype* mpitype);
280 
282 int convert_buf_datatype(void* recvbuf_in, MDI_Datatype_Type recvtype,
283  void* sendbuf_in, MDI_Datatype_Type sendtype,
284  int count);
285 
286 #endif
communicator_delete
int communicator_delete(void *comm)
Dummy function for method-specific deletion operations for communicator deletion.
Definition: mdi_global.c:545
vector_get
void * vector_get(vector *v, int index)
Return a pointer to an element of a vector.
Definition: mdi_global.c:189
mpi4py_gather_names_callback
int(* mpi4py_gather_names_callback)(void *, void *)
Python callback pointer for gathering names.
Definition: mdi_global.c:70
vector_free
int vector_free(vector *v)
Free all data associated with a vector.
Definition: mdi_global.c:176
dynamic_array_struct::capacity
size_t capacity
Total number of elements that can be stored by this vector.
Definition: mdi_global.h:86
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:241
node_struct::commands
vector * commands
Vector containing all the commands supported at this node.
Definition: mdi_global.h:131
code_struct::returned_comms
int returned_comms
The number of communicator handles that have been returned by MDI_Accept_Connection()
Definition: mdi_global.h:144
communicator_struct
Definition: mdi_global.h:104
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:255
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:118
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:408
mdi_error
void mdi_error(const char *message)
Print error message.
Definition: mdi_global.c:580
delete_code
int delete_code(int code_id)
Delete a code Returns 0 on success.
Definition: mdi_global.c:347
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:120
code_struct::comms
vector * comms
Vector containing all communicators associated with this code.
Definition: mdi_global.h:158
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:330
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:122
mpi4py_size_callback
int(* mpi4py_size_callback)(int)
Python callback pointer for MPI_Comm_size.
Definition: mdi_global.c:79
plugin_argv
char ** plugin_argv
Argument vector for plugin command-line options.
Definition: mdi_global.c:61
communicator_struct::method
int method
Communication method used by this communicator.
Definition: mdi_global.h:106
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:154
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:555
method_struct::id
int id
ID of this method.
Definition: mdi_global.h:93
code_struct::name
char name[NAME_LENGTH]
Name of the driver/engine.
Definition: mdi_global.h:138
vector_delete
int vector_delete(vector *v, int index)
Remove an element from a vector.
Definition: mdi_global.c:150
code_struct::language
int language
Native language of this code.
Definition: mdi_global.h:148
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:84
mpi4py_barrier_callback
int(* mpi4py_barrier_callback)(int)
Python callback pointer for MPI_Comm_barrier.
Definition: mdi_global.c:82
dynamic_array_struct::data
unsigned char * data
The elements stored by this vector.
Definition: mdi_global.h:82
communicator_struct::id
MDI_Comm_Type id
MDI_Comm handle that corresponds to this communicator.
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:88
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:276
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:119
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:164
code_struct::intra_rank
int intra_rank
Rank of this process within its associated code.
Definition: mdi_global.h:150
method_struct::on_selection
int(* on_selection)()
Function pointer for method initialization work.
Definition: mdi_global.h:97
node_struct::name
char name[COMMAND_LENGTH]
Name of the node.
Definition: mdi_global.h:129
code_struct::role
char role[NAME_LENGTH]
Role of the driver/engine.
Definition: mdi_global.h:140
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:116
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:169
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:394
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:76
mdi_warning
void mdi_warning(const char *message)
Print warning message.
Definition: mdi_global.c:590
code_struct::next_comm
int next_comm
The handle of the next communicator.
Definition: mdi_global.h:146
delete_communicator
int delete_communicator(int code_id, MDI_Comm_Type comm_id)
Delete a communicator Returns 0 on success.
Definition: mdi_global.c:503
mpi4py_split_callback
int(* mpi4py_split_callback)(int, int, MDI_Comm_Type, int)
Python callback pointer for MPI_Comm_split.
Definition: mdi_global.c:73
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:721
code_struct
Definition: mdi_global.h:136
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:223
delete_method
int delete_method(int method_id)
Delete a method Returns 0 on success.
Definition: mdi_global.c:425
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:97
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:604
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:162
world_size
int world_size
Size of MPI_COMM_WORLD.
Definition: mdi_global.c:85
is_initialized
int is_initialized
Flag for whether MDI has been previously initialized.
Definition: mdi_global.c:36
dynamic_array_struct
Definition: mdi_global.h:80
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:152
code_struct::nodes
vector * nodes
Vector containing all nodes supported by this code.
Definition: mdi_global.h:156
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:142
world_rank
int world_rank
Rank of this process within MPI_COMM_WORLD.
Definition: mdi_global.c:88
method_struct::method_id
int method_id
Communication method.
Definition: mdi_global.h:95
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:458
code_struct::plugin_path
char * plugin_path
Path to the plugins available to this code.
Definition: mdi_global.h:160
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:484
method_struct
Definition: mdi_global.h:91
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:204
node_struct
Definition: mdi_global.h:127
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:672
node_struct::callbacks
vector * callbacks
Vector containing all the callbacks associated with this node.
Definition: mdi_global.h:133
communicator_struct::mdi_version
int mdi_version[3]
The MDI version of the connected code.
Definition: mdi_global.h:114