source: XIOS/dev/branch_openmp/extern/ep_dev/ep_wait.cpp @ 1512

Last change on this file since 1512 was 1503, checked in by yushan, 6 years ago

rank_map is passed from vector to map, in order to have more flexibility in comm_split

File size: 2.9 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#include "ep_mpi.hpp"
12
13using namespace std;
14
15extern std::list< ep_lib::MPI_Request* > * EP_PendingRequests;
16#pragma omp threadprivate(EP_PendingRequests)
17
18
19
20namespace ep_lib
21{
22 
23  int MPI_Wait(MPI_Request *request, MPI_Status *status)
24  {
25    if((*request)->type !=1 && (*request)->type !=2 && (*request)->type !=3) 
26    {
27      printf("Error in request type\n");
28 
29      exit(1);
30    }
31
32    while((*request)->type == 2) Request_Check();
33   
34    ::MPI_Wait(to_mpi_request_ptr(*request), to_mpi_status_ptr(status));
35
36   
37    status->ep_src = (*request)->ep_src;
38    status->ep_tag = (*request)->ep_tag;
39    status->ep_datatype = (*request)->ep_datatype;
40   
41    (*request)->state = 2;
42
43    memcheck("delete "<< (*request)->mpi_request << " : in ep_lib::MPI_Wait, delete (*request)->mpi_request");
44    delete (*request)->mpi_request;
45    Request_Check();
46
47    return MPI_SUCCESS;
48
49  }   /*end of mpi_wait*/
50
51
52
53
54
55
56  int MPI_Waitall(int count, MPI_Request *array_of_requests, MPI_Status *array_of_statuses)
57  {
58    std::vector<int> finished(count, 0);
59
60    ::MPI_Request* mpi_request = new ::MPI_Request[count];
61    ::MPI_Status* mpi_status = new ::MPI_Status[count];
62
63    while(std::accumulate(finished.begin(), finished.end(), 0) < count)
64    {
65     
66      for(int i=0; i<count; i++)
67      {
68        if(array_of_requests[i]->type !=1 && array_of_requests[i]->type !=2 && array_of_requests[i]->type !=3) 
69        {
70          printf("Error in request type\n");
71 
72          exit(1);
73        }
74       
75        if(array_of_requests[i]->type == 2) Request_Check(); 
76        if(array_of_requests[i]->type != 2 && finished.at(i) == 0) 
77        {
78          finished.at(i) = 1;
79          mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request);
80        }
81      }   
82    }
83
84    ::MPI_Waitall(count, mpi_request, mpi_status);
85
86    for(int i=0; i<count; i++)
87    {
88      array_of_statuses[i].mpi_status = &mpi_status[i];
89      array_of_statuses[i].ep_src = array_of_requests[i]->ep_src;
90      array_of_statuses[i].ep_tag = array_of_requests[i]->ep_tag;
91      array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype;
92      array_of_requests[i]->state = 2;
93      memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Waitall, array_of_requests["<<i<<"]->mpi_request");
94      delete array_of_requests[i]->mpi_request;
95      if(array_of_requests[i]->type == 1) 
96      {
97        memcheck("delete "<< array_of_requests[i] <<" : in ep_lib::MPI_Waitall, array_of_requests["<<i<<"]");
98        delete array_of_requests[i];
99      }
100    }
101
102    delete[] mpi_request;
103    delete[] mpi_status;
104   
105    Request_Check();
106   
107   
108    return MPI_SUCCESS;
109  }  /* end of mpi_waitall*/
110
111
112}
113
Note: See TracBrowser for help on using the repository browser.