Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fe412d3e1b96e0e8a636761a30e0efb97124cb89
[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
23         return 0;
24 }
25
26 int MPI_Comm_size(MPI_Comm comm, int *size)
27 {
28         int retval = MPI_SUCCESS;
29
30         smpi_bench_end();
31
32         if (NULL == comm) {
33                 retval = MPI_ERR_COMM;
34         } else if (NULL == size) {
35                 retval = MPI_ERR_ARG;
36         } else {
37                 *size = comm->size;
38         }
39
40         smpi_bench_begin();
41
42         return retval;
43 }
44
45 int MPI_Comm_rank(MPI_Comm comm, int *rank)
46 {
47         int retval = MPI_SUCCESS;
48
49         smpi_bench_end();
50
51         if (NULL == comm) {
52                 retval = MPI_ERR_COMM;
53         } else if (NULL == rank) {
54                 retval = MPI_ERR_ARG;
55         } else {
56                 *rank = smpi_mpi_comm_rank(comm, SIMIX_host_self());
57         }
58
59         smpi_bench_begin();
60
61         return retval;
62 }
63
64 int MPI_Type_size(MPI_Datatype datatype, size_t *size)
65 {
66         int retval = MPI_SUCCESS;
67
68         smpi_bench_end();
69
70         if (NULL == datatype) {
71                 retval = MPI_ERR_TYPE;
72         } else if (NULL == size) {
73                 retval = MPI_ERR_ARG;
74         } else {
75                 *size = datatype->size;
76         }
77
78         smpi_bench_begin();
79
80         return retval;
81 }
82
83 // FIXME: check comm value and barrier success...
84 int MPI_Barrier(MPI_Comm comm)
85 {
86         smpi_bench_end();
87         smpi_barrier(comm);
88         smpi_bench_begin();
89         return MPI_SUCCESS;
90 }
91
92 int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request)
93 {
94         int retval = MPI_SUCCESS;
95         int dst;
96         smpi_bench_end();
97         dst = smpi_mpi_comm_rank_self(comm);
98         retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
99         if (NULL != *request && MPI_SUCCESS == retval) {
100                 retval = smpi_irecv(*request);
101         }
102         smpi_bench_begin();
103         return retval;
104 }
105
106 int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
107 {
108         int retval = MPI_SUCCESS;
109         int dst;
110         smpi_mpi_request_t request;
111         int rank;
112         smpi_bench_end();
113         dst = smpi_mpi_comm_rank_self(comm);
114         retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
115         if (NULL != request && MPI_SUCCESS == retval) {
116                 retval = smpi_irecv(request);
117                 if (MPI_SUCCESS == retval) {
118                         retval = smpi_wait(request, status);
119                 }
120                 rank = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
121                 xbt_mallocator_release(smpi_global->request_mallocator, request);
122         }
123         smpi_bench_begin();
124         return retval;
125 }
126
127 int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request *request)
128 {
129         int retval = MPI_SUCCESS;
130         int src;
131         smpi_bench_end();
132         src = smpi_mpi_comm_rank_self(comm);
133         retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
134         if (NULL != *request && MPI_SUCCESS == retval) {
135                 retval = smpi_isend(*request);
136         }
137         smpi_bench_begin();
138         return retval;
139 }
140
141 int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
142 {
143         int retval = MPI_SUCCESS;
144         int src;
145         smpi_mpi_request_t request;
146         int rank;
147         smpi_bench_end();
148         src = smpi_mpi_comm_rank_self(comm);
149         retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
150         if (NULL != request && MPI_SUCCESS == retval) {
151                 retval = smpi_isend(request);
152                 if (MPI_SUCCESS == retval) {
153                         smpi_wait(request, MPI_STATUS_IGNORE);
154                 }
155                 rank = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
156                 xbt_mallocator_release(smpi_global->request_mallocator, request);
157         }
158         smpi_bench_begin();
159         return retval;
160 }