ESyS-Particle  4.0.1
CheckedScalarInteractionFieldSlaveTagged.hpp
00001 
00002 //                                                         //
00003 // Copyright (c) 2003-2011 by The University of Queensland //
00004 // Earth Systems Science Computational Centre (ESSCC)      //
00005 // http://www.uq.edu.au/esscc                              //
00006 //                                                         //
00007 // Primary Business: Brisbane, Queensland, Australia       //
00008 // Licensed under the Open Software License version 3.0    //
00009 // http://www.opensource.org/licenses/osl-3.0.php          //
00010 //                                                         //
00012 
00013 //-- STL includes --
00014 #include <vector>
00015 #include <utility>
00016 
00017 using std::vector;
00018 using std::pair;
00019 
00020 // -- IO includes --
00021 #include <iostream>
00022 
00023 using std::cout;
00024 using std::endl;
00025 
00033 template <typename T>
00034 CheckedScalarInteractionFieldSlaveTagged<T>::CheckedScalarInteractionFieldSlaveTagged(TML_Comm* comm,TParallelInteractionStorage<T>* pis,typename T::CheckedScalarFieldFunction rdf,int tag,int mask):CheckedScalarInteractionFieldSlave<T>(comm,pis,rdf)
00035 {
00036         m_tag=tag;
00037         m_mask=mask;
00038 }
00039 
00043 template <typename T>
00044 void CheckedScalarInteractionFieldSlaveTagged<T>::SendDataFull()
00045 {
00046   vector<pair<Vec3,pair<bool,double> > > raw_data;
00047   vector<pair<Vec3,double> > data;
00048 
00049   // get raw field data from interaction storage
00050   raw_data=this->m_pis->forAllTaggedInnerInteractionsGetWithPos(this->m_rdf,m_tag,m_mask);
00051 
00052   // filter data
00053   for(vector<pair<Vec3,pair<bool,double> > >::iterator iter=raw_data.begin();
00054       iter!=raw_data.end();
00055       iter++){
00056     if(iter->second.first){
00057       data.push_back(make_pair(iter->first,iter->second.second));
00058     }
00059   }
00060   
00061   // send data to master
00062   this->m_comm->send_gather(data,0);
00063 }
00064 
00068 template <typename T>
00069 void CheckedScalarInteractionFieldSlaveTagged<T>::SendDataSum()
00070 {
00071         vector<pair<bool,double> >data_vec;
00072 
00073         // get data from interactions
00074         this->m_pis->forAllTaggedInnerInteractionsGet(data_vec,this->m_rdf,m_tag,m_mask);
00075 
00076         // sum data
00077         double sum=0.0;
00078         for(vector<pair<bool,double> >::iterator iter=data_vec.begin();
00079                 iter!=data_vec.end();
00080                 iter++)
00081         {
00082                 if(iter->first) sum+=iter->second;
00083         }
00084 
00085         vector<double> sum_vec;
00086         sum_vec.push_back(sum);
00087         this->m_comm->send_gather(sum_vec,0);
00088 }
00089 
00093 template <typename T>
00094 void CheckedScalarInteractionFieldSlaveTagged<T>::SendDataMax()
00095 {
00096         vector<pair<bool,double> >data_vec;
00097 
00098         // get data from interactions
00099         this->m_pis->forAllTaggedInnerInteractionsGet(data_vec,this->m_rdf,m_tag,m_mask);
00100 
00101         // get max 
00102         double max;
00103         bool is_set=false;
00104         for(vector<pair<bool,double> >::iterator iter=data_vec.begin();
00105             iter!=data_vec.end();
00106             iter++){
00107          if(iter->first) {
00108            if(is_set){
00109                  max=(iter->second > max) ? iter->second : max;
00110           } else {
00111              max=iter->second;
00112              is_set=true;
00113                  }
00114                 }
00115         }
00116 
00117         vector<double> max_vec;
00118         max_vec.push_back(max);
00119         this->m_comm->send_gather(max_vec,0);
00120 }