source: XIOS/dev/branch_openmp/extern/ep_dev/ep_test.cpp @ 1532

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

save dev

File size: 2.8 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      exit(1);
28    }
29
30    if((*request)->type == 2)   // irecv message not probed
31    {
32      *flag = false;
33      return Request_Check();
34    }
35   
36    else //(*request)->type == 1 || (*request)->type == 3      // isend or imrecv
37    {
38     
39      ::MPI_Status mpi_status;
40      ::MPI_Test(to_mpi_request_ptr(*request), flag, &mpi_status);
41     
42      if(*flag) 
43      {
44
45        status->mpi_status=new ::MPI_Status(mpi_status);
46        status->ep_src = (*request)->ep_src;
47        status->ep_tag = (*request)->ep_tag;
48        status->ep_datatype = (*request)->ep_datatype;
49       
50        //(*request)->state = 2;
51               
52        memcheck("delete "<< (*request)->mpi_request << " : in ep_lib::MPI_Test, delete (*request)->mpi_request");
53        delete (*request)->mpi_request;
54        delete *request;
55        *request=0;
56      }
57    }
58   
59    return Request_Check();
60  }
61
62
63  int MPI_Testall(int count, MPI_Request *array_of_requests, int *flag, MPI_Status *array_of_statuses)
64  {
65    Debug("MPI_Testall with EP");
66    *flag = false;
67   
68    int rank = array_of_requests[0]->comm->ep_comm_ptr->size_rank_info[0].first;
69   
70    for(int i=0; i<count; i++)
71    {
72      if(array_of_requests[i]->type == 2)
73      {
74        *flag=false;
75        return Request_Check();
76      }
77    }
78   
79    ::MPI_Request* mpi_request = new ::MPI_Request[count];
80    ::MPI_Status* mpi_status = new ::MPI_Status[count];
81
82
83    for(int i=0; i<count; i++)
84    {
85      mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request);
86    }
87
88    ::MPI_Testall(count, mpi_request, flag, mpi_status);
89
90    if(*flag)
91    {
92      for(int i=0; i<count; i++)
93      {
94        array_of_statuses[i].mpi_status = new ::MPI_Status(mpi_status[i]);
95        array_of_statuses[i].ep_src = array_of_requests[i]->ep_src;
96        array_of_statuses[i].ep_tag = array_of_requests[i]->ep_tag;
97        array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype;
98       
99        //array_of_requests[i]->state = 2;
100     
101        memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Testall, array_of_requests["<<i<<"]->mpi_request");
102        delete array_of_requests[i]->mpi_request;
103        delete array_of_requests[i];
104        array_of_requests[i]=0;
105       
106      }
107    }
108
109    return Request_Check();
110  }
111
112
113}
114
Note: See TracBrowser for help on using the repository browser.