From 36c1c0cffe46ba3f0ea1c28361cc37817b0a54d2 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Mon, 13 Aug 2018 12:32:56 +0200 Subject: [PATCH] reorganize ifdef'ery to avoid static analyzer errors --- src/ASM/DomainDecomposition.C | 10 ++++++++++ src/ASM/DomainDecomposition.h | 2 ++ src/ASM/LR/ASMu3D.C | 2 +- src/ASM/SAMpatchPETSc.C | 2 ++ src/ASM/SAMpatchPETSc.h | 2 ++ src/Utility/ExprFunctions.C | 10 ++++++---- src/Utility/HDF5Writer.C | 15 +++++++++------ src/Utility/Profiler.C | 2 ++ src/Utility/VTF.C | 18 ++++++++++++------ 9 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/ASM/DomainDecomposition.C b/src/ASM/DomainDecomposition.C index bfc34410..ee35054a 100644 --- a/src/ASM/DomainDecomposition.C +++ b/src/ASM/DomainDecomposition.C @@ -311,6 +311,7 @@ std::vector DomainDecomposition::calcSubdomains3D(size_t nel1, size_t ne } +#ifdef HAVE_MPI void DomainDecomposition::setupNodeNumbers(int basis, IntVec& lNodes, std::set& cbasis, const ASMbase* pch, @@ -356,6 +357,7 @@ void DomainDecomposition::setupNodeNumbers(int basis, IntVec& lNodes, } else pch->getBoundaryNodes(lidx, lNodes, it2, thick, orient, false); } +#endif bool DomainDecomposition::calcGlobalNodeNumbers(const ProcessAdm& adm, @@ -492,6 +494,7 @@ bool DomainDecomposition::calcGlobalNodeNumbers(const ProcessAdm& adm, } +#ifdef HAVE_MPI std::vector DomainDecomposition::setupEquationNumbers(const SIMbase& sim, int pidx, int lidx, const std::set& cbasis, @@ -543,6 +546,7 @@ std::vector DomainDecomposition::setupEquationNumbers(const SIMbase& sim, return result; } +#endif bool DomainDecomposition::calcGlobalEqNumbers(const ProcessAdm& adm, @@ -918,7 +922,9 @@ bool DomainDecomposition::setup(const ProcessAdm& adm, const SIMbase& sim) if (!sanityCheckCorners(sim)) return false; +#ifdef HAVE_MPI ok = 1; +#endif // Establish local equation mappings for each block. if (sim.getSolParams() && sim.getSolParams()->getNoBlocks() > 1) { @@ -968,7 +974,11 @@ bool DomainDecomposition::setup(const ProcessAdm& adm, const SIMbase& sim) // Establish global equation numbers for all blocks. if (!calcGlobalEqNumbers(adm, sim)) +#ifdef HAVE_MPI ok = 0; +#else + return false; +#endif #ifdef HAVE_MPI if (!adm.isParallel()) diff --git a/src/ASM/DomainDecomposition.h b/src/ASM/DomainDecomposition.h index 4c7696d9..7d318f40 100644 --- a/src/ASM/DomainDecomposition.h +++ b/src/ASM/DomainDecomposition.h @@ -173,6 +173,7 @@ private: size_t g1, size_t g2, size_t g3, size_t overlap); +#ifdef HAVE_MPI //! \brief Setup equation numbers for all blocks on a boundary. //! \param sim Simulator with patches and linear solver block information //! \param pidx Patch index @@ -199,6 +200,7 @@ private: std::set& cbasis, const ASMbase* pch, int dim, int lidx, int thick, int orient = 0); +#endif //! \brief Calculate the global node numbers for given finite element model. bool calcGlobalNodeNumbers(const ProcessAdm& adm, const SIMbase& sim); diff --git a/src/ASM/LR/ASMu3D.C b/src/ASM/LR/ASMu3D.C index 373049ab..4d1d9979 100644 --- a/src/ASM/LR/ASMu3D.C +++ b/src/ASM/LR/ASMu3D.C @@ -664,11 +664,11 @@ void ASMu3D::constrainNode (double xi, double eta, double zeta, { std::cerr << "ASMu3D::constrainNode not implemented properly yet" << std::endl; exit(776654); +#if 0 if (xi < 0.0 || xi > 1.0) return; if (eta < 0.0 || eta > 1.0) return; if (zeta < 0.0 || zeta > 1.0) return; -#if 0 int n1, n2, n3; if (!this->getSize(n1,n2,n3,1)) return; diff --git a/src/ASM/SAMpatchPETSc.C b/src/ASM/SAMpatchPETSc.C index 2291b44b..7d9ad69f 100644 --- a/src/ASM/SAMpatchPETSc.C +++ b/src/ASM/SAMpatchPETSc.C @@ -141,6 +141,7 @@ Real SAMpatchPETSc::normInf(const Vector& x, size_t& comp, char dofType) const } +#ifdef HAVE_MPI void SAMpatchPETSc::setupIS(char dofType) const { PetscIntVec ldofs; @@ -169,6 +170,7 @@ void SAMpatchPETSc::setupIS(char dofType) const dofIS[dofType].nDofs = gdof - gdofs.front(); } +#endif bool SAMpatchPETSc::expandSolution(const SystemVector& solVec, diff --git a/src/ASM/SAMpatchPETSc.h b/src/ASM/SAMpatchPETSc.h index 04eb67d9..0af95cbe 100644 --- a/src/ASM/SAMpatchPETSc.h +++ b/src/ASM/SAMpatchPETSc.h @@ -89,8 +89,10 @@ public: Real scaleSD = 1.0) const; private: +#ifdef HAVE_MPI //! \brief Setup a parallel index set for a given dofType void setupIS(char dofType) const; +#endif // Parameters for parallel computing int nProc; //!< Number of processes diff --git a/src/Utility/ExprFunctions.C b/src/Utility/ExprFunctions.C index 27670c3a..281fe8be 100644 --- a/src/Utility/ExprFunctions.C +++ b/src/Utility/ExprFunctions.C @@ -91,9 +91,10 @@ EvalFunc::EvalFunc (const char* function, const char* x, Real eps) : gradient(nullptr), dx(eps) { try { - size_t nalloc = 1; #ifdef USE_OPENMP - nalloc = omp_get_max_threads(); + size_t nalloc = omp_get_max_threads(); +#else + size_t nalloc = 1; #endif expr.resize(nalloc); f.resize(nalloc); @@ -183,9 +184,10 @@ Real EvalFunc::deriv (Real x) const EvalFunction::EvalFunction (const char* function) : gradient{}, dgradient{} { try { - size_t nalloc = 1; #ifdef USE_OPENMP - nalloc = omp_get_max_threads(); + size_t nalloc = omp_get_max_threads(); +#else + size_t nalloc = 1; #endif expr.resize(nalloc); f.resize(nalloc); diff --git a/src/Utility/HDF5Writer.C b/src/Utility/HDF5Writer.C index 3be70b61..132c33c6 100644 --- a/src/Utility/HDF5Writer.C +++ b/src/Utility/HDF5Writer.C @@ -69,11 +69,12 @@ int HDF5Writer::getLastTimeLevel () if (m_flag == H5F_ACC_TRUNC) return -1; - hid_t acc_tpl = H5P_DEFAULT; #ifdef HAVE_MPI MPI_Info info = MPI_INFO_NULL; - acc_tpl = H5Pcreate(H5P_FILE_ACCESS); + hid_t acc_tpl = H5Pcreate(H5P_FILE_ACCESS); H5Pset_fapl_mpio(acc_tpl, MPI_COMM_SELF, info); +#else + hid_t acc_tpl = H5P_DEFAULT; #endif m_file = H5Fopen(m_name.c_str(),m_flag,acc_tpl); @@ -101,11 +102,12 @@ void HDF5Writer::openFile(int level, bool restart) return; int file = 0; #ifdef HAS_HDF5 - hid_t acc_tpl = H5P_DEFAULT; #ifdef HAVE_MPI MPI_Info info = MPI_INFO_NULL; - acc_tpl = H5Pcreate(H5P_FILE_ACCESS); + hid_t acc_tpl = H5Pcreate(H5P_FILE_ACCESS); H5Pset_fapl_mpio(acc_tpl, *m_adm.getCommunicator(), info); +#else + hid_t acc_tpl = H5P_DEFAULT; #endif unsigned int flag = restart ? m_restart_flag : m_flag; std::string fname = restart ? m_restart_name : m_name; @@ -754,10 +756,11 @@ bool HDF5Writer::writeRestartData(int level, const DataExporter::SerializeData& m_restart_flag = H5F_ACC_RDWR; openFile(level, true); int pid = 0; - int ptot = 1; #ifdef HAVE_MPI pid = m_adm.getProcId(); - ptot = m_adm.getNoProcs(); + int ptot = m_adm.getNoProcs(); +#else + int ptot = 1; #endif for (int p = 0; p < ptot; p++) for (const std::pair& it : data) { diff --git a/src/Utility/Profiler.C b/src/Utility/Profiler.C index 17933715..f22d5564 100644 --- a/src/Utility/Profiler.C +++ b/src/Utility/Profiler.C @@ -85,7 +85,9 @@ void Profiler::start (const std::string& funcName) Profile& p = tID < 0 ? myTimers[funcName] : myMTimers[tID][funcName]; if (p.running) return; +#ifdef USE_OPENMP if (tID < 0) +#endif nRunners++; p.running = true; diff --git a/src/Utility/VTF.C b/src/Utility/VTF.C index 520d7f97..b8606bf5 100644 --- a/src/Utility/VTF.C +++ b/src/Utility/VTF.C @@ -206,6 +206,7 @@ VTF::~VTF () void VTF::writeGeometryBlocks (int iStep) { +#ifdef HAS_VTFAPI if (myBlocks.empty()) return; @@ -213,11 +214,10 @@ void VTF::writeGeometryBlocks (int iStep) for (size_t i = 0; i < myBlocks.size(); i++) geomID[i] = myBlocks[i].first; -#ifdef HAS_VTFAPI if (!myGBlock) myGBlock = new VTFAGeometryBlock(); #if HAS_VTFAPI == 1 myGBlock->SetGeometryElementBlocks(&geomID.front(),geomID.size(),iStep); -#elif HAS_VTFAPI == 2 +#else myGBlock->SetElementBlocksForState(&geomID.front(),geomID.size(),iStep); #endif #endif @@ -296,6 +296,7 @@ bool VTF::writeTransformation (const Vec3& X, const Tensor& T, bool VTF::writeVres (const std::vector& nodeResult, int idBlock, int geomID, size_t nvc) { +#ifdef HAS_VTFAPI if (!myFile) return true; const ElementBlock* grid = this->getBlock(geomID); @@ -332,12 +333,13 @@ bool VTF::writeVres (const std::vector& nodeResult, dBlock.SetMapToBlockID(myBlocks[geomID-1].first); if (VTFA_FAILURE(myFile->WriteBlock(&dBlock))) return showError("Error writing result block",idBlock); -#elif HAS_VTFAPI == 2 +#else VTFXAResultValuesBlock dBlock(idBlock,VTFXA_DIM_VECTOR,VTFXA_FALSE); dBlock.SetMapToBlockID(myBlocks[geomID-1].first,VTFXA_NODES); dBlock.SetResultValues3D(resVec.data(),nnod); if (VTFA_FAILURE(myDatabase->WriteBlock(&dBlock))) return showError("Error writing result block",idBlock); +#endif #endif return true; @@ -372,7 +374,7 @@ bool VTF::writeEres (const std::vector& elementResult, dBlock.SetMapToBlockID(myBlocks[geomID-1].first); if (VTFA_FAILURE(myFile->WriteBlock(&dBlock))) return showError("Error writing result block",idBlock); -#elif HAS_VTFAPI == 2 +#else VTFXAResultValuesBlock dBlock(idBlock,VTFXA_DIM_SCALAR,VTFXA_FALSE); dBlock.SetMapToBlockID(myBlocks[geomID-1].first,VTFXA_ELEMENTS); dBlock.SetResultValues1D(resVec.data(),nres); @@ -387,6 +389,7 @@ bool VTF::writeEres (const std::vector& elementResult, bool VTF::writeNres (const std::vector& nodalResult, int idBlock, int geomID) { +#ifdef HAS_VTFAPI if (!myFile) return true; const ElementBlock* grid = this->getBlock(geomID); @@ -410,12 +413,13 @@ bool VTF::writeNres (const std::vector& nodalResult, dBlock.SetMapToBlockID(myBlocks[geomID-1].first); if (VTFA_FAILURE(myFile->WriteBlock(&dBlock))) return showError("Error writing result block",idBlock); -#elif HAS_VTFAPI == 2 +#else VTFXAResultValuesBlock dBlock(idBlock,VTFXA_DIM_SCALAR,VTFXA_FALSE); dBlock.SetMapToBlockID(myBlocks[geomID-1].first,VTFXA_NODES); dBlock.SetResultValues1D(resVec.data(),nres); if (VTFA_FAILURE(myDatabase->WriteBlock(&dBlock))) return showError("Error writing result block",idBlock); +#endif #endif return true; @@ -424,6 +428,7 @@ bool VTF::writeNres (const std::vector& nodalResult, bool VTF::writeNfunc (const RealFunc& f, Real time, int idBlock, int geomID) { +#ifdef HAS_VTFAPI if (!myFile) return true; const ElementBlock* grid = this->getBlock(geomID); @@ -446,12 +451,13 @@ bool VTF::writeNfunc (const RealFunc& f, Real time, int idBlock, int geomID) dBlock.SetMapToBlockID(myBlocks[geomID-1].first); if (VTFA_FAILURE(myFile->WriteBlock(&dBlock))) return showError("Error writing result block",idBlock); -#elif HAS_VTFAPI == 2 +#else VTFXAResultValuesBlock dBlock(idBlock,VTFXA_DIM_SCALAR,VTFXA_FALSE); dBlock.SetMapToBlockID(myBlocks[geomID-1].first,VTFXA_NODES); dBlock.SetResultValues1D(resVec.data(),nres); if (VTFA_FAILURE(myDatabase->WriteBlock(&dBlock))) return showError("Error writing result block",idBlock); +#endif #endif return true;