Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
used host user data to store global index values and remove some clunky
[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(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
103         smpi_bench_end();
104
105         if (NULL == request) {
106                 retval = MPI_ERR_ARG;
107         } else {
108                 int dst = 0;
109                 retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
110                 if (NULL != *request && MPI_SUCCESS == retval) {
111                         retval = smpi_mpi_irecv(*request);
112                 }
113         }
114
115         smpi_bench_begin();
116
117         return retval;
118 }
119
120 int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
121 {
122         int retval = MPI_SUCCESS;
123         int dst = 0;
124         smpi_mpi_request_t request;
125
126         smpi_bench_end();
127
128         retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
129         if (NULL != request && MPI_SUCCESS == retval) {
130                 retval = smpi_mpi_irecv(request);
131                 if (MPI_SUCCESS == retval) {
132                         retval = smpi_mpi_wait(request, status);
133                 }
134                 xbt_mallocator_release(smpi_global->request_mallocator, request);
135         }
136
137         smpi_bench_begin();
138
139         return retval;
140 }
141
142 int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request *request)
143 {
144         int retval = MPI_SUCCESS;
145
146         smpi_bench_end();
147
148         if (NULL == request) {
149                 retval = MPI_ERR_ARG;
150         } else {
151                 int src = 0;
152                 retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
153                 if (NULL != *request && MPI_SUCCESS == retval) {
154                         retval = smpi_mpi_isend(*request);
155                 }
156         }
157
158         smpi_bench_begin();
159
160         return retval;
161 }
162
163 int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
164 {
165         int retval = MPI_SUCCESS;
166         int src = 0;
167         smpi_mpi_request_t request;
168
169         smpi_bench_end();
170
171         retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
172         if (NULL != request && MPI_SUCCESS == retval) {
173                 retval = smpi_mpi_isend(request);
174                 if (MPI_SUCCESS == retval) {
175                         smpi_mpi_wait(request, MPI_STATUS_IGNORE);
176                 }
177                 xbt_mallocator_release(smpi_global->request_mallocator, request);
178         }
179
180         smpi_bench_begin();
181
182         return retval;
183 }