1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef __EXPLICITMAPPING_HXX__
20 #define __EXPLICITMAPPING_HXX__
32 ExplicitMapping():_numbers(0), _domains(0), _comm_buffer(0) { }
36 if (_domains!=0) delete[] _domains;
37 if (_numbers!=0) delete[] _numbers;
38 if (_comm_buffer!=0) delete[] _comm_buffer;
41 void pushBackElem(std::pair<int,int> idistant)
43 _mapping.push_back(idistant);
46 void setDistantElem(int ilocal, std::pair<int,int> idistant)
48 _mapping[ilocal]=idistant;
51 int nbDistantDomains()
53 if (_distant_domains.empty())
55 for (std::vector <std::pair<int,int> >::const_iterator iter= _mapping.begin();
58 _distant_domains.insert(iter->first);
60 return _distant_domains.size();
63 std::pair <int,int> getDistantNumbering(int ielem)const
65 return _mapping[ielem];
68 int getDistantDomain(int i)
76 int getNbDistantElems(int i)
83 int* serialize(int idproc)
85 _comm_buffer=new int[_mapping.size()*2];
86 std::vector<int> offsets(_distant_domains.size());
88 for (int i=1; i<_distant_domains.size();i++)
89 offsets[i]=offsets[i-1]+_numbers[i-1];
91 for (int i=0; i< _mapping.size(); i++)
93 int offset= offsets[_mapping[i].first];
94 _comm_buffer[offset*2]=idproc;
95 _comm_buffer[offset*2+1]=_mapping[i].second;
96 offsets[_mapping[i].first]++;
101 void unserialize(int nbprocs, int* sizes,int nbtarget, int* targetrank, int* commbuffer)
104 for (int i=0; i< nbprocs; i++)
105 total_size+=sizes[i];
107 _mapping.resize(total_size);
108 _buffer_index=new int[total_size];
110 for (int i=0; i<nbprocs; i++)
111 for (int ielem=0; ielem<sizes[i]; ielem++)
113 _mapping[indmap].first=i;
114 _mapping[indmap].second=commbuffer[indmap*2+1];
115 _buffer_index[indmap]=commbuffer[indmap*2+1];
118 _numbers=new int [nbtarget];
119 _domains=new int [nbtarget];
122 for (int i=0; i<nbtarget; i++)
124 if (sizes[targetrank[i]]>0)
126 _numbers[index]=sizes[targetrank[i]];
131 _send_counts=new int[nbprocs];
132 for (int i=0; i<nbprocs; i++)
133 _send_counts[i]=sizes[i];
136 int* getBufferIndex() const { return _buffer_index; }
137 int* getCounts() const { return _send_counts; }
139 std::vector <std::pair<int,int> > _mapping;
140 std::set<int> _distant_domains;
147 void computeNumbers()
149 std::map <int,int> counts;
152 _numbers=new int[nbDistantDomains()];
153 _domains=new int[nbDistantDomains()];
154 for (int i=0; i< _mapping.size(); i++)
156 if ( counts.find(_mapping[i].first) == counts.end())
157 counts.insert(std::make_pair(_mapping[i].first,1));
159 (counts[_mapping[i].first])++;
162 for (std::map<int,int>::const_iterator iter=counts.begin();
166 _numbers[counter]=iter->second;
167 _domains[counter]=iter->first;