XIOS  1.0
Xml I/O Server
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Définitions de type Énumérations Valeurs énumérées Amis Macros
domain_algorithm_generate_rectilinear.cpp
Aller à la documentation de ce fichier.
1 
10 #include "grid.hpp"
11 #include "domain.hpp"
12 #include "context.hpp"
13 #include "context_client.hpp"
15 
16 namespace xios {
17 
18 CDomainAlgorithmGenerateRectilinear::CDomainAlgorithmGenerateRectilinear(CDomain* domainDestination, CDomain* domainSource,
19  CGrid* gridDest, CGrid* gridSource,
20  CGenerateRectilinearDomain* genRectDomain)
21 : CDomainAlgorithmTransformation(domainDestination, domainSource), nbDomainDistributedPart_(0)
22 TRY
23 {
25  genRectDomain->checkValid(domainDestination);
26  if (0 != gridSource) computeDistributionGridSource(gridSource);
27  else
28  {
29  computeDistributionGridDestination(gridDest);
30  }
32 }
33 CATCH
34 
39 {
40  /* Nothing to do */
41 }
42 
47 TRY
48 {
49  CContext* context = CContext::getCurrent();
50  CContextClient* client = context->client;
51 
52  std::vector<CDomain*> domListSrcP = gridSrc->getDomains();
53  std::vector<CAxis*> axisListSrcP = gridSrc->getAxis();
54 
55  for (int i = 0; i < domListSrcP.size(); ++i) // support we have only domain, more than one, for now, dont know how to process
56  {
57  // First, find (roundly) distribution of associated axis (if any)
58  if (axisListSrcP.empty()) nbDomainDistributedPart_ = client->clientSize;
59  else
60  {
61  gridSrc->solveAxisRef(false);
62  int nbAxis = axisListSrcP.size();
63  std::vector<int> nbLocalAxis(nbAxis, 0);
64  for (int j = 0; j < nbAxis; ++j)
65  {
66  std::vector<int> globalAxisIndex(axisListSrcP[j]->n);
67  for (int idx = 0; idx < axisListSrcP[j]->n; ++idx)
68  globalAxisIndex[idx] = axisListSrcP[j]->begin + idx;
69  HashXIOS<int> hashFunc;
70  StdSize hashValue = hashFunc.hashVec(globalAxisIndex);
71  std::vector<StdSize> recvBuff(client->clientSize);
72  MPI_Gather(&hashValue, 1, MPI_UNSIGNED_LONG,
73  &recvBuff[0], 1, MPI_UNSIGNED_LONG,
74  0,
75  client->intraComm);
76  if (0 == client->clientRank)
77  {
78  std::set<StdSize> setTmp;
79  for (int k = 0; k < recvBuff.size(); ++k)
80  {
81  if (setTmp.end() == setTmp.find(recvBuff[k]))
82  {
83  ++nbLocalAxis[j];
84  setTmp.insert(recvBuff[k]);
85  }
86  }
87  }
88 
89  MPI_Bcast(&nbLocalAxis[0], nbAxis, MPI_INT,
90  0, client->intraComm);
91  }
92 
93  int nbAxisDistributedPart = 1;
94  for (int j = 0; j < nbAxis; ++j) nbAxisDistributedPart *= nbLocalAxis[j];
95  nbDomainDistributedPart_ = client->clientSize/nbAxisDistributedPart;
96  }
97  }
98 }
99 CATCH
100 
104 void CDomainAlgorithmGenerateRectilinear::computeDistributionGridDestination(CGrid* gridDest)
105 TRY
106 {
107  // For now, just suppose that the grid contains only one domain
108  std::vector<CAxis*> axisListDestP = gridDest->getAxis();
109  int nbPartition = 1, idx = 0;
110  for (int i = 0; i < gridDest->axis_domain_order.numElements(); ++i)
111  {
112  if (false == (gridDest->axis_domain_order)(i))
113  {
114  nbPartition *= (axisListDestP[idx]->n_distributed_partition.isEmpty()) ? 1: (axisListDestP[idx]->n_distributed_partition.getValue());
115  ++idx;
116  }
117  }
118 
119  CContext* context = CContext::getCurrent();
120  CContextClient* client = context->client;
121  int modPart = (client->clientSize) % nbPartition;
122  if (0 != modPart)
123  ERROR("CDomainAlgorithmGenerateRectilinear::computeDistributionGridDestination(CGrid* gridDest)",
124  << "The grid " <<gridDest->getId() << " is not well-distributed. There is an incompatibility between distribution of axis and domain.");
125  nbDomainDistributedPart_ = client->clientSize/nbPartition;
126 
127 }
128 CATCH
129 
134 TRY
135 {
136  if (!domainDest_->distributionAttributesHaveValue())
137  domainDest_->redistribute(nbDomainDistributedPart_);
138  domainDest_->fillInLonLat();
139 }
140 CATCH
141 }
fillInAttributesDomainDestination()
MPI_Comm intraComm
Communicator of client group.
void computeDistributionGridSource(CGrid *gridSrc)
Calculate the number of distributed parts on domain source.
std::size_t hashVec(const std::vector< T > &vec)
Definition: utils.hpp:198
#define TRY
Definition: exception.hpp:154
int clientSize
Size of client group.
#define xios(arg)
CDomainAlgorithmGenerateRectilinear(CDomain *domainDestination, CDomain *domainSource, CGrid *gridDest, CGrid *gridSource, CGenerateRectilinearDomain *zoomDomain)
void computeIndexSourceMapping_(const std::vector< CArray< double, 1 > * > &dataAuxInputs)
Compute the index mapping between domain on grid source and one on grid destination.
A context can be both on client and on server side.
std::size_t StdSize
Definition: xios_spl.hpp:49
Algorithm for automatic generation of rectilinear domain.
int clientRank
Rank of current client.
#define ERROR(id, x)
Definition: exception.hpp:73
#define CATCH
Definition: exception.hpp:155
static CContext * getCurrent(void)
Get current context.
Definition: context.cpp:2018
CContextClient * client
Concrete contex client.
Definition: context.hpp:251