source: XIOS/trunk/src/node/grid.cpp @ 518

Last change on this file since 518 was 518, checked in by mhnguyen, 10 years ago

Fixing bug of automatic dection of buffer size

+) Split sending of longtitude and latitude event message to decrease its size into 2
+) Correct size of buffer on client and server side
+) Do some cleaning code

Test
+) On Curie
+) Test only on domain (without axis), all passed

  • 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: 23.3 KB
RevLine 
[266]1
[219]2#include "grid.hpp"
3
[352]4#include "attribute_template.hpp"
5#include "object_template.hpp"
6#include "group_template.hpp"
7#include "message.hpp"
[286]8#include <iostream>
[352]9#include "xmlioserver_spl.hpp"
10#include "type.hpp"
11#include "context.hpp"
12#include "context_client.hpp"
[369]13#include "array_new.hpp"
[219]14
[335]15namespace xios {
[219]16
17   /// ////////////////////// Définitions ////////////////////// ///
18
19   CGrid::CGrid(void)
20      : CObjectTemplate<CGrid>(), CGridAttributes()
[509]21      , withAxis(false), isChecked(false), isDomainAxisChecked(false), axis(), domain()
22      , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false)
[219]23   { /* Ne rien faire de plus */ }
24
25   CGrid::CGrid(const StdString & id)
26      : CObjectTemplate<CGrid>(id), CGridAttributes()
[509]27      , withAxis(false), isChecked(false), isDomainAxisChecked(false), axis(), domain()
28      , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false)
[219]29   { /* Ne rien faire de plus */ }
30
31   CGrid::~CGrid(void)
[509]32   {
[347]33 //     this->axis.reset() ;
34//      this->domain.reset() ;
[369]35    deque< CArray<int, 1>* >::iterator it ;
[509]36
[369]37    for(deque< CArray<int,1>* >::iterator it=storeIndex.begin(); it!=storeIndex.end();it++)  delete *it ;
38    for(deque< CArray<int,1>* >::iterator it=out_i_index.begin();it!=out_i_index.end();it++) delete *it ;
39    for(deque< CArray<int,1>* >::iterator it=out_j_index.begin();it!=out_j_index.end();it++) delete *it ;
40    for(deque< CArray<int,1>* >::iterator it=out_l_index.begin();it!=out_l_index.end();it++) delete *it ;
41
42    for(map<int,CArray<int,1>* >::iterator it=out_i_fromClient.begin();it!=out_i_fromClient.end();it++) delete it->second ;
43    for(map<int,CArray<int,1>* >::iterator it=out_j_fromClient.begin();it!=out_j_fromClient.end();it++) delete it->second ;
44    for(map<int,CArray<int,1>* >::iterator it=out_l_fromClient.begin();it!=out_l_fromClient.end();it++) delete it->second ;
45
[219]46   }
47
48   ///---------------------------------------------------------------
49
50   StdString CGrid::GetName(void)    { return (StdString("grid")); }
51   StdString CGrid::GetDefName(void) { return (CGrid::GetName()); }
52   ENodeType CGrid::GetType(void)    { return (eGrid); }
53
54   //----------------------------------------------------------------
55
[369]56   const std::deque< CArray<int,1>* > & CGrid::getStoreIndex(void) const
[509]57   {
[219]58      return (this->storeIndex );
59   }
60
61   //---------------------------------------------------------------
62
[369]63   const std::deque< CArray<int,1>* > & CGrid::getOutIIndex(void)  const
[509]64   {
65      return (this->out_i_index );
[219]66   }
67
68   //---------------------------------------------------------------
69
[369]70   const std::deque< CArray<int,1>* > & CGrid::getOutJIndex(void)  const
[509]71   {
72      return (this->out_j_index );
[219]73   }
74
75   //---------------------------------------------------------------
76
[369]77   const std::deque< CArray<int,1>* > & CGrid::getOutLIndex(void)  const
[509]78   {
79      return (this->out_l_index );
[219]80   }
81
82   //---------------------------------------------------------------
83
[347]84   const CAxis*   CGrid::getRelAxis  (void) const
[509]85   {
86      return (this->axis );
[219]87   }
88
89   //---------------------------------------------------------------
90
[347]91   const CDomain* CGrid::getRelDomain(void) const
[509]92   {
93      return (this->domain );
[219]94   }
95
96   //---------------------------------------------------------------
97
[509]98   bool CGrid::hasAxis(void) const
99   {
100      return (this->withAxis);
[219]101   }
102
103   //---------------------------------------------------------------
104
105   StdSize CGrid::getDimension(void) const
106   {
107      return ((this->withAxis)?3:2);
108   }
109
110   //---------------------------------------------------------------
111
[351]112/*
[266]113   std::vector<StdSize> CGrid::getLocalShape(void) const
[219]114   {
115      std::vector<StdSize> retvalue;
[266]116      retvalue.push_back(domain->zoom_ni_loc.getValue());
117      retvalue.push_back(domain->zoom_nj_loc.getValue());
[219]118      if (this->withAxis)
[351]119         retvalue.push_back(this->axis->zoom_size.getValue());
[219]120      return (retvalue);
121   }
[351]122*/
[219]123   //---------------------------------------------------------------
[509]124
[351]125/*
[266]126   StdSize CGrid::getLocalSize(void) const
[219]127   {
128      StdSize retvalue = 1;
[266]129      std::vector<StdSize> shape_ = this->getLocalShape();
[219]130      for (StdSize s = 0; s < shape_.size(); s++)
131         retvalue *= shape_[s];
132      return (retvalue);
133   }
[351]134*/
[266]135   //---------------------------------------------------------------
[351]136/*
[266]137   std::vector<StdSize> CGrid::getGlobalShape(void) const
138   {
139      std::vector<StdSize> retvalue;
140      retvalue.push_back(domain->ni.getValue());
141      retvalue.push_back(domain->nj.getValue());
142      if (this->withAxis)
143         retvalue.push_back(this->axis->size.getValue());
144      return (retvalue);
145   }
[351]146*/
[219]147   //---------------------------------------------------------------
[351]148
[509]149/*
[266]150   StdSize CGrid::getGlobalSize(void) const
151   {
152      StdSize retvalue = 1;
153      std::vector<StdSize> shape_ = this->getGlobalShape();
154      for (StdSize s = 0; s < shape_.size(); s++)
155         retvalue *= shape_[s];
156      return (retvalue);
157   }
[351]158*/
[286]159   StdSize CGrid::getDataSize(void) const
160   {
[369]161      StdSize retvalue=domain->data_ni.getValue() ;
[286]162      if (domain->data_dim.getValue()==2) retvalue*=domain->data_nj.getValue() ;
163      if (this->withAxis) retvalue*=this->axis->size.getValue() ;
164
165      return (retvalue);
166   }
167
[509]168   std::map<int, StdSize> CGrid::getConnectedServerDataSize()
169   {
170     std::map<int, StdSize> ret;
171     std::map<int, int>::const_iterator it = domConnectedServerSide_.begin(),
172                                       itE = domConnectedServerSide_.end();
[518]173     std::vector<int> nData = domain->nbDataSrv;
174     std::vector<int>::const_iterator itData = nData.begin();
[509]175     StdSize retVal = StdSize(0.0);
[518]176     for (; it != itE; ++it, ++itData)
[509]177     {
[518]178       retVal = (it->second < *itData) ? *itData : it->second;
[509]179       if (this->withAxis) retVal *= this->axis->size.getValue();
180       retVal *= sizeof(double);
[518]181       retVal *= 2.5 * CXios::bufferServerFactorSize; // Secure factor, myterious number
[509]182       ret.insert(make_pair(it->first, retVal));
183     }
184     return ret;
185   }
186
187
[266]188   //---------------------------------------------------------------
189
[509]190//   void CGrid::solveReference(void)
191//   {
192//      if (this->isChecked) return;
193//      CContext* context = CContext::getCurrent() ;
194//      CContextClient* client=context->client ;
195//
196//      this->solveDomainRef() ;
197//      this->solveAxisRef() ;
198//
199//      if (context->hasClient)
200//      {
201//         checkMask() ;
202//         this->computeIndex() ;
203//
204//         this->storeIndex.push_front(new CArray<int,1>() );
205//         this->out_i_index.push_front(new CArray<int,1>());
206//         this->out_j_index.push_front(new CArray<int,1>());
207//         this->out_l_index.push_front(new CArray<int,1>());
208//      }
209////      this->computeIndexServer();
210//      this->isChecked = true;
211//   }
212
213   void CGrid::solveDomainAxisRef(bool areAttributesChecked)
[219]214   {
[509]215     if (this->isDomainAxisChecked) return;
[369]216
[509]217     this->solveDomainRef(areAttributesChecked);
218     this->solveAxisRef(areAttributesChecked);
219
220     this->isDomainAxisChecked = areAttributesChecked;
221   }
222
223   void CGrid::checkMaskIndex(bool doSendingIndex)
224   {
225     CContext* context = CContext::getCurrent() ;
226     CContextClient* client=context->client ;
227
228     if (context->hasClient)
229      if (this->isChecked && doSendingIndex) sendIndex();
230
231     if (this->isChecked) return;
232
233     if (context->hasClient)
234     {
235        checkMask() ;
236        this->computeIndex() ;
237
238        this->storeIndex.push_front(new CArray<int,1>() );
239        this->out_i_index.push_front(new CArray<int,1>());
240        this->out_j_index.push_front(new CArray<int,1>());
241        this->out_l_index.push_front(new CArray<int,1>());
242     }
[300]243//      this->computeIndexServer();
[509]244     this->isChecked = true;
[219]245   }
246
[415]247
248   void CGrid::checkMask(void)
249   {
250      using namespace std;
251
252      unsigned int niu = domain->ni, nju = domain->nj;
253      unsigned int nlu = 1 ;
254      if (hasAxis()) nlu=axis->size ;
255
256      if (!mask.isEmpty())
257      {
258         if ((mask.extent(0) != niu) ||
259             (mask.extent(1) != nju) ||
260             (mask.extent(2) != nlu))
261             ERROR("CGrid::checkAttributes(void)",
[509]262                  <<"The mask has not the same size than the local grid"<<endl
[435]263                  <<"Local size is "<<niu<<"x"<<nju<<"x"<<nlu<<endl
264                  <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1)<<"x"<<mask.extent(2));
[415]265      }
[509]266      else
[415]267      {
268        mask.resize(niu,nju,nlu) ;
269        mask=true  ;
270      }
[509]271
[415]272      CArray<bool,2>& domainMask = domain->mask ;
273      for (int l=0; l < nlu ; l++)
274        for (int j=0; j < nju ; j++)
275          for(int i=0; i<niu ; i++) mask(i,j,l) = mask(i,j,l) && domainMask(i,j) ;
[509]276
277
[415]278   }
[509]279
[219]280   //---------------------------------------------------------------
281
[509]282//   void CGrid::solveDomainRef(void)
283//   {
284//      if (!domain_ref.isEmpty())
285//      {
286//         if (CDomain::has(domain_ref.getValue()))
287//         {
288//            this->domain = CDomain::get(domain_ref.getValue()) ;
289//            domain->checkAttributes() ;
290//         }
291//         else ERROR("CGrid::solveDomainRef(void)",
292//                     << "Wrong domain reference") ;
293//      }
294//      else ERROR("CGrid::solveDomainRef(void)",
295//                  << "Domain reference is not defined") ;
296//   }
297//
298//   //---------------------------------------------------------------
299//
300//   void CGrid::solveAxisRef(void)
301//   {
302//      if (!axis_ref.isEmpty())
303//      {
304//         this->withAxis = true ;
305//         if (CAxis::get(axis_ref.getValue()))
306//         {
307//            this->axis = CAxis::get(axis_ref.getValue()) ;
308//            axis->checkAttributes() ;
309//         }
310//         else ERROR("CGrid::solveAxisRef(void)",
311//                    << "Wrong axis reference") ;
312//      }
313//      else withAxis = false ;
314//   }
315
316
317   void CGrid::solveDomainRef(bool sendAtt)
[219]318   {
319      if (!domain_ref.isEmpty())
320      {
[346]321         if (CDomain::has(domain_ref.getValue()))
[219]322         {
[346]323            this->domain = CDomain::get(domain_ref.getValue()) ;
[509]324            if (sendAtt) domain->sendCheckedAttributes();
325            else domain->checkAttributesOnClient() ;
[219]326         }
327         else ERROR("CGrid::solveDomainRef(void)",
[421]328                     << "Wrong domain reference") ;
[219]329      }
330      else ERROR("CGrid::solveDomainRef(void)",
[421]331                  << "Domain reference is not defined") ;
[219]332   }
333
334   //---------------------------------------------------------------
335
[509]336   void CGrid::solveAxisRef(bool checkAtt)
[219]337   {
338      if (!axis_ref.isEmpty())
339      {
340         this->withAxis = true ;
[346]341         if (CAxis::get(axis_ref.getValue()))
[219]342         {
[346]343            this->axis = CAxis::get(axis_ref.getValue()) ;
[219]344            axis->checkAttributes() ;
345         }
346         else ERROR("CGrid::solveAxisRef(void)",
[421]347                    << "Wrong axis reference") ;
[219]348      }
349      else withAxis = false ;
350   }
351
352   //---------------------------------------------------------------
353
354   void CGrid::computeIndex(void)
[509]355   {
356
[219]357      const int ni   = domain->ni.getValue() ,
358                nj   = domain->nj.getValue() ,
[351]359                size = (this->hasAxis()) ? axis->size.getValue() : 1 ,
360                lbegin = (this->hasAxis()) ? axis->zoom_begin.getValue()-1 : 0 ,
361                lend = (this->hasAxis()) ? axis->zoom_end.getValue()-1 : 0 ;
[219]362
363
364      const int data_dim     = domain->data_dim.getValue() ,
365                data_n_index = domain->data_n_index.getValue() ,
366                data_ibegin  = domain->data_ibegin.getValue() ,
367                data_jbegin  = (data_dim == 2)
368                             ? domain->data_jbegin.getValue() : -1;
369
[369]370      CArray<int,1> data_i_index = domain->data_i_index ;
371      CArray<int,1> data_j_index = domain->data_j_index ;
[219]372
[509]373
[219]374      int indexCount = 0;
375
376      for(int l = 0; l < size ; l++)
377      {
378         for(int n = 0, i = 0, j = 0; n < data_n_index; n++)
379         {
[369]380            int temp_i = data_i_index(n) + data_ibegin,
[219]381                temp_j = (data_dim == 1) ? -1
[369]382                       : data_j_index(n) + data_jbegin;
[266]383            i = (data_dim == 1) ? (temp_i - 1) % ni
[219]384                                : (temp_i - 1) ;
[266]385            j = (data_dim == 1) ? (temp_i - 1) / ni
[219]386                                : (temp_j - 1) ;
387
[351]388            if ((l >=lbegin && l<= lend) &&
389                (i >= 0 && i < ni) &&
[415]390                (j >= 0 && j < nj) && mask(i,j,l))
[219]391               indexCount++ ;
392         }
393      }
[509]394
[369]395      storeIndex[0]  = new CArray<int,1>(indexCount) ;
396      out_i_index[0] = new CArray<int,1>(indexCount) ;
397      out_j_index[0] = new CArray<int,1>(indexCount) ;
398      out_l_index[0] = new CArray<int,1>(indexCount) ;
[509]399
[369]400      storeIndex_client.resize(indexCount) ;
401      out_i_client.resize(indexCount) ;
402      out_j_client.resize(indexCount) ;
403      out_l_client.resize(indexCount) ;
[509]404
405
[219]406      for(int count = 0, indexCount = 0,  l = 0; l < size; l++)
407      {
408         for(int n = 0, i = 0, j = 0; n < data_n_index; n++, count++)
409         {
[369]410            int temp_i = data_i_index(n) + data_ibegin,
[219]411                temp_j = (data_dim == 1) ? -1
[369]412                       : data_j_index(n) + data_jbegin;
[266]413            i = (data_dim == 1) ? (temp_i - 1) % ni
[219]414                                : (temp_i - 1) ;
[266]415            j = (data_dim == 1) ? (temp_i - 1) / ni
[219]416                                : (temp_j - 1) ;
417
[351]418            if ((l >= lbegin && l <= lend) &&
419                (i >= 0 && i < ni) &&
[415]420                (j >= 0 && j < nj) && mask(i,j,l))
[219]421            {
[369]422               (*storeIndex[0])(indexCount) = count ;
423               (*out_l_index[0])(indexCount) = l ;
424               (*out_i_index[0])(indexCount) = i ;
425               (*out_j_index[0])(indexCount) = j ;
[509]426
[369]427               storeIndex_client(indexCount) = count ;
428               out_i_client(indexCount)=i+domain->ibegin_client-1 ;
429               out_j_client(indexCount)=j+domain->jbegin_client-1 ;
430               out_l_client(indexCount)=l-lbegin ;
[219]431               indexCount++ ;
432            }
433         }
434      }
[509]435      computeDomConServer();
436//      sendIndex() ;
[266]437
438
[219]439   }
440
441   //----------------------------------------------------------------
442
[347]443   CGrid* CGrid::createGrid(CDomain* domain)
[219]444   {
445      StdString new_id = StdString("__") + domain->getId() + StdString("__") ;
[347]446      CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ;
[219]447      grid->domain_ref.setValue(domain->getId());
448      return (grid);
449   }
450
[347]451   CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis)
[219]452   {
453      StdString new_id = StdString("__") + domain->getId() +
454                         StdString("_") + axis->getId() + StdString("__") ;
[347]455      CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ;
[219]456      grid->domain_ref.setValue(domain->getId());
457      grid->axis_ref.setValue(axis->getId());
458      return (grid);
459   }
460
461   //----------------------------------------------------------------
462
[509]463   void CGrid::outputField(int rank, const CArray<double, 1>& stored,  CArray<double, 3>& field)
[219]464   {
[369]465      CArray<int,1>& out_i=*out_i_fromClient[rank] ;
466      CArray<int,1>& out_j=*out_j_fromClient[rank] ;
467      CArray<int,1>& out_l=*out_l_fromClient[rank] ;
[509]468
[369]469      for(StdSize n = 0; n < stored.numElements(); n++)
470         field(out_i(n), out_j(n), out_l(n)) = stored(n) ;
[219]471   }
472
[509]473   void CGrid::outputField(int rank, const CArray<double, 1>& stored,  CArray<double, 2>& field)
[300]474   {
[369]475      CArray<int,1>& out_i=*out_i_fromClient[rank] ;
476      CArray<int,1>& out_j=*out_j_fromClient[rank] ;
[509]477
[369]478      for(StdSize n = 0; n < stored.numElements(); n++)
479         field(out_i(n), out_j(n)) = stored(n) ;   }
[219]480
481   //---------------------------------------------------------------
482
[369]483   void CGrid::outputField(int rank,const CArray<double, 1>& stored,  CArray<double, 1>& field)
[219]484   {
[369]485      CArray<int,1>& out_i=*out_i_fromClient[rank] ;
[509]486
[369]487      for(StdSize n = 0; n < stored.numElements(); n++)
488         field(out_i(n)) = stored(n) ;
[219]489   }
490
491   //----------------------------------------------------------------
492
[509]493
[219]494   void CGrid::storeField_arr
[369]495      (const double * const data, CArray<double, 1>& stored) const
[219]496   {
[369]497      const StdSize size = storeIndex_client.numElements() ;
[300]498
[369]499      stored.resize(size) ;
500      for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)] ;
[219]501   }
[509]502
[219]503   //---------------------------------------------------------------
504
[509]505//  void CGrid::sendIndex(void)
506//  {
507//    CContext* context = CContext::getCurrent() ;
508//    CContextClient* client=context->client ;
509//
510//    CEventClient event(getType(),EVENT_ID_INDEX) ;
511//    int rank ;
512//    list<shared_ptr<CMessage> > list_msg ;
513//    list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ;
514//
515//    for(int ns=0;ns<domain->connectedServer.size();ns++)
516//    {
517//       rank=domain->connectedServer[ns] ;
518//
519//       int i,j ;
520//       int nb=0 ;
521//       for(int k=0;k<storeIndex_client.numElements();k++)
522//       {
523//         i=out_i_client(k)- domain->ibegin +1;
524//         j=out_j_client(k)- domain->jbegin +1;
525//         if (domain->mapConnectedServer(i,j)==ns)  nb++ ;
526//       }
527//
528//       CArray<int,1> storeIndex(nb) ;
529//       CArray<int,1> out_i(nb) ;
530//       CArray<int,1> out_j(nb) ;
531//       CArray<int,1> out_l(nb) ;
532//
533//
534//       nb=0 ;
535//       for(int k=0;k<storeIndex_client.numElements();k++)
536//       {
537//         i=out_i_client(k)- domain->ibegin +1 ;
538//         j=out_j_client(k)- domain->jbegin +1 ;
539//         if (domain->mapConnectedServer(i,j)==ns)
540//         {
541//            storeIndex(nb)=k ;
542//            out_i(nb)=domain->i_index(i,j) + domain->ibegin-1;
543//            out_j(nb)=domain->j_index(i,j) + domain->jbegin-1;
544//            out_l(nb)=out_l_client(k) ;
545//            nb++ ;
546//         }
547//       }
548//
549//       storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ;
550//       nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ;
551//       list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ;
552//       list_out_i.push_back(new CArray<int,1>(out_i)) ;
553//       list_out_j.push_back(new CArray<int,1>(out_j)) ;
554//       list_out_l.push_back(new CArray<int,1>(out_l)) ;
555//
556//       *list_msg.back()<<getId()<<*list_out_i.back()<<*list_out_j.back()<<*list_out_l.back() ;
557//       event.push(rank,domain->nbSenders[ns],*list_msg.back()) ;
558//    }
559//    client->sendEvent(event) ;
560//
561//    for(list<CArray<int,1>* >::iterator it=list_out_i.begin();it!=list_out_i.end();it++) delete *it ;
562//    for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ;
563//    for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ;
564//
565//  }
566
567  void CGrid::computeDomConServer()
568  {
569    if (!isDomConServerComputed_)
570    {
571      for(int ns=0;ns<domain->connectedServer.size(); ++ns)
572      {
573         int rank=domain->connectedServer[ns] ;
574
575         int i,j ;
576         int nb=0 ;
577         for(int k=0;k<storeIndex_client.numElements();++k)
578         {
579           i=out_i_client(k)- domain->ibegin +1;
580           j=out_j_client(k)- domain->jbegin +1;
581           if (domain->mapConnectedServer(i,j)==ns)  ++nb ;
582         }
583
584         domConnectedServerSide_.insert(std::make_pair(rank, nb));
585      }
586      isDomConServerComputed_ = true;
587    }
588  }
589
590
591  std::map<int, int> CGrid::getDomConServerSide()
592  {
593    return domConnectedServerSide_;
594  }
595
[300]596  void CGrid::sendIndex(void)
597  {
[347]598    CContext* context = CContext::getCurrent() ;
[300]599    CContextClient* client=context->client ;
[509]600
[300]601    CEventClient event(getType(),EVENT_ID_INDEX) ;
602    int rank ;
603    list<shared_ptr<CMessage> > list_msg ;
[369]604    list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ;
[509]605
606    if (!isDomConServerComputed_) computeDomConServer();
607
[300]608    for(int ns=0;ns<domain->connectedServer.size();ns++)
609    {
610       rank=domain->connectedServer[ns] ;
[509]611
612       int nb = domConnectedServerSide_.find(rank)->second;
[369]613       CArray<int,1> storeIndex(nb) ;
614       CArray<int,1> out_i(nb) ;
615       CArray<int,1> out_j(nb) ;
616       CArray<int,1> out_l(nb) ;
[509]617
618       int i, j;
[300]619       nb=0 ;
[369]620       for(int k=0;k<storeIndex_client.numElements();k++)
[300]621       {
[467]622         i=out_i_client(k)- domain->ibegin +1 ;
623         j=out_j_client(k)- domain->jbegin +1 ;
624         if (domain->mapConnectedServer(i,j)==ns)
[300]625         {
[369]626            storeIndex(nb)=k ;
[467]627            out_i(nb)=domain->i_index(i,j) + domain->ibegin-1;
[509]628            out_j(nb)=domain->j_index(i,j) + domain->jbegin-1;
[369]629            out_l(nb)=out_l_client(k) ;
[300]630            nb++ ;
631         }
632       }
[509]633
[369]634       storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ;
[300]635       nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ;
636       list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ;
[369]637       list_out_i.push_back(new CArray<int,1>(out_i)) ;
638       list_out_j.push_back(new CArray<int,1>(out_j)) ;
639       list_out_l.push_back(new CArray<int,1>(out_l)) ;
[300]640
[369]641       *list_msg.back()<<getId()<<*list_out_i.back()<<*list_out_j.back()<<*list_out_l.back() ;
[300]642       event.push(rank,domain->nbSenders[ns],*list_msg.back()) ;
643    }
644    client->sendEvent(event) ;
[369]645
646    for(list<CArray<int,1>* >::iterator it=list_out_i.begin();it!=list_out_i.end();it++) delete *it ;
647    for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ;
648    for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ;
[509]649
[300]650  }
[509]651
[300]652  void CGrid::recvIndex(CEventServer& event)
653  {
654    list<CEventServer::SSubEvent>::iterator it ;
655    for (it=event.subEvents.begin();it!=event.subEvents.end();++it)
656    {
657      int rank=it->rank;
658      CBufferIn* buffer=it->buffer;
659      string domainId ;
660      *buffer>>domainId ;
661      get(domainId)->recvIndex(rank,*buffer) ;
662    }
663  }
[509]664
[300]665  void CGrid::recvIndex(int rank, CBufferIn& buffer)
666  {
[369]667    CArray<int,1> out_i ;
668    CArray<int,1> out_j ;
669    CArray<int,1> out_l ;
[509]670
[300]671    buffer>>out_i>>out_j>>out_l ;
[509]672
[369]673    out_i -= domain->zoom_ibegin_srv-1 ;
674    out_j -= domain->zoom_jbegin_srv-1 ;
[509]675
[369]676    out_i_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_i) )) ;
677    out_j_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_j) )) ;
678    out_l_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_l) )) ;
[300]679  }
680
681  bool CGrid::dispatchEvent(CEventServer& event)
682  {
[509]683
[300]684    if (SuperClass::dispatchEvent(event)) return true ;
685    else
686    {
687      switch(event.type)
688      {
689        case EVENT_ID_INDEX :
690          recvIndex(event) ;
691          return true ;
692          break ;
[509]693
[300]694        default :
695          ERROR("bool CDomain::dispatchEvent(CEventServer& event)",
696                <<"Unknown Event") ;
697          return false ;
698      }
699    }
700  }
701
[369]702   void CGrid::inputFieldServer(const std::deque< CArray<double, 1>* > storedClient, CArray<double, 1>&  storedServer) const
[219]703   {
704      if ((this->storeIndex.size()-1 ) != storedClient.size())
[369]705         ERROR("void CGrid::inputFieldServer(const std::deque< CArray<double, 1>* > storedClient, CArray<double, 1>&  storedServer) const",
[421]706                << "[ Expected received field = " << (this->storeIndex.size()-1) << ", "
707                << "[ received fiedl = "    << storedClient.size() << "] "
708                << "Data from clients are missing!") ;
[369]709      storedServer.resize(storeIndex[0]->numElements());
[509]710
[219]711      for (StdSize i = 0, n = 0; i < storedClient.size(); i++)
[369]712         for (StdSize j = 0; j < storedClient[i]->numElements(); j++)
713            storedServer(n++) = (*storedClient[i])(j);
[219]714   }
715
[369]716   void CGrid::outputFieldToServer(CArray<double,1>& fieldIn, int rank, CArray<double,1>& fieldOut)
[300]717   {
[369]718     CArray<int,1>& index = *storeIndex_toSrv[rank] ;
719     int nb=index.numElements() ;
720     fieldOut.resize(nb) ;
[509]721
[369]722     for(int k=0;k<nb;k++) fieldOut(k)=fieldIn(index(k)) ;
[300]723    }
[219]724   ///---------------------------------------------------------------
725
[335]726} // namespace xios
Note: See TracBrowser for help on using the repository browser.