Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
93dbf834773766f5ba7cabded4d6d6f61998e0b2
[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  size_t value = 0;
76  *ierr = MPI_Comm_get_attr (simgrid::smpi::Comm::f2c(*comm), *comm_keyval, &value, flag);
77  *attribute_val = *(int*) value;
78 }
79
80 void mpi_comm_set_attr_ (int* comm, int* comm_keyval, void *attribute_val, int* ierr){
81
82  *ierr = MPI_Comm_set_attr ( simgrid::smpi::Comm::f2c(*comm), *comm_keyval, attribute_val);
83 }
84
85 void mpi_comm_delete_attr_ (int* comm, int* comm_keyval, int* ierr){
86
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
92  *ierr = MPI_Comm_create_keyval(reinterpret_cast<MPI_Comm_copy_attr_function*>(copy_fn),  reinterpret_cast<MPI_Comm_delete_attr_function*>(delete_fn),
93          keyval,  extra_state) ;
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   if(*len>0)
103     name[*len]=' ';
104 }
105
106 void mpi_comm_compare_ (int* comm1, int* comm2, int *result, int* ierr){
107
108  *ierr = MPI_Comm_compare(simgrid::smpi::Comm::f2c(*comm1), simgrid::smpi::Comm::f2c(*comm2), result);
109 }
110
111 void mpi_comm_disconnect_ (int* comm, int* ierr){
112  MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm);
113  *ierr = MPI_Comm_disconnect(&tmp);
114  if(*ierr == MPI_SUCCESS) {
115    simgrid::smpi::Comm::free_f(*comm);
116  }
117 }
118
119 void mpi_comm_set_errhandler_ (int* comm, void* errhandler, int* ierr) {
120  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), *static_cast<MPI_Errhandler*>(errhandler));
121 }
122
123 void mpi_comm_get_errhandler_ (int* comm, void* errhandler, int* ierr) {
124  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), static_cast<MPI_Errhandler*>(errhandler));
125 }
126
127 void mpi_comm_test_inter_ (int* comm, int* flag, int* ierr) {
128  *ierr = MPI_Comm_test_inter(simgrid::smpi::Comm::f2c(*comm), flag);
129 }
130
131 void mpi_comm_remote_group_ (int* comm, int*  group, int* ierr) {
132   MPI_Group tmp;
133  *ierr = MPI_Comm_remote_group(simgrid::smpi::Comm::f2c(*comm), &tmp);
134  if(*ierr == MPI_SUCCESS) {
135    *group = tmp->c2f();
136  }
137 }
138
139 void mpi_comm_remote_size_ (int* comm, int* size, int* ierr) {
140  *ierr = MPI_Comm_remote_size(simgrid::smpi::Comm::f2c(*comm), size);
141 }
142
143 void mpi_comm_set_name_ (int* comm, char* name, int* ierr, int size){
144  char* tname = xbt_new(char, size+1);
145  strncpy(tname, name, size);
146  tname[size]='\0';
147  *ierr = MPI_Comm_set_name (simgrid::smpi::Comm::f2c(*comm), tname);
148  xbt_free(tname);
149 }
150
151 void mpi_comm_dup_with_info_ (int* comm, int* info, int* newcomm, int* ierr){
152   MPI_Comm tmp;
153   *ierr = MPI_Comm_dup_with_info(simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info),&tmp);
154   if(*ierr == MPI_SUCCESS) {
155     *newcomm = tmp->add_f();
156   }
157 }
158
159 void mpi_comm_split_type_ (int* comm, int* split_type, int* key, int* info, int* newcomm, int* ierr){
160   MPI_Comm tmp;
161   *ierr = MPI_Comm_split_type(simgrid::smpi::Comm::f2c(*comm), *split_type, *key, simgrid::smpi::Info::f2c(*info), &tmp);
162   if(*ierr == MPI_SUCCESS) {
163     *newcomm = tmp->add_f();
164   }
165 }
166
167 void mpi_comm_set_info_ (int* comm, int* info, int* ierr){
168  *ierr = MPI_Comm_set_info (simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info));
169 }
170
171 void mpi_comm_get_info_ (int* comm, int* info, int* ierr){
172  MPI_Info tmp;
173  *ierr = MPI_Comm_get_info (simgrid::smpi::Comm::f2c(*comm), &tmp);
174  if(*ierr==MPI_SUCCESS){
175    *info = tmp->c2f();
176  }
177 }
178
179 void mpi_comm_create_errhandler_ ( void *function, void *errhandler, int* ierr){
180  *ierr = MPI_Comm_create_errhandler( reinterpret_cast<MPI_Comm_errhandler_fn*>(function), static_cast<MPI_Errhandler*>(errhandler));
181 }
182
183 void mpi_comm_call_errhandler_ (int* comm,int* errorcode, int* ierr){
184  *ierr = MPI_Comm_call_errhandler(simgrid::smpi::Comm::f2c(*comm), *errorcode);
185 }
186
187 void mpi_comm_connect_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
188   MPI_Comm tmp;
189   *ierr = MPI_Comm_connect( port_name, *reinterpret_cast<MPI_Info*>(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
190   if(*ierr == MPI_SUCCESS) {
191     *newcomm = tmp->add_f();
192   }
193 }
194
195 void mpi_comm_join_ ( int* fd, int* intercomm, int* ierr){
196   MPI_Comm tmp;
197   *ierr = MPI_Comm_join( *fd, &tmp);
198   if(*ierr == MPI_SUCCESS) {
199     *intercomm = tmp->add_f();
200   }
201 }
202
203
204 void mpi_comm_accept_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
205   MPI_Comm tmp;
206   *ierr = MPI_Comm_accept( port_name, *reinterpret_cast<MPI_Info*>(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
207   if(*ierr == MPI_SUCCESS) {
208     *newcomm = tmp->add_f();
209   }
210 }
211
212 void mpi_comm_spawn_ ( char *command, char *argv, int* maxprocs, int* info, int* root, int* comm, int* intercomm,
213                        int* array_of_errcodes, int* ierr){
214   MPI_Comm tmp;
215   *ierr = MPI_Comm_spawn( command, &argv, *maxprocs, *reinterpret_cast<MPI_Info*>(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp,
216                           array_of_errcodes);
217   if(*ierr == MPI_SUCCESS) {
218     *intercomm = tmp->add_f();
219   }
220 }
221
222 void mpi_comm_spawn_multiple_ ( int* count, char *array_of_commands, char** array_of_argv, int* array_of_maxprocs,
223                                 int* array_of_info, int* root,
224  int* comm, int* intercomm, int* array_of_errcodes, int* ierr){
225  MPI_Comm tmp;
226  *ierr = MPI_Comm_spawn_multiple(* count, &array_of_commands, &array_of_argv, array_of_maxprocs,
227  reinterpret_cast<MPI_Info*>(array_of_info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp, array_of_errcodes);
228  if(*ierr == MPI_SUCCESS) {
229    *intercomm = tmp->add_f();
230  }
231 }
232
233 void mpi_comm_get_parent_ ( int* parent, int* ierr){
234   MPI_Comm tmp;
235   *ierr = MPI_Comm_get_parent( &tmp);
236   if(*ierr == MPI_SUCCESS) {
237     *parent = tmp->c2f();
238   }
239 }
240
241 }