Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add support for MPI Errhandlers in Comm, File, Win.
[simgrid.git] / src / smpi / bindings / smpi_f77_comm.cpp
1 /* Copyright (c) 2010-2019. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "private.hpp"
7 #include "smpi_comm.hpp"
8 #include "smpi_errhandler.hpp"
9 #include "smpi_info.hpp"
10
11 extern "C" { // This should really use the C linkage to be usable from Fortran
12
13 void mpi_comm_rank_(int* comm, int* rank, int* ierr) {
14    *ierr = MPI_Comm_rank(simgrid::smpi::Comm::f2c(*comm), rank);
15 }
16
17 void mpi_comm_size_(int* comm, int* size, int* ierr) {
18    *ierr = MPI_Comm_size(simgrid::smpi::Comm::f2c(*comm), size);
19 }
20
21 void mpi_comm_dup_(int* comm, int* newcomm, int* ierr) {
22   MPI_Comm tmp;
23
24   *ierr = MPI_Comm_dup(simgrid::smpi::Comm::f2c(*comm), &tmp);
25   if(*ierr == MPI_SUCCESS) {
26     *newcomm = tmp->add_f();
27   }
28 }
29
30 void mpi_comm_create_(int* comm, int* group, int* newcomm, int* ierr) {
31   MPI_Comm tmp;
32
33   *ierr = MPI_Comm_create(simgrid::smpi::Comm::f2c(*comm),simgrid::smpi::Group::f2c(*group), &tmp);
34   if(*ierr == MPI_SUCCESS) {
35     *newcomm = tmp->add_f();
36   }
37 }
38
39 void mpi_comm_free_(int* comm, int* ierr) {
40   MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm);
41   if(tmp != MPI_COMM_WORLD && tmp != MPI_COMM_NULL) {
42     simgrid::smpi::Comm::destroy(tmp);
43     simgrid::smpi::Comm::free_f(*comm);
44   }
45   *ierr = MPI_SUCCESS;
46 }
47
48 void mpi_comm_split_(int* comm, int* color, int* key, int* comm_out, int* ierr) {
49   MPI_Comm tmp;
50
51   *ierr = MPI_Comm_split(simgrid::smpi::Comm::f2c(*comm), *color, *key, &tmp);
52   if(*ierr == MPI_SUCCESS) {
53     *comm_out = tmp->add_f();
54   }
55 }
56
57 void mpi_comm_group_(int* comm, int* group_out,  int* ierr) {
58   MPI_Group tmp;
59
60   *ierr = MPI_Comm_group(simgrid::smpi::Comm::f2c(*comm), &tmp);
61   if(*ierr == MPI_SUCCESS) {
62     *group_out = tmp->c2f();
63   }
64 }
65
66 void mpi_comm_create_group_ (int* comm, int* group, int i, int* comm_out, int* ierr){
67   MPI_Comm tmp;
68  *ierr = MPI_Comm_create_group(simgrid::smpi::Comm::f2c(*comm),simgrid::smpi::Group::f2c(*group), i, &tmp);
69   if(*ierr == MPI_SUCCESS) {
70     *comm_out = tmp->c2f();
71   }
72 }
73
74 void mpi_comm_get_attr_ (int* comm, int* comm_keyval, int *attribute_val, int *flag, int* ierr){
75  int* value = nullptr;
76  *ierr = MPI_Comm_get_attr (simgrid::smpi::Comm::f2c(*comm), *comm_keyval, &value, flag);
77  if (*flag == 1)
78    *attribute_val = *value;
79 }
80
81 void mpi_comm_set_attr_ (int* comm, int* comm_keyval, int *attribute_val, int* ierr){
82  int* val = (int*)xbt_malloc(sizeof(int));
83  *val=*attribute_val;
84  *ierr = MPI_Comm_set_attr ( simgrid::smpi::Comm::f2c(*comm), *comm_keyval, val);
85 }
86
87 void mpi_comm_delete_attr_ (int* comm, int* comm_keyval, int* ierr){
88
89  *ierr = MPI_Comm_delete_attr (simgrid::smpi::Comm::f2c(*comm),  *comm_keyval);
90 }
91
92 void mpi_comm_create_keyval_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){
93   smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Comm_copy_attr_function_fort*>(copy_fn),nullptr,nullptr};
94   smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Comm_delete_attr_function_fort*>(delete_fn),nullptr,nullptr};
95   *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state);
96 }
97
98 void mpi_comm_free_keyval_ (int* keyval, int* ierr) {
99  *ierr = MPI_Comm_free_keyval( keyval);
100 }
101
102 void mpi_comm_get_name_ (int* comm, char* name, int* len, int* ierr){
103  *ierr = MPI_Comm_get_name(simgrid::smpi::Comm::f2c(*comm), name, len);
104   for(int i = *len; i<MPI_MAX_OBJECT_NAME+1; i++)
105     name[i]=' ';
106 }
107
108 void mpi_comm_compare_ (int* comm1, int* comm2, int *result, int* ierr){
109
110  *ierr = MPI_Comm_compare(simgrid::smpi::Comm::f2c(*comm1), simgrid::smpi::Comm::f2c(*comm2), result);
111 }
112
113 void mpi_comm_disconnect_ (int* comm, int* ierr){
114  MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm);
115  *ierr = MPI_Comm_disconnect(&tmp);
116  if(*ierr == MPI_SUCCESS) {
117    simgrid::smpi::Comm::free_f(*comm);
118  }
119 }
120
121 void mpi_comm_set_errhandler_ (int* comm, int* errhandler, int* ierr) {
122  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Errhandler::f2c(*errhandler));
123 }
124
125 void mpi_comm_get_errhandler_ (int* comm, int* errhandler, int* ierr) {
126  MPI_Errhandler tmp;
127  *ierr = MPI_Errhandler_get(simgrid::smpi::Comm::f2c(*comm), &tmp);
128  if(*ierr == MPI_SUCCESS) {
129    *errhandler = tmp->c2f();
130  }
131 }
132
133 void mpi_comm_test_inter_ (int* comm, int* flag, int* ierr) {
134  *ierr = MPI_Comm_test_inter(simgrid::smpi::Comm::f2c(*comm), flag);
135 }
136
137 void mpi_comm_remote_group_ (int* comm, int*  group, int* ierr) {
138   MPI_Group tmp;
139  *ierr = MPI_Comm_remote_group(simgrid::smpi::Comm::f2c(*comm), &tmp);
140  if(*ierr == MPI_SUCCESS) {
141    *group = tmp->c2f();
142  }
143 }
144
145 void mpi_comm_remote_size_ (int* comm, int* size, int* ierr) {
146  *ierr = MPI_Comm_remote_size(simgrid::smpi::Comm::f2c(*comm), size);
147 }
148
149 void mpi_comm_set_name_ (int* comm, char* name, int* ierr){
150  int count;
151  for(count=MPI_MAX_OBJECT_NAME-1; count>=0 && name[count]==' '; count--);
152  count+=1;
153  char* tname = xbt_new(char, count+1);
154  strncpy(tname, name, count);
155  tname[count]='\0';
156  *ierr = MPI_Comm_set_name (simgrid::smpi::Comm::f2c(*comm), tname);
157  xbt_free(tname);
158 }
159
160 void mpi_comm_dup_with_info_ (int* comm, int* info, int* newcomm, int* ierr){
161   MPI_Comm tmp;
162   *ierr = MPI_Comm_dup_with_info(simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info),&tmp);
163   if(*ierr == MPI_SUCCESS) {
164     *newcomm = tmp->add_f();
165   }
166 }
167
168 void mpi_comm_split_type_ (int* comm, int* split_type, int* key, int* info, int* newcomm, int* ierr){
169   MPI_Comm tmp;
170   *ierr = MPI_Comm_split_type(simgrid::smpi::Comm::f2c(*comm), *split_type, *key, simgrid::smpi::Info::f2c(*info), &tmp);
171   if(*ierr == MPI_SUCCESS) {
172     *newcomm = tmp->add_f();
173   }
174 }
175
176 void mpi_comm_set_info_ (int* comm, int* info, int* ierr){
177  *ierr = MPI_Comm_set_info (simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info));
178 }
179
180 void mpi_comm_get_info_ (int* comm, int* info, int* ierr){
181  MPI_Info tmp;
182  *ierr = MPI_Comm_get_info (simgrid::smpi::Comm::f2c(*comm), &tmp);
183  if(*ierr==MPI_SUCCESS){
184    *info = tmp->c2f();
185  }
186 }
187
188 void mpi_comm_create_errhandler_ ( void *function, int *errhandler, int* ierr){
189  MPI_Errhandler tmp;
190  *ierr = MPI_Comm_create_errhandler( reinterpret_cast<MPI_Comm_errhandler_fn*>(function), &tmp);
191  if(*ierr==MPI_SUCCESS){
192    *errhandler = tmp->c2f();
193  }
194 }
195
196 void mpi_comm_call_errhandler_ (int* comm,int* errorcode, int* ierr){
197  *ierr = MPI_Comm_call_errhandler(simgrid::smpi::Comm::f2c(*comm), *errorcode);
198 }
199
200 void mpi_comm_connect_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
201   MPI_Comm tmp;
202   *ierr = MPI_Comm_connect( port_name, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
203   if(*ierr == MPI_SUCCESS) {
204     *newcomm = tmp->add_f();
205   }
206 }
207
208 void mpi_comm_join_ ( int* fd, int* intercomm, int* ierr){
209   MPI_Comm tmp;
210   *ierr = MPI_Comm_join( *fd, &tmp);
211   if(*ierr == MPI_SUCCESS) {
212     *intercomm = tmp->add_f();
213   }
214 }
215
216
217 void mpi_comm_accept_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
218   MPI_Comm tmp;
219   *ierr = MPI_Comm_accept( port_name, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
220   if(*ierr == MPI_SUCCESS) {
221     *newcomm = tmp->add_f();
222   }
223 }
224
225 void mpi_comm_spawn_ ( char *command, char *argv, int* maxprocs, int* info, int* root, int* comm, int* intercomm,
226                        int* array_of_errcodes, int* ierr){
227   MPI_Comm tmp;
228   *ierr = MPI_Comm_spawn( command, &argv, *maxprocs, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp,
229                           array_of_errcodes);
230   if(*ierr == MPI_SUCCESS) {
231     *intercomm = tmp->add_f();
232   }
233 }
234
235 void mpi_comm_spawn_multiple_ ( int* count, char *array_of_commands, char** array_of_argv, int* array_of_maxprocs,
236                                 int* array_of_info, int* root,
237  int* comm, int* intercomm, int* array_of_errcodes, int* ierr){
238  MPI_Comm tmp;
239  *ierr = MPI_Comm_spawn_multiple(* count, &array_of_commands, &array_of_argv, array_of_maxprocs,
240  reinterpret_cast<MPI_Info*>(array_of_info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp, array_of_errcodes);
241  if(*ierr == MPI_SUCCESS) {
242    *intercomm = tmp->add_f();
243  }
244 }
245
246 void mpi_comm_get_parent_ ( int* parent, int* ierr){
247   MPI_Comm tmp;
248   *ierr = MPI_Comm_get_parent( &tmp);
249   if(*ierr == MPI_SUCCESS) {
250     *parent = tmp->c2f();
251   }
252 }
253
254 }