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

Last change on this file since 518 was 518, checked in by mhnguyen, 9 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
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     std::vector<int> nData = domain->nbDataSrv;
174     std::vector<int>::const_iterator itData = nData.begin();
175     StdSize retVal = StdSize(0.0);
176     for (; it != itE; ++it, ++itData)
177     {
178       retVal = (it->second < *itData) ? *itData : it->second;
179       if (this->withAxis) retVal *= this->axis->size.getValue();
180       retVal *= sizeof(double);
181       retVal *= 2.5 * CXios::bufferServerFactorSize; // Secure factor, myterious number
182       ret.insert(make_pair(it->first, retVal));
183     }
184     return ret;
185   }
186
187
188   //---------------------------------------------------------------
189
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)
214   {
215     if (this->isDomainAxisChecked) return;
216
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     }
243//      this->computeIndexServer();
244     this->isChecked = true;
245   }
246
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)",
262                  <<"The mask has not the same size than the local grid"<<endl
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));
265      }
266      else
267      {
268        mask.resize(niu,nju,nlu) ;
269        mask=true  ;
270      }
271
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) ;
276
277
278   }
279
280   //---------------------------------------------------------------
281
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)
318   {
319      if (!domain_ref.isEmpty())
320      {
321         if (CDomain::has(domain_ref.getValue()))
322         {
323            this->domain = CDomain::get(domain_ref.getValue()) ;
324            if (sendAtt) domain->sendCheckedAttributes();
325            else domain->checkAttributesOnClient() ;
326         }
327         else ERROR("CGrid::solveDomainRef(void)",
328                     << "Wrong domain reference") ;
329      }
330      else ERROR("CGrid::solveDomainRef(void)",
331                  << "Domain reference is not defined") ;
332   }
333
334   //---------------------------------------------------------------
335
336   void CGrid::solveAxisRef(bool checkAtt)
337   {
338      if (!axis_ref.isEmpty())
339      {
340         this->withAxis = true ;
341         if (CAxis::get(axis_ref.getValue()))
342         {
343            this->axis = CAxis::get(axis_ref.getValue()) ;
344            axis->checkAttributes() ;
345         }
346         else ERROR("CGrid::solveAxisRef(void)",
347                    << "Wrong axis reference") ;
348      }
349      else withAxis = false ;
350   }
351
352   //---------------------------------------------------------------
353
354   void CGrid::computeIndex(void)
355   {
356
357      const int ni   = domain->ni.getValue() ,
358                nj   = domain->nj.getValue() ,
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 ;
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
370      CArray<int,1> data_i_index = domain->data_i_index ;
371      CArray<int,1> data_j_index = domain->data_j_index ;
372
373
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         {
380            int temp_i = data_i_index(n) + data_ibegin,
381                temp_j = (data_dim == 1) ? -1
382                       : data_j_index(n) + data_jbegin;
383            i = (data_dim == 1) ? (temp_i - 1) % ni
384                                : (temp_i - 1) ;
385            j = (data_dim == 1) ? (temp_i - 1) / ni
386                                : (temp_j - 1) ;
387
388            if ((l >=lbegin && l<= lend) &&
389                (i >= 0 && i < ni) &&
390                (j >= 0 && j < nj) && mask(i,j,l))
391               indexCount++ ;
392         }
393      }
394
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) ;
399
400      storeIndex_client.resize(indexCount) ;
401      out_i_client.resize(indexCount) ;
402      out_j_client.resize(indexCount) ;
403      out_l_client.resize(indexCount) ;
404
405
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         {
410            int temp_i = data_i_index(n) + data_ibegin,
411                temp_j = (data_dim == 1) ? -1
412                       : data_j_index(n) + data_jbegin;
413            i = (data_dim == 1) ? (temp_i - 1) % ni
414                                : (temp_i - 1) ;
415            j = (data_dim == 1) ? (temp_i - 1) / ni
416                                : (temp_j - 1) ;
417
418            if ((l >= lbegin && l <= lend) &&
419                (i >= 0 && i < ni) &&
420                (j >= 0 && j < nj) && mask(i,j,l))
421            {
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 ;
426
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 ;
431               indexCount++ ;
432            }
433         }
434      }
435      computeDomConServer();
436//      sendIndex() ;
437
438
439   }
440
441   //----------------------------------------------------------------
442
443   CGrid* CGrid::createGrid(CDomain* domain)
444   {
445      StdString new_id = StdString("__") + domain->getId() + StdString("__") ;
446      CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ;
447      grid->domain_ref.setValue(domain->getId());
448      return (grid);
449   }
450
451   CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis)
452   {
453      StdString new_id = StdString("__") + domain->getId() +
454                         StdString("_") + axis->getId() + StdString("__") ;
455      CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ;
456      grid->domain_ref.setValue(domain->getId());
457      grid->axis_ref.setValue(axis->getId());
458      return (grid);
459   }
460
461   //----------------------------------------------------------------
462
463   void CGrid::outputField(int rank, const CArray<double, 1>& stored,  CArray<double, 3>& field)
464   {
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] ;
468
469      for(StdSize n = 0; n < stored.numElements(); n++)
470         field(out_i(n), out_j(n), out_l(n)) = stored(n) ;
471   }
472
473   void CGrid::outputField(int rank, const CArray<double, 1>& stored,  CArray<double, 2>& field)
474   {
475      CArray<int,1>& out_i=*out_i_fromClient[rank] ;
476      CArray<int,1>& out_j=*out_j_fromClient[rank] ;
477
478      for(StdSize n = 0; n < stored.numElements(); n++)
479         field(out_i(n), out_j(n)) = stored(n) ;   }
480
481   //---------------------------------------------------------------
482
483   void CGrid::outputField(int rank,const CArray<double, 1>& stored,  CArray<double, 1>& field)
484   {
485      CArray<int,1>& out_i=*out_i_fromClient[rank] ;
486
487      for(StdSize n = 0; n < stored.numElements(); n++)
488         field(out_i(n)) = stored(n) ;
489   }
490
491   //----------------------------------------------------------------
492
493
494   void CGrid::storeField_arr
495      (const double * const data, CArray<double, 1>& stored) const
496   {
497      const StdSize size = storeIndex_client.numElements() ;
498
499      stored.resize(size) ;
500      for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)] ;
501   }
502
503   //---------------------------------------------------------------
504
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
596  void CGrid::sendIndex(void)
597  {
598    CContext* context = CContext::getCurrent() ;
599    CContextClient* client=context->client ;
600
601    CEventClient event(getType(),EVENT_ID_INDEX) ;
602    int rank ;
603    list<shared_ptr<CMessage> > list_msg ;
604    list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ;
605
606    if (!isDomConServerComputed_) computeDomConServer();
607
608    for(int ns=0;ns<domain->connectedServer.size();ns++)
609    {
610       rank=domain->connectedServer[ns] ;
611
612       int nb = domConnectedServerSide_.find(rank)->second;
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) ;
617
618       int i, j;
619       nb=0 ;
620       for(int k=0;k<storeIndex_client.numElements();k++)
621       {
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)
625         {
626            storeIndex(nb)=k ;
627            out_i(nb)=domain->i_index(i,j) + domain->ibegin-1;
628            out_j(nb)=domain->j_index(i,j) + domain->jbegin-1;
629            out_l(nb)=out_l_client(k) ;
630            nb++ ;
631         }
632       }
633
634       storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ;
635       nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ;
636       list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ;
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)) ;
640
641       *list_msg.back()<<getId()<<*list_out_i.back()<<*list_out_j.back()<<*list_out_l.back() ;
642       event.push(rank,domain->nbSenders[ns],*list_msg.back()) ;
643    }
644    client->sendEvent(event) ;
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 ;
649
650  }
651
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  }
664
665  void CGrid::recvIndex(int rank, CBufferIn& buffer)
666  {
667    CArray<int,1> out_i ;
668    CArray<int,1> out_j ;
669    CArray<int,1> out_l ;
670
671    buffer>>out_i>>out_j>>out_l ;
672
673    out_i -= domain->zoom_ibegin_srv-1 ;
674    out_j -= domain->zoom_jbegin_srv-1 ;
675
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) )) ;
679  }
680
681  bool CGrid::dispatchEvent(CEventServer& event)
682  {
683
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 ;
693
694        default :
695          ERROR("bool CDomain::dispatchEvent(CEventServer& event)",
696                <<"Unknown Event") ;
697          return false ;
698      }
699    }
700  }
701
702   void CGrid::inputFieldServer(const std::deque< CArray<double, 1>* > storedClient, CArray<double, 1>&  storedServer) const
703   {
704      if ((this->storeIndex.size()-1 ) != storedClient.size())
705         ERROR("void CGrid::inputFieldServer(const std::deque< CArray<double, 1>* > storedClient, CArray<double, 1>&  storedServer) const",
706                << "[ Expected received field = " << (this->storeIndex.size()-1) << ", "
707                << "[ received fiedl = "    << storedClient.size() << "] "
708                << "Data from clients are missing!") ;
709      storedServer.resize(storeIndex[0]->numElements());
710
711      for (StdSize i = 0, n = 0; i < storedClient.size(); i++)
712         for (StdSize j = 0; j < storedClient[i]->numElements(); j++)
713            storedServer(n++) = (*storedClient[i])(j);
714   }
715
716   void CGrid::outputFieldToServer(CArray<double,1>& fieldIn, int rank, CArray<double,1>& fieldOut)
717   {
718     CArray<int,1>& index = *storeIndex_toSrv[rank] ;
719     int nb=index.numElements() ;
720     fieldOut.resize(nb) ;
721
722     for(int k=0;k<nb;k++) fieldOut(k)=fieldIn(index(k)) ;
723    }
724   ///---------------------------------------------------------------
725
726} // namespace xios
Note: See TracBrowser for help on using the repository browser.