Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Actor: make the refcount observable, and improve debug messages
[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   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
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  int* val = (int*)xbt_malloc(sizeof(int));
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
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);
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
109  *ierr = MPI_Comm_compare(simgrid::smpi::Comm::f2c(*comm1), simgrid::smpi::Comm::f2c(*comm2), result);
110 }
111
112 void mpi_comm_disconnect_ (int* comm, int* ierr){
113  MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm);
114  *ierr = MPI_Comm_disconnect(&tmp);
115  if(*ierr == MPI_SUCCESS) {
116    simgrid::smpi::Comm::free_f(*comm);
117  }
118 }
119
120 void mpi_comm_set_errhandler_ (int* comm, void* errhandler, int* ierr) {
121  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), *static_cast<MPI_Errhandler*>(errhandler));
122 }
123
124 void mpi_comm_get_errhandler_ (int* comm, void* errhandler, int* ierr) {
125  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), static_cast<MPI_Errhandler*>(errhandler));
126 }
127
128 void mpi_comm_test_inter_ (int* comm, int* flag, int* ierr) {
129  *ierr = MPI_Comm_test_inter(simgrid::smpi::Comm::f2c(*comm), flag);
130 }
131
132 void mpi_comm_remote_group_ (int* comm, int*  group, int* ierr) {
133   MPI_Group tmp;
134  *ierr = MPI_Comm_remote_group(simgrid::smpi::Comm::f2c(*comm), &tmp);
135  if(*ierr == MPI_SUCCESS) {
136    *group = tmp->c2f();
137  }
138 }
139
140 void mpi_comm_remote_size_ (int* comm, int* size, int* ierr) {
141  *ierr = MPI_Comm_remote_size(simgrid::smpi::Comm::f2c(*comm), size);
142 }
143
144 void mpi_comm_set_name_ (int* comm, char* name, int* ierr){
145  int count;
146  for(count=MPI_MAX_OBJECT_NAME-1; count>=0 && name[count]==' '; count--);
147  count+=1;
148  char* tname = xbt_new(char, count+1);
149  strncpy(tname, name, count);
150  tname[count]='\0';
151  *ierr = MPI_Comm_set_name (simgrid::smpi::Comm::f2c(*comm), tname);
152  xbt_free(tname);
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->add_f();
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->add_f();
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, void *errhandler, int* ierr){
184  *ierr = MPI_Comm_create_errhandler( reinterpret_cast<MPI_Comm_errhandler_fn*>(function), static_cast<MPI_Errhandler*>(errhandler));
185 }
186
187 void mpi_comm_call_errhandler_ (int* comm,int* errorcode, int* ierr){
188  *ierr = MPI_Comm_call_errhandler(simgrid::smpi::Comm::f2c(*comm), *errorcode);
189 }
190
191 void mpi_comm_connect_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
192   MPI_Comm tmp;
193   *ierr = MPI_Comm_connect( port_name, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
194   if(*ierr == MPI_SUCCESS) {
195     *newcomm = tmp->add_f();
196   }
197 }
198
199 void mpi_comm_join_ ( int* fd, int* intercomm, int* ierr){
200   MPI_Comm tmp;
201   *ierr = MPI_Comm_join( *fd, &tmp);
202   if(*ierr == MPI_SUCCESS) {
203     *intercomm = tmp->add_f();
204   }
205 }
206
207
208 void mpi_comm_accept_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
209   MPI_Comm tmp;
210   *ierr = MPI_Comm_accept( port_name, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
211   if(*ierr == MPI_SUCCESS) {
212     *newcomm = tmp->add_f();
213   }
214 }
215
216 void mpi_comm_spawn_ ( char *command, char *argv, int* maxprocs, int* info, int* root, int* comm, int* intercomm,
217                        int* array_of_errcodes, int* ierr){
218   MPI_Comm tmp;
219   *ierr = MPI_Comm_spawn( command, &argv, *maxprocs, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp,
220                           array_of_errcodes);
221   if(*ierr == MPI_SUCCESS) {
222     *intercomm = tmp->add_f();
223   }
224 }
225
226 void mpi_comm_spawn_multiple_ ( int* count, char *array_of_commands, char** array_of_argv, int* array_of_maxprocs,
227                                 int* array_of_info, int* root,
228  int* comm, int* intercomm, int* array_of_errcodes, int* ierr){
229  MPI_Comm tmp;
230  *ierr = MPI_Comm_spawn_multiple(* count, &array_of_commands, &array_of_argv, array_of_maxprocs,
231  reinterpret_cast<MPI_Info*>(array_of_info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp, array_of_errcodes);
232  if(*ierr == MPI_SUCCESS) {
233    *intercomm = tmp->add_f();
234  }
235 }
236
237 void mpi_comm_get_parent_ ( int* parent, int* ierr){
238   MPI_Comm tmp;
239   *ierr = MPI_Comm_get_parent( &tmp);
240   if(*ierr == MPI_SUCCESS) {
241     *parent = tmp->c2f();
242   }
243 }
244
245 }