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
Line 
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"
11#include "ep_mpi.hpp"
12
13using namespace std;
14
15
16namespace ep_lib {
17
18  int MPI_Test(MPI_Request *request, int *flag, MPI_Status *status)
19  {
20    Debug("MPI_Test with EP");
21   
22    if(*request==0) return *flag=true;
23   
24    if((*request)->type !=1 && (*request)->type !=2 && (*request)->type !=3) 
25    {
26      printf("MPI_Test : Error in request type\n");
27 
28      exit(1);
29    }
30
31    if((*request)->type == 2)   // irecv message not probed
32    {
33      *flag = false;
34      return Request_Check();
35    }
36   
37    else //(*request)->type == 1 || (*request)->type == 3      // isend or imrecv
38    {
39     
40      ::MPI_Status mpi_status;
41     
42     
43      ::MPI_Test(to_mpi_request_ptr(*request), flag, &mpi_status);
44     
45      if(*flag) 
46      {
47
48        status->mpi_status=new ::MPI_Status(mpi_status);
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;
54               
55        memcheck("delete "<< (*request)->mpi_request << " : in ep_lib::MPI_Test, delete (*request)->mpi_request");
56        delete (*request)->mpi_request;
57        delete *request;
58        *request=0;
59      }
60    }
61   
62    return Request_Check();
63
64  }
65
66
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");
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   
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++)
88    {
89      mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request);
90    }
91
92    ::MPI_Testall(count, mpi_request, flag, mpi_status);
93
94    if(*flag)
95    {
96      for(int i=0; i<count; i++)
97      {
98        array_of_statuses[i].mpi_status = new ::MPI_Status(mpi_status[i]);
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     
105        memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Testall, array_of_requests["<<i<<"]->mpi_request");
106        delete array_of_requests[i]->mpi_request;
107        delete array_of_requests[i];
108        array_of_requests[i]=0;
109       
110      }
111     
112    }
113   
114    return Request_Check();
115
116  }
117
118
119}
120
Note: See TracBrowser for help on using the repository browser.