Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
renamed some functions and moved some data structures to make things more
[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                 *rank = smpi_mpi_comm_rank_self(comm);
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;
103
104         smpi_bench_end();
105
106         dst = smpi_mpi_comm_rank_self(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;
125         smpi_mpi_request_t request;
126
127         smpi_bench_end();
128
129         dst = smpi_mpi_comm_rank_self(comm);
130         retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
131
132         if (NULL != request && MPI_SUCCESS == retval) {
133                 retval = smpi_mpi_irecv(request);
134                 if (MPI_SUCCESS == retval) {
135                         retval = smpi_mpi_wait(request, status);
136                 }
137                 xbt_mallocator_release(smpi_global->request_mallocator, request);
138         }
139
140         smpi_bench_begin();
141
142         return retval;
143 }
144
145 int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request *request)
146 {
147         int retval = MPI_SUCCESS;
148         int src;
149
150         smpi_bench_end();
151
152         src = smpi_mpi_comm_rank_self(comm);
153         if (NULL == request) {
154                 retval = MPI_ERR_ARG;
155         } else {
156                 retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
157                 if (NULL != *request && MPI_SUCCESS == retval) {
158                         retval = smpi_mpi_isend(*request);
159                 }
160         }
161
162         smpi_bench_begin();
163
164         return retval;
165 }
166
167 int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
168 {
169         int retval = MPI_SUCCESS;
170         int src;
171         smpi_mpi_request_t request;
172
173         smpi_bench_end();
174
175         src = smpi_mpi_comm_rank_self(comm);
176         retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
177         if (NULL != request && MPI_SUCCESS == retval) {
178                 retval = smpi_mpi_isend(request);
179                 if (MPI_SUCCESS == retval) {
180                         smpi_mpi_wait(request, MPI_STATUS_IGNORE);
181                 }
182                 xbt_mallocator_release(smpi_global->request_mallocator, request);
183         }
184
185         smpi_bench_begin();
186
187         return retval;
188 }