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

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

tests in XIOS OK (client, complete, remap, toy)

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