source: XIOS/dev/dev_trunk_omp/extern/src_ep_dev/ep_lib.cpp @ 1745

Last change on this file since 1745 was 1745, checked in by yushan, 5 years ago

Generic_testcase: build flag --omp to enable EP with intelmpi. --omp2 to enable EP with openmpi. tested on Irene with compiler=intel17, mpi=intelmpi&openmpi, with and without EP

File size: 5.1 KB
Line 
1#ifdef _usingEP
2#include "ep_lib.hpp"
3#include <mpi.h>
4#include "ep_declaration.hpp"
5#include <iostream>
6#include <fstream>
7#include "ep_mpi.hpp"
8
9using namespace std;
10
11std::list< ep_lib::MPI_Request* > * EP_PendingRequests = 0;
12#pragma omp threadprivate(EP_PendingRequests)
13
14
15std::map<std::pair<int, int>, MPI_Group* > * tag_group_map = 0;
16
17std::map<int, std::pair<ep_lib::MPI_Comm*, std::pair<int, int> > > * tag_comm_map = 0;
18
19
20MPI_Group MPI_GROUP_WORLD;
21
22namespace ep_lib
23{ 
24
25  int tag_combine(int real_tag, int src, int dest)
26  {
27    int a = real_tag << 16;
28    int b = src << 8;
29    int c = dest;
30
31    return a+b+c;
32  }
33
34  int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank)
35  {   
36    for(std::map<int, std::pair<int, int> >::iterator it = comm->ep_rank_map->begin(); it != comm->ep_rank_map->end(); it++)
37    {
38      if(   ( it->second.first  == ep_rank_loc )
39         && ( it->second.second == mpi_rank ) )
40      {
41        return it->first;
42      }
43    }
44    printf("rank not find for EP_intracomm\n");
45    return MPI_Abort(comm, 0);
46  }
47 
48
49  int MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype, int *count)
50  {
51    return ::MPI_Get_count(to_mpi_status_ptr(*status), to_mpi_type(datatype), count);
52  }
53
54  double MPI_Wtime()
55  {
56    return ::MPI_Wtime();
57  }
58
59  int MPI_Comm_test_inter(MPI_Comm comm, int *flag)
60  {
61    if(comm->is_ep) return *flag = comm->is_intercomm;
62    else return ::MPI_Comm_test_inter(to_mpi_comm(comm->mpi_comm), flag);
63  }
64
65  void check_sum_send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, int type)
66  {
67
68    int src_rank;
69    int int_count;
70    ::MPI_Aint datasize, intsize, charsize, lb;
71   
72    ::MPI_Type_get_extent(*(static_cast< ::MPI_Datatype*>(datatype)), &lb, &datasize);
73    ::MPI_Type_get_extent(*(static_cast< ::MPI_Datatype*>(MPI_CHAR)), &lb, &intsize);
74
75    int_count = count * datasize / intsize ;
76
77    char *buffer = static_cast< char* >(const_cast< void*> (buf));
78   
79    unsigned long sum = 0;
80    for(int i = 0; i<int_count; i++)
81      sum += *(buffer+i); 
82
83
84    MPI_Comm_rank(comm, &src_rank);
85   
86    ofstream myfile;
87    myfile.open ("send_log.txt", ios::app);
88    if (myfile.is_open())
89    {
90      myfile << "type = " << type << " src = "<< src_rank<< " dest = "<< dest <<" tag = "<< tag << "  count = "<< count << " sum = "<< sum << "\n";
91      myfile.close(); 
92    }
93    else printf("Unable to open file\n");
94
95  }
96
97
98  void check_sum_recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, int type)
99  {
100
101    int dest_rank;
102    int int_count;
103    ::MPI_Aint datasize, intsize, charsize, lb;
104   
105    ::MPI_Type_get_extent(*(static_cast< ::MPI_Datatype*>(datatype)), &lb, &datasize);
106    ::MPI_Type_get_extent(*(static_cast< ::MPI_Datatype*>(MPI_CHAR)), &lb, &intsize);
107
108    int_count = count * datasize / intsize ;
109
110    char *buffer = static_cast< char* >(buf);
111   
112    unsigned long sum = 0;
113    for(int i = 0; i<int_count; i++)
114      sum += *(buffer+i); 
115
116
117    MPI_Comm_rank(comm, &dest_rank);
118   
119    ofstream myfile;
120    myfile.open ("recv_log.txt", ios::app);
121    if (myfile.is_open())
122    {
123      myfile << "type = " << type << " src = "<< src << " dest = "<< dest_rank <<" tag = "<< tag << "  count = "<< count << " sum = "<< sum << "\n";
124      myfile.close(); 
125    }
126    else printf("Unable to open file\n");
127
128
129  }
130
131
132  bool valid_type(MPI_Datatype datatype)
133  {
134    if(   datatype == MPI_INT
135       || datatype == MPI_FLOAT
136       || datatype == MPI_DOUBLE
137       || datatype == MPI_CHAR
138       || datatype == MPI_LONG
139       || datatype == MPI_UNSIGNED_LONG
140       || datatype == MPI_LONG_LONG_INT)
141    {
142      return true;
143    }
144
145    //std::cout<<"datatype="<<datatype<<",int="<<MPI_INT<<",float="<<MPI_FLOAT<<",double="<<MPI_DOUBLE<<",char="<<MPI_CHAR<<",long="<<MPI_LONG<<",u_char="<<MPI_UNSIGNED_CHAR<<",l_long="<<MPI_LONG_LONG<<std::endl;
146    return false;
147  }
148
149
150  bool valid_op(MPI_Op op)
151  {
152    if(   op == MPI_MAX
153       || op == MPI_MIN
154       || op == MPI_SUM
155       || op == MPI_LOR)
156    {
157      return true;
158    }
159
160    return false;
161  }
162
163
164}
165
166
167MPI_Datatype to_mpi_type(ep_lib::MPI_Datatype type)
168{
169  return *static_cast< MPI_Datatype* >(type);
170}
171
172MPI_Op to_mpi_op(ep_lib::MPI_Op op)
173{
174  return *static_cast< MPI_Op* >(op);
175}
176
177MPI_Comm to_mpi_comm(void* comm)
178{
179  return *(static_cast< MPI_Comm* >(comm));
180} 
181
182MPI_Comm* to_mpi_comm_ptr(void* comm)
183{
184  return static_cast< MPI_Comm* >(comm);
185} 
186
187MPI_Message to_mpi_message(void* message)
188{
189  return *(static_cast< MPI_Message* >(message));
190}
191
192MPI_Message* to_mpi_message_ptr(ep_lib::MPI_Message message)
193{
194  return static_cast< MPI_Message* >(message->mpi_message);
195}
196
197MPI_Info to_mpi_info(ep_lib::MPI_Info info)
198{
199  return *(static_cast< MPI_Info* >(info->mpi_info));
200}
201
202MPI_Win to_mpi_win(void* win)
203{
204  return *(static_cast< MPI_Win* >(win));
205}
206
207MPI_Aint to_mpi_aint(ep_lib::MPI_Aint aint)
208{
209  return *(static_cast< MPI_Aint* >(aint.mpi_aint));
210}
211
212MPI_Status* to_mpi_status_ptr(ep_lib::MPI_Status status)
213{
214  return static_cast< MPI_Status* >(status.mpi_status);
215}
216
217MPI_Request* to_mpi_request_ptr(ep_lib::MPI_Request request)
218{
219  return static_cast< MPI_Request* >(request->mpi_request);
220}
221
222#endif
223
Note: See TracBrowser for help on using the repository browser.