source: XIOS/dev/dev_trunk_omp/src/policy.cpp @ 1661

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

MARK: branch merged with trunk @1660. Test (test_complete, test_remap) on ADA with IntelMPI and _usingEP/_usingMPI as switch.

File size: 2.8 KB
Line 
1/*!
2   \file policy.cpp
3   \author Ha NGUYEN
4   \since 06 Oct 2015
5   \date 06 Oct 2015
6
7   \brief Some useful policies for templated classes
8 */
9
10#include "policy.hpp"
11#include <cmath>
12#ifdef _usingEP
13using namespace ep_lib;
14#endif
15
16namespace xios
17{
18
19
20DivideAdaptiveComm::DivideAdaptiveComm(const MPI_Comm& mpiComm)
21  : internalComm_(mpiComm), level_(0), groupBegin_(), nbInGroup_(), computed_(false)
22{
23
24}
25
26void DivideAdaptiveComm::computeMPICommLevel()
27{
28  if (computed_) return;
29  computed_ = true;
30
31  int mpiSize, mpiRank;
32  MPI_Comm_size(internalComm_,&mpiSize);
33  MPI_Comm_rank(internalComm_,&mpiRank);
34
35  int maxChild=1;
36  int m;
37  do
38  {
39    m=1;
40    ++maxChild;
41    for(int i=0;i<maxChild;++i) m *= maxChild;
42   } while(m<mpiSize);
43
44  int maxLevel=0;
45  for(int size=1; size<=mpiSize; size*=maxChild) ++maxLevel;
46
47  int pos, n, idx;
48  level_=0;
49  int begin=0;
50  int end=mpiSize-1;
51  int nb=end-begin+1;
52
53  nbInGroup_ = groupBegin_= std::vector<int>(maxLevel);
54  nbInGroupParents_ = groupParentsBegin_= std::vector<std::vector<int> >(maxLevel,std::vector<int>(maxChild));
55
56  groupBegin_[level_] = begin;
57  nbInGroup_[level_] = nb;
58  ++level_;
59  while (nb>2 && (level_<maxLevel))
60  {
61    n = 0; idx = 0;
62    pos = begin;
63    for(int i=0;i<maxChild && i<nb;i++)
64    {
65      if (i<nb%maxChild) n = nb/maxChild + 1;
66      else n = nb/maxChild;
67
68      if (mpiRank>=pos && mpiRank<pos+n)
69      {
70        begin=pos;
71        end=pos+n-1;
72      }
73      groupParentsBegin_[level_-1][idx] = pos;
74      nbInGroupParents_[level_-1][idx] = n;
75      ++idx;
76      pos=pos+n;
77    }
78    groupBegin_[level_] = begin;
79    nbInGroup_[level_] = nb = end-begin+1;
80
81    ++level_;
82  }
83
84  for (int i = 0; i < nbInGroup_[level_-1];++i)
85  {
86    groupParentsBegin_[level_-1][i] = groupBegin_[level_-1]+i;
87    nbInGroupParents_[level_-1][i] = 1;
88  }
89
90
91
92//  parent=vector<int>(maxLevel+1);
93//  child=vector<vector<int> >(maxLevel+1,vector<int>(maxChild));
94//  nbChild=vector<int> (maxLevel+1);
95
96//  do
97//  {
98//    n=0;
99//    pos=begin;
100//    nbChild[level_]=0;
101//    parent[level_+1]=begin;
102//    for(int i=0;i<maxChild && i<nb;i++)
103//    {
104//      if (i<nb%maxChild) n = nb/maxChild + 1;
105//      else n = nb/maxChild;
106//
107//      if (mpiRank>=pos && mpiRank<pos+n)
108//      {
109//        begin=pos;
110//        end=pos+n-1;
111//      }
112//      child[level_][i]=pos;
113//      pos=pos+n;
114//      nbChild[level_]++;
115//    }
116//    nb=end-begin+1;
117//    level_=level_+1;
118//  } while (nb>1);
119}
120
121//void DivideAdaptiveComm::divideMPICommLevel(const MPI_Comm& mpiCommLevel, int color, int level)
122//{
123////  int clientRank;
124////  MPI_Comm_rank(mpiCommLevel,&clientRank);
125//
126//   --level;
127//  if (0 < level)
128//  {
129//   int color = clientRank % 2;
130//   commLevel_.push_back(MPI_Comm());
131//   MPI_Comm_split(mpiCommLevel, color, 0, &(commLevel_.back()));
132//   divideMPICommLevel(commLevel_.back(), level);
133//  }
134//}
135
136
137}
138
Note: See TracBrowser for help on using the repository browser.