Logo AND Algorithmique Numérique Distribuée

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