Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
please herr sonar
[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_info.hpp"
9
10 extern "C" { // This should really use the C linkage to be usable from Fortran
11
12 void mpi_comm_rank_(int* comm, int* rank, int* ierr) {
13    *ierr = MPI_Comm_rank(simgrid::smpi::Comm::f2c(*comm), rank);
14 }
15
16 void mpi_comm_size_(int* comm, int* size, int* ierr) {
17    *ierr = MPI_Comm_size(simgrid::smpi::Comm::f2c(*comm), size);
18 }
19
20 void mpi_comm_dup_(int* comm, int* newcomm, int* ierr) {
21   MPI_Comm tmp;
22
23   *ierr = MPI_Comm_dup(simgrid::smpi::Comm::f2c(*comm), &tmp);
24   if(*ierr == MPI_SUCCESS) {
25     *newcomm = tmp->add_f();
26   }
27 }
28
29 void mpi_comm_create_(int* comm, int* group, int* newcomm, int* ierr) {
30   MPI_Comm tmp;
31
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
41   *ierr = MPI_Comm_free(&tmp);
42
43   if(*ierr == MPI_SUCCESS) {
44     simgrid::smpi::Comm::free_f(*comm);
45   }
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   if(*len>0)
105     for(int i = *len; i<MPI_MAX_OBJECT_NAME+1; i++)
106       name[i]=' ';
107 }
108
109 void mpi_comm_compare_ (int* comm1, int* comm2, int *result, int* ierr){
110
111  *ierr = MPI_Comm_compare(simgrid::smpi::Comm::f2c(*comm1), simgrid::smpi::Comm::f2c(*comm2), result);
112 }
113
114 void mpi_comm_disconnect_ (int* comm, int* ierr){
115  MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm);
116  *ierr = MPI_Comm_disconnect(&tmp);
117  if(*ierr == MPI_SUCCESS) {
118    simgrid::smpi::Comm::free_f(*comm);
119  }
120 }
121
122 void mpi_comm_set_errhandler_ (int* comm, void* errhandler, int* ierr) {
123  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), *static_cast<MPI_Errhandler*>(errhandler));
124 }
125
126 void mpi_comm_get_errhandler_ (int* comm, void* errhandler, int* ierr) {
127  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), static_cast<MPI_Errhandler*>(errhandler));
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  char* tname = xbt_new(char, count+1);
151  strncpy(tname, name, count);
152  tname[count]='\0';
153  *ierr = MPI_Comm_set_name (simgrid::smpi::Comm::f2c(*comm), tname);
154  xbt_free(tname);
155 }
156
157 void mpi_comm_dup_with_info_ (int* comm, int* info, int* newcomm, int* ierr){
158   MPI_Comm tmp;
159   *ierr = MPI_Comm_dup_with_info(simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info),&tmp);
160   if(*ierr == MPI_SUCCESS) {
161     *newcomm = tmp->add_f();
162   }
163 }
164
165 void mpi_comm_split_type_ (int* comm, int* split_type, int* key, int* info, int* newcomm, int* ierr){
166   MPI_Comm tmp;
167   *ierr = MPI_Comm_split_type(simgrid::smpi::Comm::f2c(*comm), *split_type, *key, simgrid::smpi::Info::f2c(*info), &tmp);
168   if(*ierr == MPI_SUCCESS) {
169     *newcomm = tmp->add_f();
170   }
171 }
172
173 void mpi_comm_set_info_ (int* comm, int* info, int* ierr){
174  *ierr = MPI_Comm_set_info (simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info));
175 }
176
177 void mpi_comm_get_info_ (int* comm, int* info, int* ierr){
178  MPI_Info tmp;
179  *ierr = MPI_Comm_get_info (simgrid::smpi::Comm::f2c(*comm), &tmp);
180  if(*ierr==MPI_SUCCESS){
181    *info = tmp->c2f();
182  }
183 }
184
185 void mpi_comm_create_errhandler_ ( void *function, void *errhandler, int* ierr){
186  *ierr = MPI_Comm_create_errhandler( reinterpret_cast<MPI_Comm_errhandler_fn*>(function), static_cast<MPI_Errhandler*>(errhandler));
187 }
188
189 void mpi_comm_call_errhandler_ (int* comm,int* errorcode, int* ierr){
190  *ierr = MPI_Comm_call_errhandler(simgrid::smpi::Comm::f2c(*comm), *errorcode);
191 }
192
193 void mpi_comm_connect_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
194   MPI_Comm tmp;
195   *ierr = MPI_Comm_connect( port_name, *reinterpret_cast<MPI_Info*>(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
196   if(*ierr == MPI_SUCCESS) {
197     *newcomm = tmp->add_f();
198   }
199 }
200
201 void mpi_comm_join_ ( int* fd, int* intercomm, int* ierr){
202   MPI_Comm tmp;
203   *ierr = MPI_Comm_join( *fd, &tmp);
204   if(*ierr == MPI_SUCCESS) {
205     *intercomm = tmp->add_f();
206   }
207 }
208
209
210 void mpi_comm_accept_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
211   MPI_Comm tmp;
212   *ierr = MPI_Comm_accept( port_name, *reinterpret_cast<MPI_Info*>(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
213   if(*ierr == MPI_SUCCESS) {
214     *newcomm = tmp->add_f();
215   }
216 }
217
218 void mpi_comm_spawn_ ( char *command, char *argv, int* maxprocs, int* info, int* root, int* comm, int* intercomm,
219                        int* array_of_errcodes, int* ierr){
220   MPI_Comm tmp;
221   *ierr = MPI_Comm_spawn( command, &argv, *maxprocs, *reinterpret_cast<MPI_Info*>(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp,
222                           array_of_errcodes);
223   if(*ierr == MPI_SUCCESS) {
224     *intercomm = tmp->add_f();
225   }
226 }
227
228 void mpi_comm_spawn_multiple_ ( int* count, char *array_of_commands, char** array_of_argv, int* array_of_maxprocs,
229                                 int* array_of_info, int* root,
230  int* comm, int* intercomm, int* array_of_errcodes, int* ierr){
231  MPI_Comm tmp;
232  *ierr = MPI_Comm_spawn_multiple(* count, &array_of_commands, &array_of_argv, array_of_maxprocs,
233  reinterpret_cast<MPI_Info*>(array_of_info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp, array_of_errcodes);
234  if(*ierr == MPI_SUCCESS) {
235    *intercomm = tmp->add_f();
236  }
237 }
238
239 void mpi_comm_get_parent_ ( int* parent, int* ierr){
240   MPI_Comm tmp;
241   *ierr = MPI_Comm_get_parent( &tmp);
242   if(*ierr == MPI_SUCCESS) {
243     *parent = tmp->c2f();
244   }
245 }
246
247 }