source: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_wait.cpp @ 1359

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

EP update all

File size: 2.3 KB
RevLine 
[1134]1/*!
[1138]2  \file ep_wait.cpp
3  \since 2 may 2016
[1134]4
[1138]5  \brief Definitions of MPI wait function: MPI_Wait, MPI_Waitall, MPI_Waitsome, MPI_Waitany
6  */
[1134]7
8#include "ep_lib.hpp"
9#include <mpi.h>
10#include "ep_declaration.hpp"
11
12using namespace std;
13
[1196]14extern std::list< ep_lib::MPI_Request* > * EP_PendingRequests;
15#pragma omp threadprivate(EP_PendingRequests)
[1134]16
17
[1196]18
[1147]19namespace ep_lib
[1295]20{
[1196]21 
[1147]22  int MPI_Wait(MPI_Request *request, MPI_Status *status)
23  {
[1196]24    if(request->type !=1 && request->type !=2 && request->type !=3) 
[1134]25    {
[1196]26      printf("Error in request type\n");
27 
28      exit(1);
[1147]29    }
[1134]30
[1196]31    while(request->type == 2) Request_Check();
[1134]32
33
[1295]34    //::MPI_Request mpi_request = static_cast< ::MPI_Request >(request->mpi_request);
[1196]35    ::MPI_Status mpi_status;
[1295]36    ::MPI_Wait(&(request->mpi_request), &mpi_status);
[1187]37     
[1295]38    // request->mpi_request = mpi_request;
[1187]39
[1196]40    status->mpi_status = &mpi_status;
41    status->ep_src = request->ep_src;
42    status->ep_tag = request->ep_tag;
43    status->ep_datatype = request->ep_datatype;
[1187]44
[1147]45    return MPI_SUCCESS;
[1138]46
[1147]47  }   /*end of mpi_wait*/
[1138]48
[1134]49
50
51
52
53
[1147]54  int MPI_Waitall(int count, MPI_Request *array_of_requests, MPI_Status *array_of_statuses)
55  {
[1196]56    std::vector<int> finished(count, 0);
[1134]57
[1196]58    ::MPI_Request* mpi_request = new ::MPI_Request[count];
59    ::MPI_Status* mpi_status = new ::MPI_Status[count];
[1147]60
[1196]61    while(std::accumulate(finished.begin(), finished.end(), 0) < count)
[1134]62    {
[1187]63     
[1147]64      for(int i=0; i<count; i++)
65      {
[1196]66        if(array_of_requests[i].type !=1 && array_of_requests[i].type !=2 && array_of_requests[i].type !=3) 
[1134]67        {
[1196]68          printf("Error in request type\n");
69 
70          exit(1);
71        }
72       
73        if(array_of_requests[i].type == 2) Request_Check(); 
74        if(array_of_requests[i].type != 2 && finished.at(i) == 0) 
75        {
76          finished.at(i) = 1;
77          mpi_request[i] = static_cast< ::MPI_Request >(array_of_requests[i].mpi_request);
78        }
79      }   
80    }
[1185]81
[1196]82    ::MPI_Waitall(count, mpi_request, mpi_status);
[1138]83
[1196]84    for(int i=0; i<count; i++)
85    {
86      array_of_statuses[i].mpi_status = &mpi_status;
87      array_of_statuses[i].ep_src = array_of_requests[i].ep_src;
88      array_of_statuses[i].ep_tag = array_of_requests[i].ep_tag;
89      array_of_statuses[i].ep_datatype = array_of_requests[i].ep_datatype;
90    }
[1147]91
[1196]92    delete[] mpi_request;
93    delete[] mpi_status;
[1295]94   
[1147]95    return MPI_SUCCESS;
96  }  /* end of mpi_waitall*/
[1134]97
98
99}
[1196]100
Note: See TracBrowser for help on using the repository browser.