source: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_test.cpp @ 1533

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

save dev

File size: 2.9 KB
RevLine 
[1134]1/*!
2   \file ep_test.cpp
3   \since 2 may 2016
4
5   \brief Definitions of MPI test function: MPI_Test, MPI_Testsome, MPI_Testany, MPI_Testall
6 */
7
8#include "ep_lib.hpp"
9#include <mpi.h>
10#include "ep_declaration.hpp"
[1533]11#include "ep_mpi.hpp"
[1134]12
13using namespace std;
14
15
16namespace ep_lib {
17
[1149]18  int MPI_Test(MPI_Request *request, int *flag, MPI_Status *status)
19  {
20    Debug("MPI_Test with EP");
[1185]21   
[1533]22    if(*request==0) return *flag=true;
23   
24    if((*request)->type !=1 && (*request)->type !=2 && (*request)->type !=3) 
[1134]25    {
[1533]26      printf("MPI_Test : Error in request type\n");
27 
28      exit(1);
[1134]29    }
30
[1520]31    if((*request)->type == 2)   // irecv message not probed
[1134]32    {
[1533]33      *flag = false;
34      return Request_Check();
[1134]35    }
[1533]36   
37    else //(*request)->type == 1 || (*request)->type == 3      // isend or imrecv
[1134]38    {
[1533]39     
[1134]40      ::MPI_Status mpi_status;
[1149]41     
42     
[1533]43      ::MPI_Test(to_mpi_request_ptr(*request), flag, &mpi_status);
[1149]44     
[1533]45      if(*flag) 
[1134]46      {
[1533]47
48        status->mpi_status=new ::MPI_Status(mpi_status);
[1520]49        status->ep_src = (*request)->ep_src;
50        status->ep_tag = (*request)->ep_tag;
51        status->ep_datatype = (*request)->ep_datatype;
52       
53        (*request)->state = 2;
[1533]54               
55        memcheck("delete "<< (*request)->mpi_request << " : in ep_lib::MPI_Test, delete (*request)->mpi_request");
[1520]56        delete (*request)->mpi_request;
57        delete *request;
[1533]58        *request=0;
59      }
[1134]60    }
[1533]61   
62    return Request_Check();
[1295]63
[1149]64  }
[1134]65
66
[1149]67  int MPI_Testall(int count, MPI_Request *array_of_requests, int *flag, MPI_Status *array_of_statuses)
68  {
69    Debug("MPI_Testall with EP");
[1533]70    *flag = false;
71   
72    int rank = array_of_requests[0]->comm->ep_comm_ptr->size_rank_info[0].first;
73   
74    for(int i=0; i<count; i++)
75    {
76      if(array_of_requests[i]->type == 2)
77      {
78        *flag=false;
79        return Request_Check();
80      }
81    }
82   
[1520]83    ::MPI_Request* mpi_request = new ::MPI_Request[count];
84    ::MPI_Status* mpi_status = new ::MPI_Status[count];
85
86
87    for(int i=0; i<count; i++)
[1134]88    {
[1520]89      mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request);
[1134]90    }
[1520]91
92    ::MPI_Testall(count, mpi_request, flag, mpi_status);
93
94    if(*flag)
95    {
96      for(int i=0; i<count; i++)
97      {
[1533]98        array_of_statuses[i].mpi_status = new ::MPI_Status(mpi_status[i]);
[1520]99        array_of_statuses[i].ep_src = array_of_requests[i]->ep_src;
100        array_of_statuses[i].ep_tag = array_of_requests[i]->ep_tag;
101        array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype;
102       
103        array_of_requests[i]->state = 2;
104     
[1533]105        memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Testall, array_of_requests["<<i<<"]->mpi_request");
[1520]106        delete array_of_requests[i]->mpi_request;
[1533]107        delete array_of_requests[i];
108        array_of_requests[i]=0;
109       
[1520]110      }
111     
112    }
[1533]113   
114    return Request_Check();
[1520]115
[1149]116  }
[1134]117
118
119}
[1520]120
Note: See TracBrowser for help on using the repository browser.