$treeview $search $mathjax
Palabos  Version 1.1
$projectbrief
$projectbrief
$searchbox

threadAttribution.h

Go to the documentation of this file.
00001 /* This file is part of the Palabos library.
00002  *
00003  * Copyright (C) 2011 FlowKit Sarl
00004  * Avenue de Chailly 23
00005  * 1012 Lausanne, Switzerland
00006  * E-mail contact: contact@flowkit.com
00007  *
00008  * The most recent release of Palabos can be downloaded at 
00009  * <http://www.palabos.org/>
00010  *
00011  * The library Palabos is free software: you can redistribute it and/or
00012  * modify it under the terms of the GNU Affero General Public License as
00013  * published by the Free Software Foundation, either version 3 of the
00014  * License, or (at your option) any later version.
00015  *
00016  * The library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Affero General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Affero General Public License
00022  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 
00029 #ifndef THREAD_ATTRIBUTION_H
00030 #define THREAD_ATTRIBUTION_H
00031 
00032 #include "core/globalDefs.h"
00033 #include <map>
00034 #include <vector>
00035 
00036 namespace plb {
00037 
00038 struct ThreadAttribution {
00039     virtual ~ThreadAttribution() { }
00041     virtual bool isLocal(plint blockId) const =0;
00044     virtual bool allBlocksAreLocal() const =0;
00046     virtual int getMpiProcess(plint blockId) const =0;
00049     virtual int getLocalThreadId(plint blockId) const =0;
00053     virtual ThreadAttribution* merge (
00054               ThreadAttribution const& rhs,
00055               std::map<plint,std::vector<plint> > const& remappedIds ) const =0;
00058     virtual ThreadAttribution* extend (
00059               std::vector<plint> const& ids,
00060               std::vector<plint> const& mpiProcesses, std::vector<plint> const& localThreads ) const =0;
00061     virtual bool hasCoProcessors() const { return false; }
00062     virtual void setCoProcessors(std::map<plint,int> processorHandles) { }
00063     virtual int getCoProcessorHandle(plint id) const { return 0; }
00064     virtual ThreadAttribution* clone() const =0;
00065 };
00066 
00067 struct SerialThreadAttribution : public ThreadAttribution {
00068     virtual bool isLocal(plint blockId) const;
00069     virtual bool allBlocksAreLocal() const;
00070     virtual int getMpiProcess(plint blockId) const;
00071     virtual int getLocalThreadId(plint blockId) const;
00072     virtual ThreadAttribution* merge (
00073               ThreadAttribution const& rhs,
00074               std::map<plint,std::vector<plint> > const& remappedIds ) const;
00075     virtual ThreadAttribution* extend (
00076               std::vector<plint> const& ids,
00077               std::vector<plint> const& mpiProcesses, std::vector<plint> const& localThreads ) const;
00078     virtual ThreadAttribution* clone() const;
00079 };
00080 
00081 struct OneToOneThreadAttribution : public ThreadAttribution {
00082     virtual bool isLocal(plint blockId) const;
00083     virtual bool allBlocksAreLocal() const;
00084     virtual int getMpiProcess(plint blockId) const;
00085     virtual int getLocalThreadId(plint blockId) const;
00086     virtual ThreadAttribution* merge (
00087               ThreadAttribution const& rhs,
00088               std::map<plint,std::vector<plint> > const& remappedIds ) const;
00089     virtual ThreadAttribution* extend (
00090               std::vector<plint> const& ids,
00091               std::vector<plint> const& mpiProcesses, std::vector<plint> const& localThreads ) const;
00092     virtual ThreadAttribution* clone() const;
00093 };
00094 
00095 class ExplicitThreadAttribution : public ThreadAttribution {
00096 public:
00097     ExplicitThreadAttribution();
00098     ExplicitThreadAttribution(std::map<plint,plint> const& mpiProcessAttribution_);
00099     ExplicitThreadAttribution(std::map<plint,plint> const& mpiProcessAttribution_,
00100                               std::map<plint,plint> const& localThreadAttribution_ );
00101     void addBlock(plint blockId, plint mpiProcess, plint localThread=0);
00102     virtual bool isLocal(plint blockId) const;
00103     virtual bool allBlocksAreLocal() const;
00104     virtual int getMpiProcess(plint blockId) const;
00105     virtual int getLocalThreadId(plint blockId) const;
00106     virtual ThreadAttribution* merge (
00107               ThreadAttribution const& rhs,
00108               std::map<plint,std::vector<plint> > const& remappedIds ) const;
00109     virtual ThreadAttribution* extend (
00110               std::vector<plint> const& ids,
00111               std::vector<plint> const& mpiProcesses, std::vector<plint> const& localThreads ) const; 
00112     virtual bool hasCoProcessors() const {
00113         return !coProcessors.empty();
00114     }
00115     virtual void setCoProcessors(std::map<plint,int> processorHandles) {
00116         coProcessors = processorHandles;
00117     }
00118     virtual int getCoProcessorHandle(plint id) const {
00119         std::map<plint,int>::const_iterator it = coProcessors.find(id);
00120         if (it==coProcessors.end()) {
00121             return -1;
00122         }
00123         else {
00124             return it->second;
00125         }
00126     }
00127     virtual ThreadAttribution* clone() const;
00128 private:
00129     std::map<plint,plint> mpiProcessAttribution;
00130     std::map<plint,plint> localThreadAttribution;
00131     std::map<plint,int> coProcessors;
00132 };
00133 
00134 }  // namespace plb
00135 
00136 #endif  // THREAD_ATTRIBUTION_H