Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
protect against failed get
[simgrid.git] / src / smpi / bindings / smpi_f77_comm.cpp
1 /* Copyright (c) 2010-2018. 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, void *attribute_val, int* ierr){
82
83  *ierr = MPI_Comm_set_attr ( simgrid::smpi::Comm::f2c(*comm), *comm_keyval, attribute_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
93  *ierr = MPI_Comm_create_keyval(reinterpret_cast<MPI_Comm_copy_attr_function*>(copy_fn),  reinterpret_cast<MPI_Comm_delete_attr_function*>(delete_fn),
94          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   if(*len>0)
104     name[*len]=' ';
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, int size){
145  char* tname = xbt_new(char, size+1);
146  strncpy(tname, name, size);
147  tname[size]='\0';
148  *ierr = MPI_Comm_set_name (simgrid::smpi::Comm::f2c(*comm), tname);
149  xbt_free(tname);
150 }
151
152 void mpi_comm_dup_with_info_ (int* comm, int* info, int* newcomm, int* ierr){
153   MPI_Comm tmp;
154   *ierr = MPI_Comm_dup_with_info(simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info),&tmp);
155   if(*ierr == MPI_SUCCESS) {
156     *newcomm = tmp->add_f();
157   }
158 }
159
160 void mpi_comm_split_type_ (int* comm, int* split_type, int* key, int* info, int* newcomm, int* ierr){
161   MPI_Comm tmp;
162   *ierr = MPI_Comm_split_type(simgrid::smpi::Comm::f2c(*comm), *split_type, *key, simgrid::smpi::Info::f2c(*info), &tmp);
163   if(*ierr == MPI_SUCCESS) {
164     *newcomm = tmp->add_f();
165   }
166 }
167
168 void mpi_comm_set_info_ (int* comm, int* info, int* ierr){
169  *ierr = MPI_Comm_set_info (simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info));
170 }
171
172 void mpi_comm_get_info_ (int* comm, int* info, int* ierr){
173  MPI_Info tmp;
174  *ierr = MPI_Comm_get_info (simgrid::smpi::Comm::f2c(*comm), &tmp);
175  if(*ierr==MPI_SUCCESS){
176    *info = tmp->c2f();
177  }
178 }
179
180 void mpi_comm_create_errhandler_ ( void *function, void *errhandler, int* ierr){
181  *ierr = MPI_Comm_create_errhandler( reinterpret_cast<MPI_Comm_errhandler_fn*>(function), static_cast<MPI_Errhandler*>(errhandler));
182 }
183
184 void mpi_comm_call_errhandler_ (int* comm,int* errorcode, int* ierr){
185  *ierr = MPI_Comm_call_errhandler(simgrid::smpi::Comm::f2c(*comm), *errorcode);
186 }
187
188 void mpi_comm_connect_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
189   MPI_Comm tmp;
190   *ierr = MPI_Comm_connect( port_name, *reinterpret_cast<MPI_Info*>(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
191   if(*ierr == MPI_SUCCESS) {
192     *newcomm = tmp->add_f();
193   }
194 }
195
196 void mpi_comm_join_ ( int* fd, int* intercomm, int* ierr){
197   MPI_Comm tmp;
198   *ierr = MPI_Comm_join( *fd, &tmp);
199   if(*ierr == MPI_SUCCESS) {
200     *intercomm = tmp->add_f();
201   }
202 }
203
204
205 void mpi_comm_accept_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
206   MPI_Comm tmp;
207   *ierr = MPI_Comm_accept( port_name, *reinterpret_cast<MPI_Info*>(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
208   if(*ierr == MPI_SUCCESS) {
209     *newcomm = tmp->add_f();
210   }
211 }
212
213 void mpi_comm_spawn_ ( char *command, char *argv, int* maxprocs, int* info, int* root, int* comm, int* intercomm,
214                        int* array_of_errcodes, int* ierr){
215   MPI_Comm tmp;
216   *ierr = MPI_Comm_spawn( command, &argv, *maxprocs, *reinterpret_cast<MPI_Info*>(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp,
217                           array_of_errcodes);
218   if(*ierr == MPI_SUCCESS) {
219     *intercomm = tmp->add_f();
220   }
221 }
222
223 void mpi_comm_spawn_multiple_ ( int* count, char *array_of_commands, char** array_of_argv, int* array_of_maxprocs,
224                                 int* array_of_info, int* root,
225  int* comm, int* intercomm, int* array_of_errcodes, int* ierr){
226  MPI_Comm tmp;
227  *ierr = MPI_Comm_spawn_multiple(* count, &array_of_commands, &array_of_argv, array_of_maxprocs,
228  reinterpret_cast<MPI_Info*>(array_of_info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp, array_of_errcodes);
229  if(*ierr == MPI_SUCCESS) {
230    *intercomm = tmp->add_f();
231  }
232 }
233
234 void mpi_comm_get_parent_ ( int* parent, int* ierr){
235   MPI_Comm tmp;
236   *ierr = MPI_Comm_get_parent( &tmp);
237   if(*ierr == MPI_SUCCESS) {
238     *parent = tmp->c2f();
239   }
240 }
241
242 }