Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce dupplication around smpi factors
[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   if (MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm); 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->c2f();
54   }
55 }
56
57 void mpi_comm_group_(int* comm, int* group_out,  int* ierr) {
58   MPI_Group tmp;
59   *ierr = MPI_Comm_group(simgrid::smpi::Comm::f2c(*comm), &tmp);
60   if(*ierr == MPI_SUCCESS) {
61     *group_out = tmp->c2f();
62   }
63 }
64
65 void mpi_comm_create_group_ (int* comm, int* group, int i, int* comm_out, int* ierr){
66   MPI_Comm tmp;
67  *ierr = MPI_Comm_create_group(simgrid::smpi::Comm::f2c(*comm),simgrid::smpi::Group::f2c(*group), i, &tmp);
68   if(*ierr == MPI_SUCCESS) {
69     *comm_out = tmp->c2f();
70   }
71 }
72
73 void mpi_comm_get_attr_ (int* comm, int* comm_keyval, int *attribute_val, int *flag, int* ierr){
74  int* value = nullptr;
75  *ierr = MPI_Comm_get_attr (simgrid::smpi::Comm::f2c(*comm), *comm_keyval, &value, flag);
76  if (*flag == 1)
77    *attribute_val = *value;
78 }
79
80 void mpi_comm_set_attr_ (int* comm, int* comm_keyval, int *attribute_val, int* ierr){
81   auto* val = xbt_new(int, 1);
82   *val      = *attribute_val;
83   *ierr     = MPI_Comm_set_attr(simgrid::smpi::Comm::f2c(*comm), *comm_keyval, val);
84 }
85
86 void mpi_comm_delete_attr_ (int* comm, int* comm_keyval, int* ierr){
87  *ierr = MPI_Comm_delete_attr (simgrid::smpi::Comm::f2c(*comm),  *comm_keyval);
88 }
89
90 void mpi_comm_create_keyval_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){
91   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};
92   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};
93   *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state, true);
94 }
95
96 void mpi_comm_free_keyval_ (int* keyval, int* ierr) {
97  *ierr = MPI_Comm_free_keyval( keyval);
98 }
99
100 void mpi_comm_get_name_ (int* comm, char* name, int* len, int* ierr){
101  *ierr = MPI_Comm_get_name(simgrid::smpi::Comm::f2c(*comm), name, len);
102   for(int i = *len; i<MPI_MAX_OBJECT_NAME+1; i++)
103     name[i]=' ';
104 }
105
106 void mpi_comm_compare_ (int* comm1, int* comm2, int *result, int* ierr){
107  *ierr = MPI_Comm_compare(simgrid::smpi::Comm::f2c(*comm1), simgrid::smpi::Comm::f2c(*comm2), result);
108 }
109
110 void mpi_comm_disconnect_ (int* comm, int* ierr){
111  MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm);
112  *ierr = MPI_Comm_disconnect(&tmp);
113  if(*ierr == MPI_SUCCESS) {
114    simgrid::smpi::Comm::free_f(*comm);
115  }
116 }
117
118 void mpi_comm_set_errhandler_ (int* comm, int* errhandler, int* ierr) {
119  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Errhandler::f2c(*errhandler));
120 }
121
122 void mpi_comm_get_errhandler_ (int* comm, int* errhandler, int* ierr) {
123  MPI_Errhandler tmp;
124  *ierr = MPI_Errhandler_get(simgrid::smpi::Comm::f2c(*comm), &tmp);
125  if(*ierr == MPI_SUCCESS) {
126    *errhandler = tmp->c2f();
127  }
128 }
129
130 void mpi_comm_test_inter_ (int* comm, int* flag, int* ierr) {
131  *ierr = MPI_Comm_test_inter(simgrid::smpi::Comm::f2c(*comm), flag);
132 }
133
134 void mpi_comm_remote_group_ (int* comm, int*  group, int* ierr) {
135   MPI_Group tmp;
136  *ierr = MPI_Comm_remote_group(simgrid::smpi::Comm::f2c(*comm), &tmp);
137  if(*ierr == MPI_SUCCESS) {
138    *group = tmp->c2f();
139  }
140 }
141
142 void mpi_comm_remote_size_ (int* comm, int* size, int* ierr) {
143  *ierr = MPI_Comm_remote_size(simgrid::smpi::Comm::f2c(*comm), size);
144 }
145
146 void mpi_comm_set_name_ (int* comm, char* name, int* ierr){
147  int count;
148  for(count=MPI_MAX_OBJECT_NAME-1; count>=0 && name[count]==' '; count--);
149  count+=1;
150  std::string tname(name, count);
151  *ierr = MPI_Comm_set_name(simgrid::smpi::Comm::f2c(*comm), tname.c_str());
152 }
153
154 void mpi_comm_dup_with_info_ (int* comm, int* info, int* newcomm, int* ierr){
155   MPI_Comm tmp;
156   *ierr = MPI_Comm_dup_with_info(simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info),&tmp);
157   if(*ierr == MPI_SUCCESS) {
158     *newcomm = tmp->c2f();
159   }
160 }
161
162 void mpi_comm_split_type_ (int* comm, int* split_type, int* key, int* info, int* newcomm, int* ierr){
163   MPI_Comm tmp;
164   *ierr = MPI_Comm_split_type(simgrid::smpi::Comm::f2c(*comm), *split_type, *key, simgrid::smpi::Info::f2c(*info), &tmp);
165   if(*ierr == MPI_SUCCESS) {
166     *newcomm = tmp->c2f();
167   }
168 }
169
170 void mpi_comm_set_info_ (int* comm, int* info, int* ierr){
171  *ierr = MPI_Comm_set_info (simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info));
172 }
173
174 void mpi_comm_get_info_ (int* comm, int* info, int* ierr){
175  MPI_Info tmp;
176  *ierr = MPI_Comm_get_info (simgrid::smpi::Comm::f2c(*comm), &tmp);
177  if(*ierr==MPI_SUCCESS){
178    *info = tmp->c2f();
179  }
180 }
181
182 void mpi_comm_create_errhandler_ ( void *function, int *errhandler, int* ierr){
183  MPI_Errhandler tmp;
184  *ierr = MPI_Comm_create_errhandler( reinterpret_cast<MPI_Comm_errhandler_fn*>(function), &tmp);
185  if(*ierr==MPI_SUCCESS){
186    *errhandler = tmp->c2f();
187  }
188 }
189
190 void mpi_comm_call_errhandler_ (int* comm,int* errorcode, int* ierr){
191  *ierr = MPI_Comm_call_errhandler(simgrid::smpi::Comm::f2c(*comm), *errorcode);
192 }
193
194 void mpi_comm_connect_(char* port_name, int* info, int* root, int* comm, int* newcomm, int* ierr)
195 {
196   MPI_Comm tmp;
197   *ierr = MPI_Comm_connect(port_name, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
198   if(*ierr == MPI_SUCCESS) {
199     *newcomm = tmp->c2f();
200   }
201 }
202
203 void mpi_comm_join_ ( int* fd, int* intercomm, int* ierr){
204   MPI_Comm tmp;
205   *ierr = MPI_Comm_join( *fd, &tmp);
206   if(*ierr == MPI_SUCCESS) {
207     *intercomm = tmp->c2f();
208   }
209 }
210
211
212 void mpi_comm_accept_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
213   MPI_Comm tmp;
214   *ierr = MPI_Comm_accept( port_name, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
215   if(*ierr == MPI_SUCCESS) {
216     *newcomm = tmp->c2f();
217   }
218 }
219
220 void mpi_comm_spawn_ ( char *command, char *argv, int* maxprocs, int* info, int* root, int* comm, int* intercomm,
221                        int* array_of_errcodes, int* ierr){
222   MPI_Comm tmp;
223   *ierr = MPI_Comm_spawn( command, &argv, *maxprocs, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp,
224                           array_of_errcodes);
225   if(*ierr == MPI_SUCCESS) {
226     *intercomm = tmp->c2f();
227   }
228 }
229
230 void mpi_comm_spawn_multiple_ ( int* count, char *array_of_commands, char** array_of_argv, int* array_of_maxprocs,
231                                 int* array_of_info, int* root,
232  int* comm, int* intercomm, int* array_of_errcodes, int* ierr){
233  MPI_Comm tmp;
234  *ierr = MPI_Comm_spawn_multiple(* count, &array_of_commands, &array_of_argv, array_of_maxprocs,
235  reinterpret_cast<MPI_Info*>(array_of_info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp, array_of_errcodes);
236  if(*ierr == MPI_SUCCESS) {
237    *intercomm = tmp->c2f();
238  }
239 }
240
241 void mpi_comm_get_parent_ ( int* parent, int* ierr){
242   MPI_Comm tmp;
243   *ierr = MPI_Comm_get_parent( &tmp);
244   if(*ierr == MPI_SUCCESS) {
245     *parent = tmp->c2f();
246   }
247 }
248
249 }