Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'depencencies' of https://framagit.org/simgrid/simgrid into depencencies
[simgrid.git] / src / smpi / bindings / smpi_f77_comm.cpp
1 /* Copyright (c) 2010-2020. 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   *ierr = MPI_Comm_create(simgrid::smpi::Comm::f2c(*comm),simgrid::smpi::Group::f2c(*group), &tmp);
33   if(*ierr == MPI_SUCCESS) {
34     *newcomm = tmp->add_f();
35   }
36 }
37
38 void mpi_comm_free_(int* comm, int* ierr) {
39   MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm);
40   if(tmp != MPI_COMM_WORLD && tmp != MPI_COMM_NULL) {
41     simgrid::smpi::Comm::destroy(tmp);
42     simgrid::smpi::Comm::free_f(*comm);
43   }
44   *ierr = MPI_SUCCESS;
45 }
46
47 void mpi_comm_split_(int* comm, int* color, int* key, int* comm_out, int* ierr) {
48   MPI_Comm tmp;
49
50   *ierr = MPI_Comm_split(simgrid::smpi::Comm::f2c(*comm), *color, *key, &tmp);
51   if(*ierr == MPI_SUCCESS) {
52     *comm_out = tmp->add_f();
53   }
54 }
55
56 void mpi_comm_group_(int* comm, int* group_out,  int* ierr) {
57   MPI_Group tmp;
58   *ierr = MPI_Comm_group(simgrid::smpi::Comm::f2c(*comm), &tmp);
59   if(*ierr == MPI_SUCCESS) {
60     *group_out = tmp->c2f();
61   }
62 }
63
64 void mpi_comm_create_group_ (int* comm, int* group, int i, int* comm_out, int* ierr){
65   MPI_Comm tmp;
66  *ierr = MPI_Comm_create_group(simgrid::smpi::Comm::f2c(*comm),simgrid::smpi::Group::f2c(*group), i, &tmp);
67   if(*ierr == MPI_SUCCESS) {
68     *comm_out = tmp->c2f();
69   }
70 }
71
72 void mpi_comm_get_attr_ (int* comm, int* comm_keyval, int *attribute_val, int *flag, int* ierr){
73  int* value = nullptr;
74  *ierr = MPI_Comm_get_attr (simgrid::smpi::Comm::f2c(*comm), *comm_keyval, &value, flag);
75  if (*flag == 1)
76    *attribute_val = *value;
77 }
78
79 void mpi_comm_set_attr_ (int* comm, int* comm_keyval, int *attribute_val, int* ierr){
80  int* val = (int*)xbt_malloc(sizeof(int));
81  *val=*attribute_val;
82  *ierr = MPI_Comm_set_attr ( simgrid::smpi::Comm::f2c(*comm), *comm_keyval, val);
83 }
84
85 void mpi_comm_delete_attr_ (int* comm, int* comm_keyval, int* ierr){
86  *ierr = MPI_Comm_delete_attr (simgrid::smpi::Comm::f2c(*comm),  *comm_keyval);
87 }
88
89 void mpi_comm_create_keyval_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){
90   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};
91   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};
92   *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state);
93 }
94
95 void mpi_comm_free_keyval_ (int* keyval, int* ierr) {
96  *ierr = MPI_Comm_free_keyval( keyval);
97 }
98
99 void mpi_comm_get_name_ (int* comm, char* name, int* len, int* ierr){
100  *ierr = MPI_Comm_get_name(simgrid::smpi::Comm::f2c(*comm), name, len);
101   for(int i = *len; i<MPI_MAX_OBJECT_NAME+1; i++)
102     name[i]=' ';
103 }
104
105 void mpi_comm_compare_ (int* comm1, int* comm2, int *result, int* ierr){
106  *ierr = MPI_Comm_compare(simgrid::smpi::Comm::f2c(*comm1), simgrid::smpi::Comm::f2c(*comm2), result);
107 }
108
109 void mpi_comm_disconnect_ (int* comm, int* ierr){
110  MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm);
111  *ierr = MPI_Comm_disconnect(&tmp);
112  if(*ierr == MPI_SUCCESS) {
113    simgrid::smpi::Comm::free_f(*comm);
114  }
115 }
116
117 void mpi_comm_set_errhandler_ (int* comm, int* errhandler, int* ierr) {
118  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Errhandler::f2c(*errhandler));
119 }
120
121 void mpi_comm_get_errhandler_ (int* comm, int* errhandler, int* ierr) {
122  MPI_Errhandler tmp;
123  *ierr = MPI_Errhandler_get(simgrid::smpi::Comm::f2c(*comm), &tmp);
124  if(*ierr == MPI_SUCCESS) {
125    *errhandler = tmp->c2f();
126  }
127 }
128
129 void mpi_comm_test_inter_ (int* comm, int* flag, int* ierr) {
130  *ierr = MPI_Comm_test_inter(simgrid::smpi::Comm::f2c(*comm), flag);
131 }
132
133 void mpi_comm_remote_group_ (int* comm, int*  group, int* ierr) {
134   MPI_Group tmp;
135  *ierr = MPI_Comm_remote_group(simgrid::smpi::Comm::f2c(*comm), &tmp);
136  if(*ierr == MPI_SUCCESS) {
137    *group = tmp->c2f();
138  }
139 }
140
141 void mpi_comm_remote_size_ (int* comm, int* size, int* ierr) {
142  *ierr = MPI_Comm_remote_size(simgrid::smpi::Comm::f2c(*comm), size);
143 }
144
145 void mpi_comm_set_name_ (int* comm, char* name, int* ierr){
146  int count;
147  for(count=MPI_MAX_OBJECT_NAME-1; count>=0 && name[count]==' '; count--);
148  count+=1;
149  char* tname = xbt_new(char, count+1);
150  strncpy(tname, name, count);
151  tname[count]='\0';
152  *ierr = MPI_Comm_set_name (simgrid::smpi::Comm::f2c(*comm), tname);
153  xbt_free(tname);
154 }
155
156 void mpi_comm_dup_with_info_ (int* comm, int* info, int* newcomm, int* ierr){
157   MPI_Comm tmp;
158   *ierr = MPI_Comm_dup_with_info(simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info),&tmp);
159   if(*ierr == MPI_SUCCESS) {
160     *newcomm = tmp->add_f();
161   }
162 }
163
164 void mpi_comm_split_type_ (int* comm, int* split_type, int* key, int* info, int* newcomm, int* ierr){
165   MPI_Comm tmp;
166   *ierr = MPI_Comm_split_type(simgrid::smpi::Comm::f2c(*comm), *split_type, *key, simgrid::smpi::Info::f2c(*info), &tmp);
167   if(*ierr == MPI_SUCCESS) {
168     *newcomm = tmp->add_f();
169   }
170 }
171
172 void mpi_comm_set_info_ (int* comm, int* info, int* ierr){
173  *ierr = MPI_Comm_set_info (simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info));
174 }
175
176 void mpi_comm_get_info_ (int* comm, int* info, int* ierr){
177  MPI_Info tmp;
178  *ierr = MPI_Comm_get_info (simgrid::smpi::Comm::f2c(*comm), &tmp);
179  if(*ierr==MPI_SUCCESS){
180    *info = tmp->c2f();
181  }
182 }
183
184 void mpi_comm_create_errhandler_ ( void *function, int *errhandler, int* ierr){
185  MPI_Errhandler tmp;
186  *ierr = MPI_Comm_create_errhandler( reinterpret_cast<MPI_Comm_errhandler_fn*>(function), &tmp);
187  if(*ierr==MPI_SUCCESS){
188    *errhandler = tmp->c2f();
189  }
190 }
191
192 void mpi_comm_call_errhandler_ (int* comm,int* errorcode, int* ierr){
193  *ierr = MPI_Comm_call_errhandler(simgrid::smpi::Comm::f2c(*comm), *errorcode);
194 }
195
196 void mpi_comm_connect_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
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->add_f();
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->add_f();
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->add_f();
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->add_f();
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->add_f();
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 }