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

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

Seperating database of context on "client" side and "server" side

+) Add one more context in contex client in case of attached mode
+) Do some minor changements to make sure everything fine in case of attached mode
+) Replace buffer group with the new options

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