Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
102520e22d508b0d5fb65d631a3eb0814b75723a
[simgrid.git] / src / smpi / smpi_mpi.c
1 #include "private.h"
2
3 int MPI_Init(int *argc, char ***argv)
4 {
5         smpi_mpi_init();
6         smpi_bench_begin();
7         return MPI_SUCCESS;
8 }
9
10 int MPI_Finalize()
11 {
12         smpi_bench_end();
13         smpi_mpi_finalize();
14         return MPI_SUCCESS;
15 }
16
17 // right now this just exits the current node, should send abort signal to all
18 // hosts in the communicator;
19 int MPI_Abort(MPI_Comm comm, int errorcode)
20 {
21         smpi_exit(errorcode);
22         return 0;
23 }
24
25 int MPI_Comm_size(MPI_Comm comm, int *size)
26 {
27         int retval = MPI_SUCCESS;
28
29         smpi_bench_end();
30
31         if (NULL == comm) {
32                 retval = MPI_ERR_COMM;
33         } else if (NULL == size) {
34                 retval = MPI_ERR_ARG;
35         } else {
36                 *size = comm->size;
37         }
38
39         smpi_bench_begin();
40
41         return retval;
42 }
43
44 int MPI_Comm_rank(MPI_Comm comm, int *rank)
45 {
46         int retval = MPI_SUCCESS;
47
48         smpi_bench_end();
49
50         if (NULL == comm) {
51                 retval = MPI_ERR_COMM;
52         } else if (NULL == rank) {
53                 retval = MPI_ERR_ARG;
54         } else {
55                 retval = smpi_mpi_comm_rank(comm, rank);
56         }
57
58         smpi_bench_begin();
59
60         return retval;
61 }
62
63 int MPI_Type_size(MPI_Datatype datatype, size_t *size)
64 {
65         int retval = MPI_SUCCESS;
66
67         smpi_bench_end();
68
69         if (NULL == datatype) {
70                 retval = MPI_ERR_TYPE;
71         } else if (NULL == size) {
72                 retval = MPI_ERR_ARG;
73         } else {
74                 *size = datatype->size;
75         }
76
77         smpi_bench_begin();
78
79         return retval;
80 }
81
82 int MPI_Barrier(MPI_Comm comm)
83 {
84         int retval = MPI_SUCCESS;
85
86         smpi_bench_end();
87
88         if (NULL == comm) {
89                 retval = MPI_ERR_COMM;
90         } else {
91                 retval = smpi_mpi_barrier(comm);
92         }
93
94         smpi_bench_begin();
95
96         return retval;
97 }
98
99 int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request)
100 {
101         int retval = MPI_SUCCESS;
102         int dst = 0;
103
104         smpi_bench_end();
105
106         //dst = smpi_mpi_comm_rank(comm);
107         if (NULL == request) {
108                 retval = MPI_ERR_ARG;
109         } else {
110                 retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
111                 if (NULL != *request && MPI_SUCCESS == retval) {
112                         retval = smpi_mpi_irecv(*request);
113                 }
114         }
115
116         smpi_bench_begin();
117
118         return retval;
119 }
120
121 int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
122 {
123         int retval = MPI_SUCCESS;
124         int dst = 0;
125         smpi_mpi_request_t request;
126
127         smpi_bench_end();
128
129         // FIXME: necessary?
130         //dst = smpi_mpi_comm_rank(comm);
131         retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
132
133         if (NULL != request && MPI_SUCCESS == retval) {
134                 retval = smpi_mpi_irecv(request);
135                 if (MPI_SUCCESS == retval) {
136                         retval = smpi_mpi_wait(request, status);
137                 }
138                 xbt_mallocator_release(smpi_global->request_mallocator, request);
139         }
140
141         smpi_bench_begin();
142
143         return retval;
144 }
145
146 int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request *request)
147 {
148         int retval = MPI_SUCCESS;
149         int src = 0;
150
151         smpi_bench_end();
152
153         //src = smpi_mpi_comm_rank(comm);
154         if (NULL == request) {
155                 retval = MPI_ERR_ARG;
156         } else {
157                 retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
158                 if (NULL != *request && MPI_SUCCESS == retval) {
159                         retval = smpi_mpi_isend(*request);
160                 }
161         }
162
163         smpi_bench_begin();
164
165         return retval;
166 }
167
168 int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
169 {
170         int retval = MPI_SUCCESS;
171         int src = 0;
172         smpi_mpi_request_t request;
173
174         smpi_bench_end();
175
176         //src = smpi_mpi_comm_rank(comm);
177         retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
178         if (NULL != request && MPI_SUCCESS == retval) {
179                 retval = smpi_mpi_isend(request);
180                 if (MPI_SUCCESS == retval) {
181                         smpi_mpi_wait(request, MPI_STATUS_IGNORE);
182                 }
183                 xbt_mallocator_release(smpi_global->request_mallocator, request);
184         }
185
186         smpi_bench_begin();
187
188         return retval;
189 }