1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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
20 #ifndef __EXPLICITMAPPING_HXX__
21 #define __EXPLICITMAPPING_HXX__
33 ExplicitMapping():_numbers(0), _domains(0), _comm_buffer(0) { }
37 if (_domains!=0) delete[] _domains;
38 if (_numbers!=0) delete[] _numbers;
39 if (_comm_buffer!=0) delete[] _comm_buffer;
42 void pushBackElem(std::pair<int,int> idistant)
44 _mapping.push_back(idistant);
47 void setDistantElem(int ilocal, std::pair<int,int> idistant)
49 _mapping[ilocal]=idistant;
52 int nbDistantDomains()
54 if (_distant_domains.empty())
56 for (std::vector <std::pair<int,int> >::const_iterator iter= _mapping.begin();
59 _distant_domains.insert(iter->first);
61 return _distant_domains.size();
64 std::pair <int,int> getDistantNumbering(int ielem)const
66 return _mapping[ielem];
69 int getDistantDomain(int i)
77 int getNbDistantElems(int i)
84 int* serialize(int idproc)
86 _comm_buffer=new int[_mapping.size()*2];
87 std::vector<int> offsets(_distant_domains.size());
89 for (int i=1; i<(int)_distant_domains.size();i++)
90 offsets[i]=offsets[i-1]+_numbers[i-1];
92 for (int i=0; i<(int)_mapping.size(); i++)
94 int offset= offsets[_mapping[i].first];
95 _comm_buffer[offset*2]=idproc;
96 _comm_buffer[offset*2+1]=_mapping[i].second;
97 offsets[_mapping[i].first]++;
102 void unserialize(int nbprocs, int* sizes,int nbtarget, int* targetrank, int* commbuffer)
105 for (int i=0; i< nbprocs; i++)
106 total_size+=sizes[i];
108 _mapping.resize(total_size);
109 _buffer_index=new int[total_size];
111 for (int i=0; i<nbprocs; i++)
112 for (int ielem=0; ielem<sizes[i]; ielem++)
114 _mapping[indmap].first=i;
115 _mapping[indmap].second=commbuffer[indmap*2+1];
116 _buffer_index[indmap]=commbuffer[indmap*2+1];
119 _numbers=new int [nbtarget];
120 _domains=new int [nbtarget];
123 for (int i=0; i<nbtarget; i++)
125 if (sizes[targetrank[i]]>0)
127 _numbers[index]=sizes[targetrank[i]];
132 _send_counts=new int[nbprocs];
133 for (int i=0; i<nbprocs; i++)
134 _send_counts[i]=sizes[i];
137 int* getBufferIndex() const { return _buffer_index; }
138 int* getCounts() const { return _send_counts; }
140 std::vector <std::pair<int,int> > _mapping;
141 std::set<int> _distant_domains;
148 void computeNumbers()
150 std::map <int,int> counts;
153 _numbers=new int[nbDistantDomains()];
154 _domains=new int[nbDistantDomains()];
155 for (int i=0; i<(int)_mapping.size(); i++)
157 if ( counts.find(_mapping[i].first) == counts.end())
158 counts.insert(std::make_pair(_mapping[i].first,1));
160 (counts[_mapping[i].first])++;
163 for (std::map<int,int>::const_iterator iter=counts.begin();
167 _numbers[counter]=iter->second;
168 _domains[counter]=iter->first;