source: XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_wait.cpp @ 1146

Last change on this file since 1146 was 1146, checked in by yushan, 7 years ago

save modif

File size: 4.3 KB
Line 
1/*!
2  \file ep_wait.cpp
3  \since 2 may 2016
4
5  \brief Definitions of MPI wait function: MPI_Wait, MPI_Waitall, MPI_Waitsome, MPI_Waitany
6  */
7
8#include "ep_lib.hpp"
9#include <mpi.h>
10#include "ep_declaration.hpp"
11
12using namespace std;
13
14
15
16namespace ep_lib {     
17
18    int MPI_Wait(MPI_Request *request, MPI_Status *status)
19    {
20
21        if(request->type == 1)
22        {
23            ::MPI_Request mpi_request = static_cast< ::MPI_Request >(request->mpi_request);
24            ::MPI_Status mpi_status;
25            ::MPI_Wait(&mpi_request, &mpi_status);
26
27
28
29            status->mpi_status = &mpi_status;
30            status->ep_src = request->ep_src;
31            status->ep_tag = request->ep_tag;
32            status->ep_datatype = request->ep_datatype;
33
34            return 0;
35        }
36
37        if(request->type == 2)
38        {
39            int flag = false;
40            MPI_Message message;
41
42            while(!flag)
43            {
44                Message_Check(request->comm);
45#pragma omp flush
46                MPI_Improbe(request->ep_src, request->ep_tag, request->comm, &flag, &message, status);
47            }
48
49            int count;
50            MPI_Get_count(status, request->ep_datatype, &count);
51            MPI_Mrecv(request->buf, count, request->ep_datatype, &message, status);
52            status->ep_datatype = request->ep_datatype;
53
54            //check_sum_recv(request->buf, count, request->ep_datatype, request->ep_src, request->ep_tag, request->comm, 2);
55
56            return 0;
57        }
58
59        if(request->type == 3)
60        {
61            ::MPI_Request mpi_request = static_cast< ::MPI_Request >(request->mpi_request);
62            ::MPI_Status mpi_status;
63            ::MPI_Wait(&mpi_request, &mpi_status);
64
65            status->mpi_status = new ::MPI_Status(mpi_status);
66            status->ep_src = request->ep_src;
67            status->ep_tag = request->ep_tag;
68            status->ep_datatype = request->ep_datatype;
69
70            //int count;
71            //MPI_Get_count(status, request->ep_datatype, &count);
72            //check_sum_recv(request->buf, count, request->ep_datatype, request->ep_src, request->ep_tag, request->comm, 2);
73        }
74        return MPI_SUCCESS;
75    }
76
77
78
79
80
81
82    int MPI_Waitall(int count, MPI_Request *array_of_requests, MPI_Status *array_of_statuses)
83    {
84        int dest_rank;
85        MPI_Comm_rank(MPI_COMM_WORLD, &dest_rank);
86
87        int finished = 0;
88        int finished_index[count];
89
90        for(int i=0; i<count; i++)
91        {
92            finished_index[i] = false;
93        }
94
95        while(finished < count)
96        {
97            for(int i=0; i<count; i++)
98            {
99                //MPI_Test(&array_of_requests[i], &finished_index[i], &array_of_statuses[i]);
100                if(finished_index[i] == false) // this request has not been tested.
101                {
102                    if(array_of_requests[i].type != 2) // isend or imrecv
103                    {     
104                        MPI_Wait(&array_of_requests[i], &array_of_statuses[i]);
105                        finished++;
106                        finished_index[i] = true;
107                    }
108                    else // irecv
109                    {
110                        int flag = false;
111                        MPI_Message message;
112
113                        MPI_Improbe(array_of_requests[i].ep_src, array_of_requests[i].ep_tag, array_of_requests[i].comm, &flag, &message, &array_of_statuses[i]);
114
115                        if(flag)
116                        {
117                            //printf("dest_rank = %d, Waiting one message with src = %d, tag = %d, buf = %p\n", dest_rank, array_of_requests[i].ep_src, array_of_requests[i].ep_tag, array_of_requests[i].buf);
118                            int recv_count;
119                            MPI_Get_count(&array_of_statuses[i], array_of_requests[i].ep_datatype, &recv_count);
120                            MPI_Mrecv(array_of_requests[i].buf, recv_count, array_of_requests[i].ep_datatype, &message, &array_of_statuses[i]);
121                            //check_sum_recv(array_of_requests[i].buf, recv_count, array_of_requests[i].ep_datatype, array_of_requests[i].ep_src, array_of_requests[i].ep_tag, array_of_requests[i].comm, 2);
122
123                            finished++;
124                            finished_index[i] = true;
125                        }
126                    }
127                }
128            }   
129        }
130        return MPI_SUCCESS;
131    }
132
133
134
135
136
137}
Note: See TracBrowser for help on using the repository browser.