Skip to content

Commit 9ec9fe2

Browse files
committed
removed HAVE_MPI and minor fix
1 parent 74ce20b commit 9ec9fe2

File tree

2 files changed

+61
-85
lines changed

2 files changed

+61
-85
lines changed

SU2_CFD/include/output/filewriter/CCGNSFileWriter.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* \file CCGNSFileWriter.hpp
3-
* \brief Headers fo paraview binary file writer class.
3+
* \brief Headers for CGNS file writer class.
44
* \author G. Baldan
55
* \version 7.2.0 "Blackbird"
66
*
@@ -31,9 +31,6 @@
3131
#include "cgnslib.h"
3232
#endif
3333

34-
/*--- Define data precision of output (float or double). ---*/
35-
typedef float dataPrecision;
36-
3734
#include "CFileWriter.hpp"
3835

3936
class CCGNSFileWriter final : public CFileWriter {
@@ -54,14 +51,15 @@ class CCGNSFileWriter final : public CFileWriter {
5451
cgsize_t GlobalPoint; /*!< \brief Total number of points. */
5552
cgsize_t GlobalElem; /*!< \brief Total number of elements. */
5653

54+
typedef float dataPrecision; /*!< \brief Define data precision of output (float or double). */
55+
const DataType_t dataType = RealSingle; /*!< \brief Datatype of fields can be RealSingle or RealDouble. */
56+
5757
vector<cgsize_t> sendBufferConnectivity; /*!< \brief Send buffer for connectivity data. */
5858
vector<cgsize_t> recvBufferConnectivity; /*!< \brief Receive buffer for connectivity data. */
5959
vector<dataPrecision> recvBufferField; /*!< \brief Send buffer for field data. */
6060
vector<dataPrecision> sendBufferField; /*!< \brief Receive buffer for field data. */
6161

6262
cgsize_t cumulative; /*!< \brief Cumulative number of elements written. */
63-
64-
DataType_t dataType; /*!< \brief Datatype of fields can be RealSingle or RealDouble. */
6563
#endif
6664
public:
6765
/*!

SU2_CFD/src/output/filewriter/CCGNSFileWriter.cpp

Lines changed: 57 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
const string CCGNSFileWriter::fileExt = ".cgns";
3131

3232
CCGNSFileWriter::CCGNSFileWriter(string valFileName, CParallelDataSorter* valDataSorter, bool isSurf)
33-
: CFileWriter(std::move(valFileName), valDataSorter, fileExt) {
34-
isSurface = isSurf;
35-
}
33+
: CFileWriter(std::move(valFileName), valDataSorter, fileExt), isSurface(isSurf) {}
3634

3735
void CCGNSFileWriter::Write_Data() {
3836
#ifdef HAVE_CGNS
@@ -62,7 +60,7 @@ void CCGNSFileWriter::Write_Data() {
6260
/*--- Initialize and write fields. ---*/
6361
InitializeFields();
6462

65-
auto& fieldNames = dataSorter->GetFieldNames();
63+
const auto& fieldNames = dataSorter->GetFieldNames();
6664
for (unsigned long i = nDim; i < fieldNames.size(); ++i) {
6765
WriteField(i, fieldNames[i]);
6866
}
@@ -85,15 +83,8 @@ void CCGNSFileWriter::InitializeMeshFile() {
8583
GlobalPoint = static_cast<cgsize_t>(dataSorter->GetnPointsGlobal());
8684
cumulative = 0;
8785

88-
if (typeid(dataPrecision) == typeid(float))
89-
dataType = RealSingle;
90-
else if (typeid(dataPrecision) == typeid(double))
91-
dataType = RealDouble;
92-
else
93-
SU2_MPI::Error("Wrong data type in CGNS output", CURRENT_FUNCTION);
94-
9586
/*--- If surface file cell dimension is decreased. ---*/
96-
auto nCell = static_cast<int>(nDim - isSurface);
87+
const auto nCell = static_cast<int>(nDim - isSurface);
9788

9889
if (rank == MASTER_NODE) {
9990
/*--- Remove the previous file if present. ---*/
@@ -118,8 +109,7 @@ void CCGNSFileWriter::InitializeMeshFile() {
118109

119110
void CCGNSFileWriter::WriteField(int iField, const string& FieldName) {
120111
/*--- Check if field is coordinate. ---*/
121-
bool isCoord = false;
122-
if (FieldName == "CoordinateX" || FieldName == "CoordinateY" || FieldName == "CoordinateZ") isCoord = true;
112+
const bool isCoord = iField < nDim;
123113

124114
/*--- Create send buffer. ---*/
125115
sendBufferField.resize(nLocalPoints);
@@ -128,20 +118,18 @@ void CCGNSFileWriter::WriteField(int iField, const string& FieldName) {
128118
sendBufferField[iPoint] = static_cast<dataPrecision>(dataSorter->GetData(iField, iPoint));
129119
}
130120

131-
#ifdef HAVE_MPI
132121
if (rank != MASTER_NODE) {
133122
SU2_MPI::Send(sendBufferField.data(), nLocalPoints * sizeof(dataPrecision), MPI_CHAR, MASTER_NODE, 0,
134123
SU2_MPI::GetComm());
135124
return;
136125
}
137-
#endif
138126

139127
/*--- Coordinate vector is written in blocks, one for each process. ---*/
140128
cgsize_t nodeBegin = 1;
141129
cgsize_t nodeEnd = static_cast<cgsize_t>(nLocalPoints);
142130

143131
if (isCoord) {
144-
int CoordinateNumber = iField + 1;
132+
int CoordinateNumber;
145133
CallCGNS(cg_coord_partial_write(cgnsFileID, cgnsBase, cgnsZone, dataType, FieldName.c_str(), &nodeBegin, &nodeEnd,
146134
sendBufferField.data(), &CoordinateNumber));
147135
} else {
@@ -150,20 +138,20 @@ void CCGNSFileWriter::WriteField(int iField, const string& FieldName) {
150138
&nodeEnd, sendBufferField.data(), &fieldNumber));
151139
}
152140

153-
#ifdef HAVE_MPI
154141
for (int i = 0; i < size; ++i) {
155142
if (i == MASTER_NODE) continue;
143+
/*--- In CGNS numbering starts form 1 and ranges are inclusive ---*/
156144
nodeBegin = static_cast<cgsize_t>(dataSorter->GetnPointCumulative(i) + 1);
157145
nodeEnd = static_cast<cgsize_t>(dataSorter->GetnPointCumulative(i + 1));
158146

159-
int recvSize = static_cast<int>(nodeEnd - nodeBegin + 1);
147+
const auto recvSize = static_cast<int>(nodeEnd - nodeBegin + 1);
160148
recvBufferField.resize(recvSize);
161149

162150
SU2_MPI::Recv(recvBufferField.data(), recvSize * sizeof(dataPrecision), MPI_CHAR, i, 0, SU2_MPI::GetComm(),
163151
MPI_STATUS_IGNORE);
164152
if (recvSize <= 0) continue;
165153
if (isCoord) {
166-
int CoordinateNumber = iField + 1;
154+
int CoordinateNumber;
167155
CallCGNS(cg_coord_partial_write(cgnsFileID, cgnsBase, cgnsZone, dataType, FieldName.c_str(), &nodeBegin, &nodeEnd,
168156
recvBufferField.data(), &CoordinateNumber));
169157
} else {
@@ -172,81 +160,71 @@ void CCGNSFileWriter::WriteField(int iField, const string& FieldName) {
172160
&nodeBegin, &nodeEnd, recvBufferField.data(), &fieldNumber));
173161
}
174162
}
175-
#endif
176163
}
177164

178165
void CCGNSFileWriter::WriteConnectivity(GEO_TYPE type, const string& SectionName) {
179-
unsigned long nTotElem = dataSorter->GetnElemGlobal(type);
180-
if (nTotElem > 0) {
181-
/*--- Create a new CGNS node to store connectivity. ---*/
182-
ElementType_t elementType = GetCGNSType(type);
166+
const auto nTotElem = dataSorter->GetnElemGlobal(type);
167+
if (nTotElem == 0) return;
183168

184-
cgsize_t firstElem = cumulative + 1;
185-
cgsize_t endElem = cumulative + static_cast<cgsize_t>(nTotElem);
169+
/*--- Create a new CGNS node to store connectivity. ---*/
170+
const auto elementType = GetCGNSType(type);
186171

187-
int cgnsSection;
188-
if (rank == MASTER_NODE)
189-
CallCGNS(cg_section_partial_write(cgnsFileID, cgnsBase, cgnsZone, SectionName.c_str(), elementType, firstElem,
190-
endElem, 0, &cgnsSection));
172+
cgsize_t firstElem = cumulative + 1;
173+
cgsize_t endElem = cumulative + static_cast<cgsize_t>(nTotElem);
191174

192-
/*--- Retrieve element distribution among processes. ---*/
193-
unsigned long nLocalElem = dataSorter->GetnElem(type);
175+
int cgnsSection;
176+
if (rank == MASTER_NODE)
177+
CallCGNS(cg_section_partial_write(cgnsFileID, cgnsBase, cgnsZone, SectionName.c_str(), elementType, firstElem,
178+
endElem, 0, &cgnsSection));
194179

195-
#ifdef HAVE_MPI
196-
vector<unsigned long> distElem;
197-
distElem.resize(size);
180+
/*--- Retrieve element distribution among processes. ---*/
181+
const auto nLocalElem = dataSorter->GetnElem(type);
198182

199-
SU2_MPI::Allgather(&nLocalElem, 1, MPI_UNSIGNED_LONG, distElem.data(), 1, MPI_UNSIGNED_LONG, SU2_MPI::GetComm());
183+
vector<unsigned long> distElem(size);
200184

201-
firstElem = cumulative + 1;
202-
endElem = cumulative + static_cast<cgsize_t>(distElem[rank]);
203-
#else
204-
firstElem = cumulative + 1;
205-
endElem = cumulative + static_cast<cgsize_t>(nLocalElem);
206-
#endif
185+
SU2_MPI::Allgather(&nLocalElem, 1, MPI_UNSIGNED_LONG, distElem.data(), 1, MPI_UNSIGNED_LONG, SU2_MPI::GetComm());
207186

208-
/*--- Connectivity is stored in send buffer. ---*/
209-
unsigned short nPointsElem = nPointsOfElementType(type);
210-
sendBufferConnectivity.resize(nLocalElem * nPointsElem);
187+
firstElem = cumulative + 1;
188+
endElem = cumulative + static_cast<cgsize_t>(distElem[rank]);
211189

212-
for (unsigned long iElem = 0; iElem < nLocalElem; iElem++) {
213-
for (unsigned long iPoint = 0; iPoint < nPointsElem; iPoint++) {
214-
sendBufferConnectivity[iPoint + nPointsElem * iElem] =
215-
static_cast<cgsize_t>(dataSorter->GetElem_Connectivity(type, iElem, iPoint));
216-
}
217-
}
190+
/*--- Connectivity is stored in send buffer. ---*/
191+
const auto nPointsElem = nPointsOfElementType(type);
192+
sendBufferConnectivity.resize(nLocalElem * nPointsElem);
218193

219-
#ifdef HAVE_MPI
220-
auto bufferSize = static_cast<int>(nLocalElem * nPointsElem * sizeof(cgsize_t));
221-
if (rank != MASTER_NODE) {
222-
SU2_MPI::Send(sendBufferConnectivity.data(), bufferSize, MPI_CHAR, MASTER_NODE, 1, SU2_MPI::GetComm());
223-
return;
194+
for (unsigned long iElem = 0; iElem < nLocalElem; iElem++) {
195+
for (unsigned long iPoint = 0; iPoint < nPointsElem; iPoint++) {
196+
sendBufferConnectivity[iPoint + nPointsElem * iElem] =
197+
static_cast<cgsize_t>(dataSorter->GetElem_Connectivity(type, iElem, iPoint));
224198
}
225-
#endif
199+
}
226200

227-
/*--- Connectivity vector is written in blocks, one for each process. ---*/
228-
if (nLocalElem > 0)
201+
const auto bufferSize = static_cast<int>(nLocalElem * nPointsElem * sizeof(cgsize_t));
202+
if (rank != MASTER_NODE) {
203+
SU2_MPI::Send(sendBufferConnectivity.data(), bufferSize, MPI_CHAR, MASTER_NODE, 1, SU2_MPI::GetComm());
204+
return;
205+
}
206+
207+
/*--- Connectivity vector is written in blocks, one for each process. ---*/
208+
if (nLocalElem > 0)
209+
CallCGNS(cg_elements_partial_write(cgnsFileID, cgnsBase, cgnsZone, cgnsSection, firstElem, endElem,
210+
sendBufferConnectivity.data()));
211+
212+
for (int i = 0; i < size; ++i) {
213+
if (i == MASTER_NODE) continue;
214+
/*--- In CGNS numbering starts form 1 and ranges are inclusive ---*/
215+
firstElem += static_cast<cgsize_t>(distElem[i - 1]);
216+
endElem += static_cast<cgsize_t>(distElem[i]);
217+
const auto recvSize = static_cast<int>(endElem - firstElem + 1);
218+
recvBufferConnectivity.resize(recvSize * nPointsElem);
219+
220+
const auto recvByte = static_cast<int>(recvBufferConnectivity.size() * sizeof(cgsize_t));
221+
SU2_MPI::Recv(recvBufferConnectivity.data(), recvByte, MPI_CHAR, i, 1, SU2_MPI::GetComm(), MPI_STATUS_IGNORE);
222+
223+
if (!recvBufferConnectivity.empty())
229224
CallCGNS(cg_elements_partial_write(cgnsFileID, cgnsBase, cgnsZone, cgnsSection, firstElem, endElem,
230-
sendBufferConnectivity.data()));
231-
232-
#ifdef HAVE_MPI
233-
for (int i = 0; i < size; ++i) {
234-
if (i == MASTER_NODE) continue;
235-
firstElem += static_cast<cgsize_t>(distElem[i - 1]);
236-
endElem += static_cast<cgsize_t>(distElem[i]);
237-
int recvSize = static_cast<int>(endElem - firstElem + 1);
238-
recvBufferConnectivity.resize(recvSize * nPointsElem);
239-
240-
auto recvByte = static_cast<int>(recvBufferConnectivity.size() * sizeof(cgsize_t));
241-
SU2_MPI::Recv(recvBufferConnectivity.data(), recvByte, MPI_CHAR, i, 1, SU2_MPI::GetComm(), MPI_STATUS_IGNORE);
242-
243-
if (!recvBufferConnectivity.empty())
244-
CallCGNS(cg_elements_partial_write(cgnsFileID, cgnsBase, cgnsZone, cgnsSection, firstElem, endElem,
245-
recvBufferConnectivity.data()));
246-
}
247-
#endif
248-
cumulative += static_cast<cgsize_t>(nTotElem);
225+
recvBufferConnectivity.data()));
249226
}
227+
cumulative += static_cast<cgsize_t>(nTotElem);
250228
}
251229

252230
void CCGNSFileWriter::InitializeFields() {

0 commit comments

Comments
 (0)