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

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

save dev

File size: 2.8 KB
RevLine 
[1381]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"
[1522]11#include "ep_mpi.hpp"
[1381]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   
[1522]22    if(*request==0) return *flag=true;
23   
24    if((*request)->type !=1 && (*request)->type !=2 && (*request)->type !=3) 
[1381]25    {
[1522]26      printf("MPI_Test : Error in request type\n");
27      exit(1);
[1381]28    }
29
[1500]30    if((*request)->type == 2)   // irecv message not probed
[1381]31    {
[1522]32      *flag = false;
33      return Request_Check();
[1381]34    }
[1522]35   
36    else //(*request)->type == 1 || (*request)->type == 3      // isend or imrecv
[1381]37    {
[1522]38     
[1381]39      ::MPI_Status mpi_status;
[1522]40      ::MPI_Test(to_mpi_request_ptr(*request), flag, &mpi_status);
[1381]41     
[1522]42      if(*flag) 
[1381]43      {
[1522]44
45        status->mpi_status=new ::MPI_Status(mpi_status);
[1500]46        status->ep_src = (*request)->ep_src;
47        status->ep_tag = (*request)->ep_tag;
48        status->ep_datatype = (*request)->ep_datatype;
[1522]49       
[1527]50        //(*request)->state = 2;
[1522]51               
52        memcheck("delete "<< (*request)->mpi_request << " : in ep_lib::MPI_Test, delete (*request)->mpi_request");
[1520]53        delete (*request)->mpi_request;
[1522]54        delete *request;
55        *request=0;
56      }
[1381]57    }
[1522]58   
59    return Request_Check();
[1381]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");
[1522]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   
[1520]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++)
[1381]84    {
[1520]85      mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request);
[1381]86    }
[1500]87
[1520]88    ::MPI_Testall(count, mpi_request, flag, mpi_status);
89
[1522]90    if(*flag)
[1520]91    {
92      for(int i=0; i<count; i++)
93      {
[1522]94        array_of_statuses[i].mpi_status = new ::MPI_Status(mpi_status[i]);
[1520]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;
[1522]98       
[1527]99        //array_of_requests[i]->state = 2;
[1520]100     
[1522]101        memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Testall, array_of_requests["<<i<<"]->mpi_request");
[1520]102        delete array_of_requests[i]->mpi_request;
[1522]103        delete array_of_requests[i];
104        array_of_requests[i]=0;
105       
[1520]106      }
107    }
[1527]108
[1522]109    return Request_Check();
[1381]110  }
111
112
113}
[1520]114
Note: See TracBrowser for help on using the repository browser.