1 // Copyright (C) 2007-2022 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 #include "ExplicitMapping.hxx"
25 ExplicitMapping::ExplicitMapping():
26 _mapping(), _distant_domains(),
27 _numbers(0), _domains(0), _comm_buffer(0),
28 _buffer_index(0), _send_counts(0)
31 ExplicitMapping::~ExplicitMapping()
33 if (_domains!=0) delete[] _domains;
34 if (_numbers!=0) delete[] _numbers;
35 if (_comm_buffer!=0) delete[] _comm_buffer;
38 void ExplicitMapping::pushBackElem(std::pair<int,mcIdType> idistant)
40 _mapping.push_back(idistant);
43 void ExplicitMapping::setDistantElem(mcIdType ilocal, std::pair<int,mcIdType> idistant)
45 _mapping[ilocal]=idistant;
48 int ExplicitMapping::nbDistantDomains()
50 if (_distant_domains.empty())
52 for (std::vector <std::pair<int,mcIdType> >::const_iterator iter= _mapping.begin();
55 _distant_domains.insert(iter->first);
57 return (int)_distant_domains.size();
60 std::pair <int,mcIdType> ExplicitMapping::getDistantNumbering(mcIdType ielem)const
62 return _mapping[ielem];
65 int ExplicitMapping::getDistantDomain(int i)
73 int ExplicitMapping::getNbDistantElems(int i)
80 mcIdType* ExplicitMapping::serialize(int idproc)
82 _comm_buffer=new mcIdType[_mapping.size()*2];
83 std::vector<mcIdType> offsets(_distant_domains.size());
85 for (int i=1; i<(int)_distant_domains.size();i++)
86 offsets[i]=offsets[i-1]+_numbers[i-1];
88 for (int i=0; i<(int)_mapping.size(); i++)
90 mcIdType offset= offsets[_mapping[i].first];
91 _comm_buffer[offset*2]=idproc;
92 _comm_buffer[offset*2+1]=_mapping[i].second;
93 offsets[_mapping[i].first]++;
98 void ExplicitMapping::unserialize(int nbprocs, int* sizes,int nbtarget, int* targetrank, mcIdType* commbuffer)
101 for (int i=0; i< nbprocs; i++)
102 total_size+=sizes[i];
104 _mapping.resize(total_size);
105 _buffer_index=new int[total_size];
107 for (int i=0; i<nbprocs; i++)
108 for (int ielem=0; ielem<sizes[i]; ielem++)
110 _mapping[indmap].first=i;
111 _mapping[indmap].second=commbuffer[indmap*2+1];
112 _buffer_index[indmap]=(int)commbuffer[indmap*2+1];
115 _numbers=new int [nbtarget];
116 _domains=new int [nbtarget];
119 for (int i=0; i<nbtarget; i++)
121 if (sizes[targetrank[i]]>0)
123 _numbers[index]=sizes[targetrank[i]];
128 _send_counts=new int[nbprocs];
129 for (int i=0; i<nbprocs; i++)
130 _send_counts[i]=sizes[i];
133 void ExplicitMapping::computeNumbers()
135 std::map <int,int> counts;
138 _numbers=new int[nbDistantDomains()];
139 _domains=new int[nbDistantDomains()];
140 for (int i=0; i<(int)_mapping.size(); i++)
142 if ( counts.find(_mapping[i].first) == counts.end())
143 counts.insert(std::make_pair(_mapping[i].first,1));
145 (counts[_mapping[i].first])++;
148 for (std::map<int,int>::const_iterator iter=counts.begin();
152 _numbers[counter]=iter->second;
153 _domains[counter]=iter->first;