Skip to content

Commit 2bc1821

Browse files
committed
Seperate function for MPI specific operations
1 parent d0e78c7 commit 2bc1821

2 files changed

Lines changed: 55 additions & 49 deletions

File tree

Common/include/grid_movement/CRadialBasisFunctionInterpolation.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class CRadialBasisFunctionInterpolation : public CVolumetricMovement {
6969
unsigned long Local_nControlNodes;
7070
vector<unsigned long> Local_nControlNodesVec;
7171

72-
vector<su2double> LocalCoords;
72+
// vector<su2double> LocalCoords;
7373
vector<su2double> GlobalCoords;
7474

7575

@@ -172,4 +172,6 @@ class CRadialBasisFunctionInterpolation : public CVolumetricMovement {
172172
void GreedyIteration(CGeometry* geometry, CConfig* config);
173173

174174
void GetInitMaxErrorNode(CGeometry* geometry, CConfig* config);
175+
176+
void MPI_Operations(CGeometry* geometry);
175177
};

Common/src/grid_movement/CRadialBasisFunctionInterpolation.cpp

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,7 @@ void CRadialBasisFunctionInterpolation::GetInterpolationCoefficients(CGeometry*
143143

144144

145145
#ifdef HAVE_MPI
146-
Local_nControlNodes = controlNodes->size();
147-
148-
Local_nControlNodesVec.resize(size);
149-
/*--- gathering local control node coordinate sizes on all processes. ---*/
150-
SU2_MPI::Allgather(&Local_nControlNodes, 1, MPI_UNSIGNED_LONG, Local_nControlNodesVec.data(), 1, MPI_UNSIGNED_LONG, SU2_MPI::GetComm());
151-
152-
153-
Global_nControlNodes = 0;
154-
for( auto& n : Local_nControlNodesVec) Global_nControlNodes += n;
155-
146+
MPI_Operations(geometry);
156147
#endif
157148

158149

@@ -232,45 +223,7 @@ void CRadialBasisFunctionInterpolation::SetInterpolationMatrix(CGeometry* geomet
232223
/*--- In case of parallel computation, the interpolation coefficients are computed on the master node.
233224
In order to do so the coordinates of all control nodes are collected on the master node ---*/
234225

235-
#ifdef HAVE_MPI
236-
237-
/*--- array containing the global control node coordinates. ---*/
238-
GlobalCoords.resize(Global_nControlNodes*nDim);
239-
240-
/*--- array containing the local control node coordinates. ---*/
241-
LocalCoords.resize(Local_nControlNodes*nDim);
242-
243-
/*--- storing local control node coordinates ---*/
244-
for(iNode = 0; iNode < controlNodes->size(); iNode++){
245-
auto coord = geometry->nodes->GetCoord((*controlNodes)[iNode]->GetIndex());
246-
for ( unsigned short iDim = 0 ; iDim < nDim; iDim++ ){
247-
LocalCoords[ iNode * nDim + iDim ] = coord[iDim];
248-
}
249-
}
250-
251-
/*--- array containing size of local control node coordinates. ---*/
252-
int LocalCoordsSizes[SU2_MPI::GetSize()];
253-
254-
int localCoordsSize = LocalCoords.size();
255-
/*--- gathering local control node coordinate sizes on all processes. ---*/
256-
SU2_MPI::Allgather(&localCoordsSize, 1, MPI_INT, LocalCoordsSizes, 1, MPI_INT, SU2_MPI::GetComm());
257-
258-
259-
/*--- array containing the starting indices for the allgatherv operation*/
260-
int disps[SU2_MPI::GetSize()];
261-
262-
for(auto x = 0; x < SU2_MPI::GetSize(); x++){
263-
if(x == 0){
264-
disps[x] = 0;
265-
}else{
266-
disps[x] = disps[x-1]+LocalCoordsSizes[x-1];
267-
}
268-
}
269-
270-
/*--- making global control node coordinates available on all processes ---*/
271-
SU2_MPI::Allgatherv(LocalCoords.data(), localCoordsSize, MPI_DOUBLE, GlobalCoords.data(), LocalCoordsSizes, disps, MPI_DOUBLE, SU2_MPI::GetComm()); //TODO local coords can be deleted after this operation
272226

273-
#endif
274227

275228
if(rank == MASTER_NODE){
276229
/*--- Initialization of the interpolation matrix ---*/
@@ -598,3 +551,54 @@ void CRadialBasisFunctionInterpolation::GetInitMaxErrorNode(CGeometry* geometry,
598551
MaxError = sqrt(maxDeformation) / ((su2double)config->GetGridDef_Nonlinear_Iter());
599552
// cout << "rank: " << rank << " Max error node: " << MaxErrorNode << endl;
600553
}
554+
555+
556+
void CRadialBasisFunctionInterpolation::MPI_Operations(CGeometry* geometry){
557+
Local_nControlNodes = controlNodes->size();
558+
559+
Local_nControlNodesVec.resize(size);
560+
561+
/*--- gathering local control node coordinate sizes on all processes. ---*/
562+
SU2_MPI::Allgather(&Local_nControlNodes, 1, MPI_UNSIGNED_LONG, Local_nControlNodesVec.data(), 1, MPI_UNSIGNED_LONG, SU2_MPI::GetComm());
563+
564+
565+
Global_nControlNodes = 0;
566+
for( auto& n : Local_nControlNodesVec) Global_nControlNodes += n;
567+
568+
/*--- array containing the global control node coordinates. ---*/
569+
GlobalCoords.resize(Global_nControlNodes*nDim);
570+
571+
/*--- array containing the local control node coordinates. ---*/
572+
vector<su2double> LocalCoords(nDim*Local_nControlNodes);
573+
574+
575+
/*--- storing local control node coordinates ---*/
576+
for(unsigned long iNode = 0; iNode < controlNodes->size(); iNode++){
577+
auto coord = geometry->nodes->GetCoord((*controlNodes)[iNode]->GetIndex());
578+
for ( unsigned short iDim = 0 ; iDim < nDim; iDim++ ){
579+
LocalCoords[ iNode * nDim + iDim ] = coord[iDim];
580+
}
581+
}
582+
583+
/*--- array containing size of local control node coordinates. ---*/
584+
int LocalCoordsSizes[SU2_MPI::GetSize()];
585+
586+
int localCoordsSize = LocalCoords.size();
587+
/*--- gathering local control node coordinate sizes on all processes. ---*/
588+
SU2_MPI::Allgather(&localCoordsSize, 1, MPI_INT, LocalCoordsSizes, 1, MPI_INT, SU2_MPI::GetComm());
589+
590+
591+
/*--- array containing the starting indices for the allgatherv operation*/
592+
int disps[SU2_MPI::GetSize()];
593+
594+
for(auto x = 0; x < SU2_MPI::GetSize(); x++){
595+
if(x == 0){
596+
disps[x] = 0;
597+
}else{
598+
disps[x] = disps[x-1]+LocalCoordsSizes[x-1];
599+
}
600+
}
601+
602+
/*--- making global control node coordinates available on all processes ---*/
603+
SU2_MPI::Allgatherv(LocalCoords.data(), localCoordsSize, MPI_DOUBLE, GlobalCoords.data(), LocalCoordsSizes, disps, MPI_DOUBLE, SU2_MPI::GetComm()); //TODO local coords can be deleted after this operation
604+
};

0 commit comments

Comments
 (0)