source: XIOS/trunk/src/node/domain.cpp @ 579

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

Correct some bugs on discovering server index and do some code cleanings

+) Add some checking functions to make sure mpi_isend and mpi_irecv work correctly
+) Add comments to code
+) Remove some redundant code and comments

Test
+) On Curie
+) The new functions are tested in test_new_features.f90. Test_client and test_complete work like before
+) Test cases:

  • 3 dimension grid with: 1 domain, 1 axis
  • 3 dimension grid with: 3 axis
  • Attached and connected

+) All pass and results are correct

TODO:
+) Fix zoom bug with grid composed of only one axis

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 31.6 KB
RevLine 
[219]1#include "domain.hpp"
2
[352]3#include "attribute_template.hpp"
4#include "object_template.hpp"
5#include "group_template.hpp"
[219]6
[300]7#include "xmlioserver_spl.hpp"
8#include "event_client.hpp"
9#include "event_server.hpp"
10#include "buffer_in.hpp"
[352]11#include "message.hpp"
12#include "type.hpp"
13#include "context.hpp"
14#include "context_client.hpp"
[369]15#include "array_new.hpp"
[553]16#include "server_distribution_description.hpp"
[569]17#include "client_server_mapping_distributed.hpp"
[274]18
[335]19namespace xios {
[509]20
[219]21   /// ////////////////////// Définitions ////////////////////// ///
22
23   CDomain::CDomain(void)
24      : CObjectTemplate<CDomain>(), CDomainAttributes()
[553]25      , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_()
[219]26   { /* Ne rien faire de plus */ }
27
28   CDomain::CDomain(const StdString & id)
29      : CObjectTemplate<CDomain>(id), CDomainAttributes()
[553]30      , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_()
[449]31         { /* Ne rien faire de plus */ }
[219]32
33   CDomain::~CDomain(void)
[509]34   {
[219]35   }
36
37   ///---------------------------------------------------------------
38
39   const std::set<StdString> & CDomain::getRelFiles(void) const
40   {
[509]41      return (this->relFiles);
[219]42   }
43
44   //----------------------------------------------------------------
[509]45
[219]46   bool CDomain::hasZoom(void) const
47   {
[509]48      return ((this->zoom_ni.getValue() != this->ni_glo.getValue()) &&
[219]49              (this->zoom_nj.getValue() != this->nj_glo.getValue()));
50   }
[509]51
[219]52   //----------------------------------------------------------------
[509]53
[219]54   bool CDomain::isEmpty(void) const
55   {
[509]56      return ((this->zoom_ni_srv == 0) ||
[300]57              (this->zoom_nj_srv == 0));
[219]58   }
59
60   //----------------------------------------------------------------
61
62   bool CDomain::IsWritten(const StdString & filename) const
63   {
64      return (this->relFiles.find(filename) != this->relFiles.end());
65   }
66
67   //----------------------------------------------------------------
68
69   void CDomain::addRelFile(const StdString & filename)
70   {
71      this->relFiles.insert(filename);
72   }
73
74
75   StdString CDomain::GetName(void)   { return (StdString("domain")); }
76   StdString CDomain::GetDefName(void){ return (CDomain::GetName()); }
77   ENodeType CDomain::GetType(void)   { return (eDomain); }
78
79   //----------------------------------------------------------------
80
[467]81   void CDomain::checkDomain(void)
[219]82   {
[449]83      if (!type.isEmpty() && type==type_attr::unstructured)
84      {
85         if (ni_glo.isEmpty() || ni_glo <= 0 )
86         {
87            ERROR("CDomain::checkAttributes(void)",
88               << "[ Id = " << this->getId() << " ] "
89               << "The global domain is badly defined,"
[509]90               << " check the \'ni_glo\'  value !")
[449]91         }
92         nj_glo=ni_glo ;
93         ni_glo=1 ;
94         if (!ni.isEmpty()) nj=ni ;
95         if (!ibegin.isEmpty()) jbegin=ibegin ;
96         if (!iend.isEmpty()) jend=iend ;
[467]97         if (!i_index.isEmpty())
98         {
99          j_index.resize(1,nj) ;
100          for(int i=0;i<ni;i++) j_index(0,i)=i_index(i,0) ;
101          i_index.resize(1,nj) ;
102          for(int j=0;j<nj;j++) i_index(0,j)=0 ;
103         }
104
105         if (!mask.isEmpty())
106         {
107          CArray<int,2> mask_tmp(nj,1) ;
108          mask_tmp = mask ;
109          mask.resize(1,nj) ;
110          for(int j=0;j<nj;j++) mask(0,j)=mask_tmp(j,0) ;
111         }
[449]112         ni=1 ;
[551]113         ibegin=0 ;
114         iend=0 ;
[509]115
[449]116      }
117      else if ((ni_glo.isEmpty() || ni_glo.getValue() <= 0 ) ||
[274]118          (nj_glo.isEmpty() || nj_glo.getValue() <= 0 ))
119      {
[219]120         ERROR("CDomain::checkAttributes(void)",
121               << "[ Id = " << this->getId() << " ] "
[421]122               << "The global domain is badly defined,"
[509]123               << " check the \'ni_glo\' et \'nj_glo\' values !")
[274]124      }
[467]125      checkLocalIDomain() ;
126      checkLocalJDomain() ;
[509]127
[467]128     if (i_index.isEmpty())
129     {
130       i_index.resize(ni,nj) ;
131       for(int j=0;j<nj;j++)
[509]132         for(int i=0;i<ni;i++) i_index(i,j)=i ;
[467]133     }
[509]134
[467]135     if (j_index.isEmpty())
136     {
137        j_index.resize(ni,nj) ;
138        for(int j=0;j<nj;j++)
[509]139         for(int i=0;i<ni;i++) j_index(i,j)=j ;
[467]140     }
[509]141
[219]142   }
143
144   //----------------------------------------------------------------
145
146   void CDomain::checkLocalIDomain(void)
147   {
148      if (!ni.isEmpty() && !ibegin.isEmpty() && iend.isEmpty())
149         iend.setValue(ibegin.getValue() + ni.getValue() - 1) ;
150
151      else if (!ni.isEmpty() && !iend.isEmpty()   && ibegin.isEmpty())
152         ibegin.setValue( - ni.getValue() + iend.getValue() + 1) ;
153
154      else if (!ibegin.isEmpty() && !iend.isEmpty() && ni.isEmpty())
155         ni.setValue(iend.getValue() - ibegin.getValue() + 1) ;
156
[449]157      else if (!ibegin.isEmpty() && !iend.isEmpty() && !ni.isEmpty() )
[219]158      {
[449]159         if (iend.getValue() != ibegin.getValue() + ni.getValue() - 1)
160           ERROR("CDomain::checkAttributes(void)",
161                 << "The domain si wrong defined,"
162                 << " iend is different of (ibegin + ni - 1) !") ;
[219]163      }
164      else
165      {
166         ERROR("CDomain::checkAttributes(void)",
[421]167               << "The domain is wrong defined,"
168               << " 2 value from \'iend\', \'ibegin\', \'ni\'  must be defined !") ;
[219]169      }
170
171
172      if (ni.getValue() < 0 || ibegin.getValue() > iend.getValue() ||
[551]173          ibegin.getValue() < 0 || iend.getValue() > (ni_glo.getValue()-1))
[449]174          {
175
[219]176         ERROR("CDomain::checkAttributes(void)",
177               << "[ Id = " << this->getId() << " ] "
[421]178               << "Local domain is wrong defined,"
179               << " Check the value : ni, ni_glo, ibegin, iend") ;
[449]180        }
[219]181   }
182
183   //----------------------------------------------------------------
184
185   void CDomain::checkLocalJDomain(void)
186   {
187      if (!nj.isEmpty() && !jbegin.isEmpty() && jend.isEmpty())
188         jend.setValue(jbegin.getValue() + nj.getValue() - 1) ;
189
190      else if (!nj.isEmpty() && !jend.isEmpty() && jbegin.isEmpty())
191         jbegin.setValue( - nj.getValue() + jend.getValue() + 1) ;
192
193      else if (!jbegin.isEmpty() && !jend.isEmpty() && nj.isEmpty())
194         nj.setValue(jend.getValue() - jbegin.getValue() + 1) ;
195
[449]196      else if (!jbegin.isEmpty() && !jend.isEmpty() && !nj.isEmpty() )
[219]197      {
[449]198          if  (jend.getValue() != jbegin.getValue() + nj.getValue() - 1)
199             ERROR("CDomain::checkAttributes(void)",
200                 << "The domain is wrong defined,"
201                 << " iend is different of (jbegin + nj - 1) !") ;
[219]202      }
203      else
204      {
205         ERROR("CDomain::checkAttributes(void)",
[421]206               << "The domain is wrong defined,"
207               << " 2 values from  jend, jbegin, nj  must be defined !") ;
[219]208      }
209
210      if (nj.getValue() < 0 || jbegin.getValue() > jend.getValue() ||
[551]211          jbegin.getValue() < 0 || jend.getValue() > (nj_glo.getValue()-1))
[219]212         ERROR("CDomain::checkAttributes(void)",
[421]213               << "Domain is wrong defined,"
214               << " Check the values : nj, nj_glo, jbegin, jend") ;
[509]215
[449]216     ibegin_client=ibegin ; iend_client=iend ; ni_client=ni ;
217     jbegin_client=jbegin ; jend_client=jend ; nj_client=nj ;
[219]218   }
219
220   //----------------------------------------------------------------
221
222   void CDomain::checkMask(void)
223   {
224      using namespace std;
[509]225
[219]226      int ibegin_mask = 0,
227          jbegin_mask = 0,
228          iend_mask = iend.getValue() - ibegin.getValue(),
229          jend_mask = jend.getValue() - jbegin.getValue();
[509]230
[219]231      if (!zoom_ibegin.isEmpty())
232      {
233         int zoom_iend = zoom_ibegin.getValue() + zoom_ni.getValue() - 1;
234         int zoom_jend = zoom_jbegin.getValue() + zoom_nj.getValue() - 1;
[509]235
[219]236         ibegin_mask = max (ibegin.getValue(), zoom_ibegin.getValue());
237         jbegin_mask = max (jbegin.getValue(), zoom_jbegin.getValue());
238         iend_mask   = min (iend.getValue(), zoom_iend);
239         jend_mask   = min (jend.getValue(), zoom_jend);
[509]240
[219]241         ibegin_mask -= ibegin.getValue();
242         jbegin_mask -= jbegin.getValue();
243         iend_mask   -= ibegin.getValue();
244         jend_mask   -= jbegin.getValue();
245      }
246
[509]247
[219]248      if (!mask.isEmpty())
249      {
[467]250         if ((mask.extent(0) != ni) ||
251             (mask.extent(1) != nj))
[219]252            ERROR("CDomain::checkAttributes(void)",
[435]253                  <<"the mask has not the same size than the local domain"<<endl
[467]254                   <<"Local size is "<<ni<<"x"<<nj<<endl
[509]255                  <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1));
[467]256         for (int i = 0; i < ni; i++)
[219]257         {
[467]258            for (int j = 0; j < nj; j++)
[219]259            {
260               if (i < ibegin_mask && i > iend_mask &&
261                   j < jbegin_mask && j > jend_mask )
[369]262                     mask(i,j) = false;
[219]263            }
264         }
265      }
266      else // (!mask.hasValue())
267      { // Si aucun masque n'est défini,
268        // on en crée un nouveau qui valide l'intégralité du domaine.
[369]269         mask.resize(ni,nj) ;
[219]270         for (int i = 0; i < ni.getValue(); i++)
271         {
272            for (int j = 0; j < nj.getValue(); j++)
273            {
274               if (i >= ibegin_mask && i <= iend_mask &&
275                   j >= jbegin_mask && j <= jend_mask )
[369]276                     mask(i,j) = true;
277               else  mask(i,j) = false;
[219]278            }
279         }
280      }
281   }
282
283
284   //----------------------------------------------------------------
285
286   void CDomain::checkDomainData(void)
[509]287   {
[219]288      if (!data_dim.isEmpty() &&
289         !(data_dim.getValue() == 1 || data_dim.getValue() == 2))
290      {
291         ERROR("CDomain::checkAttributes(void)",
[421]292               << "Data dimension incompatible (must be 1 or 2) !") ;
[219]293      }
294      else if (data_dim.isEmpty())
295      {
296         ERROR("CDomain::checkAttributes(void)",
[421]297               << "Data dimension undefined !") ;
[219]298      }
299
300      if (data_ibegin.isEmpty())
301         data_ibegin.setValue(0) ;
302      if (data_jbegin.isEmpty() && (data_dim.getValue() == 2))
303         data_jbegin.setValue(0) ;
304
305      if (!data_ni.isEmpty() && (data_ni.getValue() <= 0))
306      {
307         ERROR("CDomain::checkAttributes(void)",
[421]308               << "Data dimension is negative (data_ni).") ;
[219]309      }
310      else if (data_ni.isEmpty())
311      {
312         data_ni.setValue((data_dim.getValue() == 1)
313                           ? (ni.getValue() * nj.getValue())
314                           : ni.getValue());
315      }
316
317      if (data_dim.getValue() == 2)
318      {
319         if (!data_nj.isEmpty() && (data_nj.getValue() <= 0) )
320         {
321            ERROR("CDomain::checkAttributes(void)",
[421]322                  << "Data dimension is negative (data_nj).") ;
[219]323         }
324         else if (data_nj.isEmpty())
325            data_nj.setValue(nj.getValue()) ;
326      }
327
328   }
329
330   //----------------------------------------------------------------
331
332   void CDomain::checkCompression(void)
333   {
334      if (!data_i_index.isEmpty())
335      {
[369]336         int ssize = data_i_index.numElements();
[219]337         if (!data_n_index.isEmpty() &&
338            (data_n_index.getValue() != ssize))
339         {
340            ERROR("CDomain::checkAttributes(void)",
[421]341                  <<"Dimension data_i_index incompatible with data_n_index.") ;
[219]342         }
343         else if (data_n_index.isEmpty())
344            data_n_index.setValue(ssize) ;
345
346         if (data_dim.getValue() == 2)
347         {
348            if (!data_j_index.isEmpty() &&
[369]349               (data_j_index.numElements() != data_i_index.numElements()))
[219]350            {
351               ERROR("CDomain::checkAttributes(void)",
[421]352                     <<"Dimension data_j_index incompatible with data_i_index.") ;
[219]353            }
354            else if (data_j_index.isEmpty())
355            {
356               ERROR("CDomain::checkAttributes(void)",
[421]357                     <<"data_j_index must be defined !") ;
[219]358            }
359         }
360      }
361      else
362      {
363         if (!data_n_index.isEmpty() ||
364            ((data_dim.getValue() == 2) && (!data_j_index.isEmpty())))
[421]365            ERROR("CDomain::checkAttributes(void)", << "data_i_index undefined") ;
[219]366      }
367
368      if (data_n_index.isEmpty())
369      { // -> bloc re-vérifié OK
370         if (data_dim.getValue() == 1)
371         {
372            const int dni = data_ni.getValue();
[369]373            data_i_index.resize(dni) ;
[219]374            data_n_index.setValue(dni);
[369]375            for (int i = 0; i < dni; i++) data_i_index(i) = i+1 ;
[219]376         }
377         else   // (data_dim == 2)
378         {
379            const int dni = data_ni.getValue() * data_nj.getValue();
[369]380            data_i_index.resize(dni) ;
381            data_j_index.resize(dni) ;
[509]382
[219]383            data_n_index.setValue(dni);
[509]384
[266]385            for(int count = 0, j = 0; j  < data_nj.getValue(); j++)
[219]386            {
[266]387               for(int i = 0; i < data_ni.getValue(); i++, count++)
[219]388               {
[369]389                  data_i_index(count) = i+1 ;
390                  data_j_index(count) = j+1 ;
[219]391               }
392            }
393         }
394      }
395   }
396
397   //----------------------------------------------------------------
[509]398
[266]399   void CDomain::completeLonLatClient(void)
[219]400   {
[384]401      int i,j,k ;
402      CArray<double,1> lonvalue_temp(ni*nj) ;
403      CArray<double,1> latvalue_temp(ni*nj) ;
[449]404      CArray<double,2> bounds_lon_temp(nvertex,ni*nj) ;
405      CArray<double,2> bounds_lat_temp(nvertex,ni*nj) ;
[509]406
[449]407      if (type.isEmpty())
[384]408      {
[509]409        if ( lonvalue.numElements() == ni*nj && latvalue.numElements() == ni*nj )
[449]410        {
411          type.setValue(type_attr::curvilinear) ;
412          isCurvilinear=true ;
413        }
[509]414        else if ( lonvalue.numElements() == ni && latvalue.numElements() == nj )
[449]415        {
416          type.setValue(type_attr::regular) ;
417          isCurvilinear=false ;
418        }
419        else ERROR("void CDomain::completeLonLatClient(void)",<<"the grid is nor curvilinear, nor cartesian, because the size of longitude and latitude array is not coherent with the domain size"<<endl
420                                                              <<"lonvalue size = " << lonvalue.numElements() << "different of ni or ni*nj"<<endl
421                                                              <<"latvalue size = " << latvalue.numElements() << "different of nj or ni*nj" ) ;
422      }
423      if (type==type_attr::curvilinear || type==type_attr::unstructured)
424      {
[384]425        lonvalue_temp=lonvalue ;
426        latvalue_temp=latvalue ;
[449]427        if (hasBounds) bounds_lon_temp=bounds_lon ;
428        if (hasBounds) bounds_lat_temp=bounds_lat ;
[384]429      }
430      else
431      {
432        for(j=0;j<nj;j++)
[509]433          for(i=0;i<ni;i++)
[384]434          {
435            k=j*ni+i ;
436            lonvalue_temp(k)=lonvalue(i) ;
437            latvalue_temp(k)=latvalue(j) ;
[449]438            if (hasBounds)
439            {
[509]440              for(int n=0;n<nvertex;n++)
[449]441              {
442                bounds_lon_temp(n,k)=bounds_lon(n,i) ;
443                bounds_lat_temp(n,k)=bounds_lat(n,j) ;
444              }
445            }
[384]446          }
447      }
[509]448
[384]449      StdSize dm = zoom_ni_client * zoom_nj_client;
[266]450
[384]451      lonvalue.resize(dm);
452      latvalue.resize(dm);
[509]453
[384]454      for (int i = 0; i < zoom_ni_client; i++)
455      {
456        for (int j = 0; j < zoom_nj_client; j++)
457        {
[509]458          lonvalue(i + j * zoom_ni_client) = lonvalue_temp( (i + zoom_ibegin_client-ibegin) + (j + zoom_jbegin_client -jbegin)*ni );
[449]459          latvalue(i + j * zoom_ni_client) = latvalue_temp( (i + zoom_ibegin_client - ibegin)+(j + zoom_jbegin_client - jbegin)*ni );
460          if (hasBounds)
461          {
[509]462            for(int n=0;n<nvertex;n++)
[449]463            {
[509]464              bounds_lon(n,i + j * zoom_ni_client) = bounds_lon_temp( n, (i + zoom_ibegin_client - ibegin) + (j + zoom_jbegin_client -jbegin)*ni );
[449]465              bounds_lat(n,i + j * zoom_ni_client) = bounds_lat_temp( n, (i + zoom_ibegin_client - ibegin)+(j + zoom_jbegin_client -jbegin)*ni );
466            }
467          }
[384]468        }
[266]469      }
[449]470    }
[219]471
[509]472
[219]473   //----------------------------------------------------------------
474
475   void CDomain::checkZoom(void)
476   {
477      // Résolution et vérification des données globales de zoom.
478      if (!this->zoom_ni.isEmpty() || !this->zoom_nj.isEmpty() ||
479          !this->zoom_ibegin.isEmpty() || !this->zoom_jbegin.isEmpty())
480      {
[384]481         if (this->zoom_ni.isEmpty()     || this->zoom_nj.isEmpty() ||
482             this->zoom_ibegin.isEmpty() || this->zoom_jbegin.isEmpty())
[219]483         {
484            ERROR("CDomain::checkZoom(void)",
[384]485                  <<"if one of zoom attributes is defined then all zoom attributes must be defined") ;
[219]486         }
487         else
488         {
[449]489            int zoom_iend = zoom_ibegin + zoom_ni - 1;
490            int zoom_jend = zoom_jbegin + zoom_nj - 1;
[509]491
[551]492            if (zoom_ibegin < 0  || zoom_jbegin < 0 || zoom_iend > (ni_glo-1) || zoom_jend > (nj_glo-1))
[219]493               ERROR("CDomain::checkZoom(void)",
[421]494                     << "Zoom is wrong defined,"
[479]495                     << " Check the values : zoom_ni, zoom_nj, zoom_ibegin, zoom_jbegin") ;
[219]496         }
497      }
498      else
499      {
[509]500         zoom_ni = ni_glo;
[449]501         zoom_nj = nj_glo;
[551]502         zoom_ibegin = 0;
503         zoom_jbegin = 0;
[219]504      }
[509]505
[449]506      // compute client zoom indices
507
508      int zoom_iend=zoom_ibegin+zoom_ni-1 ;
509      zoom_ibegin_client = ibegin_client > zoom_ibegin ? ibegin_client : zoom_ibegin ;
510      zoom_iend_client = iend_client < zoom_iend ? iend_client : zoom_iend ;
511      zoom_ni_client=zoom_iend_client-zoom_ibegin_client+1 ;
512      if (zoom_ni_client<0) zoom_ni_client=0 ;
513
[509]514
[449]515      int zoom_jend=zoom_jbegin+zoom_nj-1 ;
516      zoom_jbegin_client = jbegin_client > zoom_jbegin ? jbegin_client : zoom_jbegin ;
517      zoom_jend_client = jend_client < zoom_jend ? jend_client : zoom_jend ;
518      zoom_nj_client=zoom_jend_client-zoom_jbegin_client+1 ;
519      if (zoom_nj_client<0) zoom_nj_client=0 ;
[467]520
[219]521   }
[509]522
[449]523   void CDomain::checkBounds(void)
524   {
525     if (!nvertex.isEmpty() && !bounds_lon.isEmpty() && !bounds_lat.isEmpty())
526     {
527       hasBounds=true ;
[509]528
[449]529     }
[509]530     else
[449]531     {
532       hasBounds=false;
533       nvertex=0 ;
534     }
535   }
[509]536
[219]537   //----------------------------------------------------------------
[509]538   // Divide function checkAttributes into 2 seperate ones
539   // This function only checks all attributes of current domain
540   void CDomain::checkAttributesOnClient()
541   {
542     if (this->isClientChecked) return;
543     CContext* context=CContext::getCurrent();
[219]544
[509]545      this->checkDomain();
546      this->checkZoom();
547      this->checkBounds();
548
549      if (context->hasClient)
550      { // CÃŽté client uniquement
551         this->checkMask();
552         this->checkDomainData();
553         this->checkCompression();
554         this->completeLonLatClient();
555         this->computeConnectedServer() ;
556      }
557      else
558      { // CÃŽté serveur uniquement
559//         if (!this->isEmpty())
560// ne sert plus //   this->completeLonLatServer();
561      }
562
563      this->isClientChecked = true;
564   }
565
566   // Send all checked attributes to server
567   void CDomain::sendCheckedAttributes()
568   {
569     if (!this->isClientChecked) checkAttributesOnClient();
570     CContext* context=CContext::getCurrent() ;
571
572     if (this->isChecked) return;
573     if (context->hasClient)
574     {
575       sendServerAttribut() ;
576       sendLonLat() ;
577     }
578
579     this->isChecked = true;
580   }
581
[219]582   void CDomain::checkAttributes(void)
583   {
584      if (this->isChecked) return;
[347]585      CContext* context=CContext::getCurrent() ;
[219]586
[467]587      this->checkDomain();
[219]588      this->checkZoom();
[449]589      this->checkBounds();
[509]590
[300]591      if (context->hasClient)
[219]592      { // CÃŽté client uniquement
593         this->checkMask();
594         this->checkDomainData();
595         this->checkCompression();
[449]596         this->completeLonLatClient();
[219]597      }
598      else
599      { // CÃŽté serveur uniquement
[286]600//         if (!this->isEmpty())
[300]601// ne sert plus //   this->completeLonLatServer();
[219]602      }
[509]603
[300]604      if (context->hasClient)
605      {
606        computeConnectedServer() ;
607        sendServerAttribut() ;
608        sendLonLat() ;
609      }
[509]610
[219]611      this->isChecked = true;
612   }
[509]613
[300]614  void CDomain::sendServerAttribut(void)
615  {
[553]616    std::vector<int> nGlobDomain(2);
617    nGlobDomain[0] = ni_glo.getValue();
618    nGlobDomain[1] = nj_glo.getValue();
619    CServerDistributionDescription serverDescription(nGlobDomain);
620
[300]621    int ni_srv=ni_glo.getValue() ;
[551]622    int ibegin_srv=0 ;
[300]623    int iend_srv=ni_glo.getValue() ;
[509]624
[300]625    int nj_srv ;
626    int jbegin_srv ;
627    int jend_srv ;
[509]628
[347]629    CContext* context=CContext::getCurrent() ;
[300]630    CContextClient* client=context->client ;
631    int nbServer=client->serverSize ;
632    int serverRank=client->getServerLeader() ;
[509]633
[553]634     serverDescription.computeServerDistribution(nbServer);
635     std::vector<std::vector<int> > serverIndexBegin = serverDescription.getServerIndexBegin();
636     std::vector<std::vector<int> > serverDimensionSizes = serverDescription.getServerDimensionSizes();
637     ibegin_srv = (serverIndexBegin[serverRank])[0];
638     jbegin_srv = serverIndexBegin[serverRank][1];
639     ni_srv = serverDimensionSizes[serverRank][0];
640     nj_srv = serverDimensionSizes[serverRank][1];
641     iend_srv = ibegin_srv+ni_srv-1;
642     jend_srv = jbegin_srv+nj_srv-1;
[509]643
644     CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT) ;
[300]645     if (client->isServerLeader())
646     {
647       CMessage msg ;
648       msg<<this->getId() ;
649       msg<<ni_srv<<ibegin_srv<<iend_srv<<nj_srv<<jbegin_srv<<jend_srv;
650       event.push(client->getServerLeader(),1,msg) ;
651       client->sendEvent(event) ;
652     }
653     else client->sendEvent(event) ;
654  }
[467]655
[300]656  void CDomain::computeConnectedServer(void)
657  {
[467]658    ibegin_client=ibegin ; iend_client=iend ; ni_client=ni ;
659    jbegin_client=jbegin ; jend_client=jend ; nj_client=nj ;
[509]660
[553]661    CContext* context=CContext::getCurrent() ;
[300]662    CContextClient* client=context->client ;
[553]663    int nbServer=client->serverSize;
664    bool doComputeGlobalIndexServer = true;
[449]665
[553]666    int i,j,i_ind,j_ind ;
[449]667    int zoom_iend=zoom_ibegin+zoom_ni-1 ;
668    int zoom_jend=zoom_jbegin+zoom_nj-1 ;
[509]669
670
[553]671    // Precompute number of index
672    int globalIndexCount = 0;
[467]673    for(j=0;j<nj;j++)
674      for(i=0;i<ni;i++)
675      {
[551]676        i_ind=ibegin+i_index(i,j) ;
677        j_ind=jbegin+j_index(i,j) ;
[509]678
[551]679        if (i_ind >= zoom_ibegin && i_ind <= zoom_iend && j_ind >= zoom_jbegin && j_ind <= zoom_jend)
[300]680        {
[553]681          ++globalIndexCount;
[300]682        }
[467]683      }
684
[553]685    // Fill in index
686    CArray<size_t,1> globalIndexDomain(globalIndexCount);
687    size_t globalIndex;
688    globalIndexCount = 0;
[467]689
[553]690    for(j=0;j<nj;j++)
691      for(i=0;i<ni;i++)
[467]692      {
[553]693        i_ind=ibegin+i_index(i,j) ;
694        j_ind=jbegin+j_index(i,j) ;
[509]695
[553]696        if (i_ind >= zoom_ibegin && i_ind <= zoom_iend && j_ind >= zoom_jbegin && j_ind <= zoom_jend)
[300]697        {
[553]698          globalIndex = i_ind + j_ind * ni_glo;
699          globalIndexDomain(globalIndexCount) = globalIndex;
700          ++globalIndexCount;
[300]701        }
702      }
[509]703
[569]704     std::vector<int> nGlobDomain(2);
705     nGlobDomain[0] = ni_glo.getValue();
706     nGlobDomain[1] = nj_glo.getValue();
707     size_t globalSizeIndex = 1, indexBegin, indexEnd;
708     int range, clientSize = client->clientSize;
709     for (int i = 0; i < nGlobDomain.size(); ++i) globalSizeIndex *= nGlobDomain[i];
710     indexBegin = 0;
711     for (int i = 0; i < clientSize; ++i)
712     {
713       range = globalSizeIndex / clientSize;
714       if (i < (globalSizeIndex%clientSize)) ++range;
715       if (i == client->clientRank) break;
716       indexBegin += range;
717     }
718     indexEnd = indexBegin + range - 1;
719
720    CServerDistributionDescription serverDescription(nGlobDomain);
721    serverDescription.computeServerGlobalIndexInRange(nbServer, std::make_pair<size_t,size_t>(indexBegin, indexEnd));
722    CClientServerMapping* clientServerMap = new CClientServerMappingDistributed(serverDescription.getGlobalIndexRange(),
723                                                                                client->intraComm);
724    clientServerMap->computeServerIndexMapping(globalIndexDomain);
725    const std::map<int, std::vector<size_t> >& globalIndexDomainOnServer = clientServerMap->getGlobalIndexOnServer();
[553]726    std::vector<int> connectedServerRank;
727    for (std::map<int, std::vector<size_t> >::const_iterator it = globalIndexDomainOnServer.begin(); it != globalIndexDomainOnServer.end(); ++it) {
728      connectedServerRank.push_back(it->first);
729    }
[569]730    nbConnectedClients_ = clientServerMap->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank);
[553]731    indSrv_ = globalIndexDomainOnServer;
[569]732
733    delete clientServerMap;
[300]734  }
[467]735
[300]736  void CDomain::sendLonLat(void)
737  {
[553]738    int ns,n,i,j,ind,nv, idx;
[347]739    CContext* context = CContext::getCurrent() ;
[300]740    CContextClient* client=context->client ;
741    // send lon lat for each connected server
[509]742
[518]743    CEventClient eventLon(getType(),EVENT_ID_LON) ;
744    CEventClient eventLat(getType(),EVENT_ID_LAT) ;
745
746    list<shared_ptr<CMessage> > list_msgLon ;
747    list<shared_ptr<CMessage> > list_msgLat ;
[449]748    list< CArray<int,1>* > list_indi,list_indj ;
749    list< CArray<double,1>* >list_lon,list_lat ;
750    list< CArray<double,2>* >list_boundslon,list_boundslat ;
[300]751
[553]752    std::map<int, std::vector<size_t> >::const_iterator it, itbMap, iteMap;
753    itbMap = indSrv_.begin();
754    iteMap = indSrv_.end();
755    for (it = itbMap; it != iteMap; ++it)
[300]756    {
[553]757      int rank = it->first;
758      int nbData = (it->second).size();
[467]759      CArray<int,1> indi(nbData) ;
760      CArray<int,1> indj(nbData) ;
761      CArray<double,1> lon(nbData) ;
762      CArray<double,1> lat(nbData) ;
[553]763      CArray<double,2> boundslon(nvertex,nbData);
764      CArray<double,2> boundslat(nvertex,nbData);
[509]765
[553]766      for (n = 0; n < nbData; ++n)
[467]767      {
[553]768        idx = static_cast<int>((it->second)[n]);
769        i = idx%ni_glo;
770        j = idx/ni_glo;
[551]771        ind=(i-(zoom_ibegin_client))+(j-(zoom_jbegin_client))*zoom_ni_client ;
[509]772
[467]773        lon(n)=lonvalue(ind) ;
774        lat(n)=latvalue(ind) ;
775        if (hasBounds)
[300]776        {
[467]777          for(nv=0;nv<nvertex;nv++)
[449]778          {
[467]779            boundslon(nv,n)=bounds_lon(nv,ind);
780            boundslat(nv,n)=bounds_lat(nv,ind);
[449]781          }
[300]782        }
[551]783        indi(n)=ibegin+i_index(i-ibegin,j-jbegin)  ;
784        indj(n)=jbegin+j_index(i-ibegin,j-jbegin)  ;
[467]785      }
[509]786
[449]787      list_indi.push_back(new CArray<int,1>(indi.copy())) ;
788      list_indj.push_back(new CArray<int,1>(indj.copy())) ;
[369]789      list_lon.push_back(new CArray<double,1>(lon.copy())) ;
790      list_lat.push_back(new CArray<double,1>(lat.copy())) ;
[449]791      if (hasBounds) list_boundslon.push_back(new CArray<double,2>(boundslon.copy())) ;
792      if (hasBounds) list_boundslat.push_back(new CArray<double,2>(boundslat.copy())) ;
[369]793
[518]794      list_msgLon.push_back(shared_ptr<CMessage>(new CMessage)) ;
795      list_msgLat.push_back(shared_ptr<CMessage>(new CMessage)) ;
[300]796
[518]797      *list_msgLon.back()<<this->getId()<<(int)type ; // enum ne fonctionne pour les message => ToFix
798      *list_msgLat.back()<<this->getId()<<(int)type ;
799      *list_msgLon.back()<<isCurvilinear ;
800      *list_msgLat.back()<<isCurvilinear ;
801      *list_msgLon.back()<<*list_indi.back()<<*list_indj.back()<<*list_lon.back() ;
802      *list_msgLat.back()<<*list_indi.back()<<*list_indj.back()<<*list_lat.back() ;
803
804      if (hasBounds)
805      {
806        *list_msgLon.back()<<*list_boundslon.back();
807        *list_msgLat.back()<<*list_boundslat.back();
808      }
[553]809      eventLon.push(rank,nbConnectedClients_[rank],*list_msgLon.back()) ;
810      eventLat.push(rank,nbConnectedClients_[rank],*list_msgLat.back()) ;
[300]811    }
812
[518]813    client->sendEvent(eventLon) ;
814    client->sendEvent(eventLat) ;
[509]815
816
[449]817    for(list<CArray<int,1>* >::iterator it=list_indi.begin();it!=list_indi.end();it++) delete *it;
818    for(list<CArray<int,1>* >::iterator it=list_indj.begin();it!=list_indj.end();it++) delete *it;
819    for(list<CArray<double,1>* >::iterator it=list_lon.begin();it!=list_lon.end();it++)   delete *it;
820    for(list<CArray<double,1>* >::iterator it=list_lat.begin();it!=list_lat.end();it++)   delete *it;
821    if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslon.begin();it!=list_boundslon.end();it++)   delete *it;
[509]822    if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslat.begin();it!=list_boundslat.end();it++)   delete *it;
[300]823  }
[509]824
[300]825  bool CDomain::dispatchEvent(CEventServer& event)
826   {
[509]827
[300]828      if (SuperClass::dispatchEvent(event)) return true ;
829      else
830      {
831        switch(event.type)
832        {
833           case EVENT_ID_SERVER_ATTRIBUT :
834             recvServerAttribut(event) ;
835             return true ;
836             break ;
[518]837           case EVENT_ID_LON :
838             recvLon(event) ;
[300]839             return true ;
840             break ;
[518]841           case EVENT_ID_LAT :
842             recvLat(event) ;
843             return true ;
844             break ;
[300]845           default :
846             ERROR("bool CContext::dispatchEvent(CEventServer& event)",
847                    <<"Unknown Event") ;
848           return false ;
849         }
850      }
851   }
[509]852
[300]853  void CDomain::recvServerAttribut(CEventServer& event)
854  {
855    CBufferIn* buffer=event.subEvents.begin()->buffer;
856    string domainId ;
857    *buffer>>domainId ;
858    get(domainId)->recvServerAttribut(*buffer) ;
859  }
[509]860
[300]861  void CDomain::recvServerAttribut(CBufferIn& buffer)
862  {
863    int zoom_iend=zoom_ibegin.getValue()+zoom_ni.getValue()-1 ;
864    int zoom_jend=zoom_jbegin.getValue()+zoom_nj.getValue()-1 ;
865
866     buffer>>ni_srv>>ibegin_srv>>iend_srv>>nj_srv>>jbegin_srv>>jend_srv;
[509]867
868
[300]869    zoom_ibegin_srv = zoom_ibegin.getValue() > ibegin_srv ? zoom_ibegin.getValue() : ibegin_srv ;
870    zoom_iend_srv = zoom_iend < iend_srv ? zoom_iend : iend_srv ;
871    zoom_ni_srv=zoom_iend_srv-zoom_ibegin_srv+1 ;
[509]872
[300]873    zoom_jbegin_srv = zoom_jbegin.getValue() > jbegin_srv ? zoom_jbegin.getValue() : jbegin_srv ;
874    zoom_jend_srv = zoom_jend < jend_srv ? zoom_jend : jend_srv ;
875    zoom_nj_srv=zoom_jend_srv-zoom_jbegin_srv+1 ;
876
[509]877    if (zoom_ni_srv<=0 || zoom_nj_srv<=0)
[300]878    {
[551]879      zoom_ibegin_srv=0 ; zoom_iend_srv=0 ; zoom_ni_srv=0 ;
880      zoom_jbegin_srv=0 ; zoom_jend_srv=0 ; zoom_nj_srv=0 ;
[300]881    }
[369]882    lonvalue_srv.resize(zoom_ni_srv*zoom_nj_srv) ;
[456]883    lonvalue_srv = 0. ;
[369]884    latvalue_srv.resize(zoom_ni_srv*zoom_nj_srv) ;
[456]885    latvalue_srv = 0. ;
[509]886    if (hasBounds)
[456]887    {
888      bounds_lon_srv.resize(nvertex,zoom_ni_srv*zoom_nj_srv) ;
889      bounds_lon_srv = 0. ;
890      bounds_lat_srv.resize(nvertex,zoom_ni_srv*zoom_nj_srv) ;
891      bounds_lat_srv = 0. ;
892    }
[300]893  }
[509]894
[518]895  void CDomain::recvLon(CEventServer& event)
[300]896  {
897    list<CEventServer::SSubEvent>::iterator it ;
898    for (it=event.subEvents.begin();it!=event.subEvents.end();++it)
899    {
900      CBufferIn* buffer=it->buffer;
901      string domainId ;
902      *buffer>>domainId ;
[518]903      get(domainId)->recvLon(*buffer) ;
[300]904    }
905  }
[509]906
[518]907  void CDomain::recvLon(CBufferIn& buffer)
[300]908  {
[449]909    CArray<int,1> indi ;
910    CArray<int,1> indj ;
[369]911    CArray<double,1> lon ;
[518]912    CArray<double,2> boundslon ;
913
914    int type_int ;
915    buffer>>type_int>>isCurvilinear>>indi>>indj>>lon ;
916    if (hasBounds) buffer>>boundslon ;
917    type.setValue((type_attr::t_enum)type_int) ; // probleme des type enum avec les buffers : ToFix
918
919    int i,j,ind_srv ;
920    for(int ind=0;ind<indi.numElements();ind++)
921    {
922      i=indi(ind) ; j=indj(ind) ;
[551]923      ind_srv=(i-(zoom_ibegin_srv))+(j-(zoom_jbegin_srv))*zoom_ni_srv ;
[518]924      lonvalue_srv(ind_srv)=lon(ind) ;
925      if (hasBounds)
926      {
927        for(int nv=0;nv<nvertex;nv++)
928        {
929          bounds_lon_srv(nv,ind_srv)=boundslon(nv,ind) ;
930        }
931      }
932    }
933  }
934
935  void CDomain::recvLat(CEventServer& event)
936  {
937    list<CEventServer::SSubEvent>::iterator it ;
938    for (it=event.subEvents.begin();it!=event.subEvents.end();++it)
939    {
940      CBufferIn* buffer=it->buffer;
941      string domainId ;
942      *buffer>>domainId ;
943      get(domainId)->recvLat(*buffer) ;
944    }
945  }
946
947  void CDomain::recvLat(CBufferIn& buffer)
948  {
949    CArray<int,1> indi ;
950    CArray<int,1> indj ;
[369]951    CArray<double,1> lat ;
[449]952    CArray<double,2> boundslat ;
[509]953
[449]954    int type_int ;
[518]955    buffer>>type_int>>isCurvilinear>>indi>>indj>>lat ;
956    if (hasBounds) buffer>>boundslat ;
[449]957    type.setValue((type_attr::t_enum)type_int) ; // probleme des type enum avec les buffers : ToFix
[300]958    int i,j,ind_srv ;
[369]959    for(int ind=0;ind<indi.numElements();ind++)
[300]960    {
[369]961      i=indi(ind) ; j=indj(ind) ;
[551]962      ind_srv=(i-(zoom_ibegin_srv))+(j-(zoom_jbegin_srv))*zoom_ni_srv ;
[369]963      latvalue_srv(ind_srv)=lat(ind) ;
[509]964      if (hasBounds)
[449]965      {
[509]966        for(int nv=0;nv<nvertex;nv++)
[449]967        {
[467]968          bounds_lat_srv(nv,ind_srv)=boundslat(nv,ind) ;
[449]969        }
970      }
[300]971    }
972  }
[553]973
[219]974   //----------------------------------------------------------------
[509]975
[540]976   DEFINE_REF_FUNC(Domain,domain)
[509]977
[219]978   ///---------------------------------------------------------------
979
[335]980} // namespace xios
Note: See TracBrowser for help on using the repository browser.