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

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

branch merged with trunk @1645. arch file (ep&mpi) added for ADA

File size: 4.9 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)
141    {
142      return true;
143    }
144
145    return false;
146  }
147
148
149  bool valid_op(MPI_Op op)
150  {
151    if(   op == MPI_MAX
152       || op == MPI_MIN
153       || op == MPI_SUM
154       || op == MPI_LOR)
155    {
156      return true;
157    }
158
159    return false;
160  }
161
162
163}
164
165
166MPI_Datatype to_mpi_type(ep_lib::MPI_Datatype type)
167{
168  return *static_cast< MPI_Datatype* >(type);
169}
170
171MPI_Op to_mpi_op(ep_lib::MPI_Op op)
172{
173  return *static_cast< MPI_Op* >(op);
174}
175
176MPI_Comm to_mpi_comm(void* comm)
177{
178  return *(static_cast< MPI_Comm* >(comm));
179} 
180
181MPI_Comm* to_mpi_comm_ptr(void* comm)
182{
183  return static_cast< MPI_Comm* >(comm);
184} 
185
186MPI_Message to_mpi_message(void* message)
187{
188  return *(static_cast< MPI_Message* >(message));
189}
190
191MPI_Message* to_mpi_message_ptr(ep_lib::MPI_Message message)
192{
193  return static_cast< MPI_Message* >(message->mpi_message);
194}
195
196MPI_Info to_mpi_info(ep_lib::MPI_Info info)
197{
198  return *(static_cast< MPI_Info* >(info->mpi_info));
199}
200
201MPI_Win to_mpi_win(void* win)
202{
203  return *(static_cast< MPI_Win* >(win));
204}
205
206MPI_Aint to_mpi_aint(ep_lib::MPI_Aint aint)
207{
208  return *(static_cast< MPI_Aint* >(aint.mpi_aint));
209}
210
211MPI_Status* to_mpi_status_ptr(ep_lib::MPI_Status status)
212{
213  return static_cast< MPI_Status* >(status.mpi_status);
214}
215
216MPI_Request* to_mpi_request_ptr(ep_lib::MPI_Request request)
217{
218  return static_cast< MPI_Request* >(request->mpi_request);
219}
220
221#endif
222
Note: See TracBrowser for help on using the repository browser.