source: XIOS/trunk/src/transformation/domain_algorithm_generate_rectilinear.cpp @ 687

Last change on this file since 687 was 687, checked in by mhnguyen, 9 years ago

Implementing auto-generate rectilinear domain

+) Add a new special transformation to generate (complete) rectilinear domain

Test
+) On Curie
+) test_new_feature passed

File size: 3.2 KB
Line 
1/*!
2   \file domain_algorithm_generate_rectilinear.cpp
3   \author Ha NGUYEN
4   \since 31 Aug 2015
5   \date 31 Aug 2015
6
7   \brief Algorithm for automatic generation of rectilinear domain.
8 */
9#include "domain_algorithm_generate_rectilinear.hpp"
10#include "grid.hpp"
11#include "domain.hpp"
12#include "context.hpp"
13#include "context_client.hpp"
14#include "generate_rectilinear_domain.hpp"
15
16namespace xios {
17
18CDomainAlgorithmGenerateRectilinear::CDomainAlgorithmGenerateRectilinear(CDomain* domainDestination, CDomain* domainSource,
19                                                                         CGrid* gridSource, CGenerateRectilinearDomain* genRectDomain)
20: CDomainAlgorithmTransformation(domainDestination, domainSource), gridSrc_(gridSource), nbDomainDistributedPart_(0)
21{
22  genRectDomain->checkValid(domainSource);
23  computeDistributionGridSource();
24  fillInAttributesDomainDestination();
25}
26
27/*!
28  Compute the index mapping between domain on grid source and one on grid destination
29*/
30void CDomainAlgorithmGenerateRectilinear::computeIndexSourceMapping()
31{
32 /* Nothing to do */
33}
34
35/*!
36  Calculate the number of distributed parts on domain source
37*/
38void CDomainAlgorithmGenerateRectilinear::computeDistributionGridSource()
39{
40  CContext* context = CContext::getCurrent();
41  CContextClient* client = context->client;
42
43  std::vector<CDomain*> domListSrcP = gridSrc_->getDomains();
44  std::vector<CAxis*> axisListSrcP = gridSrc_->getAxis();
45
46  for (int i = 0; i < domListSrcP.size(); ++i) // support we have only domain, more than one, for now, dont know how to process
47  {
48    // First, find (roundly) distribution of associated axis (if any)
49    if (axisListSrcP.empty()) nbDomainDistributedPart_ = client->clientSize;
50    else
51    {
52      gridSrc_->solveAxisRef(false);
53      int nbAxis = axisListSrcP.size();
54      std::vector<int> nbLocalAxis(nbAxis, 0);
55      for (int j = 0; j < nbAxis; ++j)
56      {
57        std::vector<int> globalAxisIndex(axisListSrcP[j]->n);
58        for (int idx = 0; idx < axisListSrcP[j]->n; ++idx)
59          globalAxisIndex[idx] = axisListSrcP[j]->begin + idx;
60        HashXIOS<int> hashFunc;
61        StdSize hashValue = hashFunc.hashVec(globalAxisIndex);
62        std::vector<StdSize> recvBuff(client->clientSize);
63        MPI_Gather(&hashValue, 1, MPI_UNSIGNED_LONG,
64                   &recvBuff[0], 1, MPI_UNSIGNED_LONG,
65                   0,
66                   client->intraComm);
67        if (0 == client->clientRank)
68        {
69          std::set<StdSize> setTmp;
70          for (int k = 0; k < recvBuff.size(); ++k)
71          {
72            if (setTmp.end() == setTmp.find(recvBuff[k]))
73            {
74              ++nbLocalAxis[j];
75              setTmp.insert(recvBuff[k]);
76            }
77          }
78        }
79
80        MPI_Bcast(&nbLocalAxis[0], nbAxis, MPI_INT,
81                  0, client->intraComm);
82      }
83
84      int nbAxisDistributedPart = 1;
85      for (int j = 0; j < nbAxis; ++j) nbAxisDistributedPart *= nbLocalAxis[j];
86      nbDomainDistributedPart_ = client->clientSize/nbAxisDistributedPart;
87    }
88  }
89}
90
91/*!
92  Fill in all necessary attributes of domain destination and their values
93*/
94void CDomainAlgorithmGenerateRectilinear::fillInAttributesDomainDestination()
95{
96  domainDest_->redistribute(nbDomainDistributedPart_);
97}
98
99}
Note: See TracBrowser for help on using the repository browser.