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

Last change on this file since 1520 was 1520, checked in by yushan, 3 years ago

save dev. TO DO : test with xios

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