Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / src / smpi / bindings / smpi_f77_comm.cpp
1 /* Copyright (c) 2010-2022. 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 #include <string>
12
13 extern "C" { // This should really use the C linkage to be usable from Fortran
14
15 void mpi_comm_rank_(int* comm, int* rank, int* ierr) {
16    *ierr = MPI_Comm_rank(simgrid::smpi::Comm::f2c(*comm), rank);
17 }
18
19 void mpi_comm_size_(int* comm, int* size, int* ierr) {
20    *ierr = MPI_Comm_size(simgrid::smpi::Comm::f2c(*comm), size);
21 }
22
23 void mpi_comm_dup_(int* comm, int* newcomm, int* ierr) {
24   MPI_Comm tmp;
25
26   *ierr = MPI_Comm_dup(simgrid::smpi::Comm::f2c(*comm), &tmp);
27   if(*ierr == MPI_SUCCESS) {
28     *newcomm = tmp->c2f();
29   }
30 }
31
32 void mpi_comm_create_(int* comm, int* group, int* newcomm, int* ierr) {
33   MPI_Comm tmp;
34   *ierr = MPI_Comm_create(simgrid::smpi::Comm::f2c(*comm),simgrid::smpi::Group::f2c(*group), &tmp);
35   if(*ierr == MPI_SUCCESS) {
36     *newcomm = tmp->c2f();
37   }
38 }
39
40 void mpi_comm_free_(int* comm, int* ierr) {
41   MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm);
42   if(tmp != MPI_COMM_WORLD && tmp != MPI_COMM_NULL) {
43     simgrid::smpi::Comm::destroy(tmp);
44     simgrid::smpi::Comm::free_f(*comm);
45   }
46   *ierr = MPI_SUCCESS;
47 }
48
49 void mpi_comm_split_(int* comm, int* color, int* key, int* comm_out, int* ierr) {
50   MPI_Comm tmp;
51
52   *ierr = MPI_Comm_split(simgrid::smpi::Comm::f2c(*comm), *color, *key, &tmp);
53   if(*ierr == MPI_SUCCESS) {
54     *comm_out = tmp->c2f();
55   }
56 }
57
58 void mpi_comm_group_(int* comm, int* group_out,  int* ierr) {
59   MPI_Group tmp;
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   auto* val = xbt_new(int, 1);
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  *ierr = MPI_Comm_delete_attr (simgrid::smpi::Comm::f2c(*comm),  *comm_keyval);
89 }
90
91 void mpi_comm_create_keyval_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){
92   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};
93   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};
94   *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state, true);
95 }
96
97 void mpi_comm_free_keyval_ (int* keyval, int* ierr) {
98  *ierr = MPI_Comm_free_keyval( keyval);
99 }
100
101 void mpi_comm_get_name_ (int* comm, char* name, int* len, int* ierr){
102  *ierr = MPI_Comm_get_name(simgrid::smpi::Comm::f2c(*comm), name, len);
103   for(int i = *len; i<MPI_MAX_OBJECT_NAME+1; i++)
104     name[i]=' ';
105 }
106
107 void mpi_comm_compare_ (int* comm1, int* comm2, int *result, int* ierr){
108  *ierr = MPI_Comm_compare(simgrid::smpi::Comm::f2c(*comm1), simgrid::smpi::Comm::f2c(*comm2), result);
109 }
110
111 void mpi_comm_disconnect_ (int* comm, int* ierr){
112  MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm);
113  *ierr = MPI_Comm_disconnect(&tmp);
114  if(*ierr == MPI_SUCCESS) {
115    simgrid::smpi::Comm::free_f(*comm);
116  }
117 }
118
119 void mpi_comm_set_errhandler_ (int* comm, int* errhandler, int* ierr) {
120  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Errhandler::f2c(*errhandler));
121 }
122
123 void mpi_comm_get_errhandler_ (int* comm, int* errhandler, int* ierr) {
124  MPI_Errhandler tmp;
125  *ierr = MPI_Errhandler_get(simgrid::smpi::Comm::f2c(*comm), &tmp);
126  if(*ierr == MPI_SUCCESS) {
127    *errhandler = tmp->c2f();
128  }
129 }
130
131 void mpi_comm_test_inter_ (int* comm, int* flag, int* ierr) {
132  *ierr = MPI_Comm_test_inter(simgrid::smpi::Comm::f2c(*comm), flag);
133 }
134
135 void mpi_comm_remote_group_ (int* comm, int*  group, int* ierr) {
136   MPI_Group tmp;
137  *ierr = MPI_Comm_remote_group(simgrid::smpi::Comm::f2c(*comm), &tmp);
138  if(*ierr == MPI_SUCCESS) {
139    *group = tmp->c2f();
140  }
141 }
142
143 void mpi_comm_remote_size_ (int* comm, int* size, int* ierr) {
144  *ierr = MPI_Comm_remote_size(simgrid::smpi::Comm::f2c(*comm), size);
145 }
146
147 void mpi_comm_set_name_ (int* comm, char* name, int* ierr){
148  int count;
149  for(count=MPI_MAX_OBJECT_NAME-1; count>=0 && name[count]==' '; count--);
150  count+=1;
151  std::string tname(name, count);
152  *ierr = MPI_Comm_set_name(simgrid::smpi::Comm::f2c(*comm), tname.c_str());
153 }
154
155 void mpi_comm_dup_with_info_ (int* comm, int* info, int* newcomm, int* ierr){
156   MPI_Comm tmp;
157   *ierr = MPI_Comm_dup_with_info(simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info),&tmp);
158   if(*ierr == MPI_SUCCESS) {
159     *newcomm = tmp->c2f();
160   }
161 }
162
163 void mpi_comm_split_type_ (int* comm, int* split_type, int* key, int* info, int* newcomm, int* ierr){
164   MPI_Comm tmp;
165   *ierr = MPI_Comm_split_type(simgrid::smpi::Comm::f2c(*comm), *split_type, *key, simgrid::smpi::Info::f2c(*info), &tmp);
166   if(*ierr == MPI_SUCCESS) {
167     *newcomm = tmp->c2f();
168   }
169 }
170
171 void mpi_comm_set_info_ (int* comm, int* info, int* ierr){
172  *ierr = MPI_Comm_set_info (simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info));
173 }
174
175 void mpi_comm_get_info_ (int* comm, int* info, int* ierr){
176  MPI_Info tmp;
177  *ierr = MPI_Comm_get_info (simgrid::smpi::Comm::f2c(*comm), &tmp);
178  if(*ierr==MPI_SUCCESS){
179    *info = tmp->c2f();
180  }
181 }
182
183 void mpi_comm_create_errhandler_ ( void *function, int *errhandler, int* ierr){
184  MPI_Errhandler tmp;
185  *ierr = MPI_Comm_create_errhandler( reinterpret_cast<MPI_Comm_errhandler_fn*>(function), &tmp);
186  if(*ierr==MPI_SUCCESS){
187    *errhandler = tmp->c2f();
188  }
189 }
190
191 void mpi_comm_call_errhandler_ (int* comm,int* errorcode, int* ierr){
192  *ierr = MPI_Comm_call_errhandler(simgrid::smpi::Comm::f2c(*comm), *errorcode);
193 }
194
195 void mpi_comm_connect_(char* port_name, int* info, int* root, int* comm, int* newcomm, int* ierr)
196 {
197   MPI_Comm tmp;
198   *ierr = MPI_Comm_connect(port_name, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
199   if(*ierr == MPI_SUCCESS) {
200     *newcomm = tmp->c2f();
201   }
202 }
203
204 void mpi_comm_join_ ( int* fd, int* intercomm, int* ierr){
205   MPI_Comm tmp;
206   *ierr = MPI_Comm_join( *fd, &tmp);
207   if(*ierr == MPI_SUCCESS) {
208     *intercomm = tmp->c2f();
209   }
210 }
211
212
213 void mpi_comm_accept_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
214   MPI_Comm tmp;
215   *ierr = MPI_Comm_accept( port_name, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
216   if(*ierr == MPI_SUCCESS) {
217     *newcomm = tmp->c2f();
218   }
219 }
220
221 void mpi_comm_spawn_ ( char *command, char *argv, int* maxprocs, int* info, int* root, int* comm, int* intercomm,
222                        int* array_of_errcodes, int* ierr){
223   MPI_Comm tmp;
224   *ierr = MPI_Comm_spawn( command, &argv, *maxprocs, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp,
225                           array_of_errcodes);
226   if(*ierr == MPI_SUCCESS) {
227     *intercomm = tmp->c2f();
228   }
229 }
230
231 void mpi_comm_spawn_multiple_ ( int* count, char *array_of_commands, char** array_of_argv, int* array_of_maxprocs,
232                                 int* array_of_info, int* root,
233  int* comm, int* intercomm, int* array_of_errcodes, int* ierr){
234  MPI_Comm tmp;
235  *ierr = MPI_Comm_spawn_multiple(* count, &array_of_commands, &array_of_argv, array_of_maxprocs,
236  reinterpret_cast<MPI_Info*>(array_of_info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp, array_of_errcodes);
237  if(*ierr == MPI_SUCCESS) {
238    *intercomm = tmp->c2f();
239  }
240 }
241
242 void mpi_comm_get_parent_ ( int* parent, int* ierr){
243   MPI_Comm tmp;
244   *ierr = MPI_Comm_get_parent( &tmp);
245   if(*ierr == MPI_SUCCESS) {
246     *parent = tmp->c2f();
247   }
248 }
249
250 }