From 7677b03dfcbb24329d6e82681b5424310ff99b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Thu, 27 Nov 2025 15:52:11 +0100 Subject: [PATCH 1/7] Minor clean up --- kratos/containers/data_value_container.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/kratos/containers/data_value_container.h b/kratos/containers/data_value_container.h index d53de603403c..065edcfc5f24 100644 --- a/kratos/containers/data_value_container.h +++ b/kratos/containers/data_value_container.h @@ -13,15 +13,11 @@ #pragma once // System includes -#include -#include #include -#include // External includes // Project includes -#include "includes/define.h" #include "containers/variable.h" #include "includes/kratos_components.h" #include "includes/exception.h" @@ -93,6 +89,7 @@ class KRATOS_API(KRATOS_CORE) DataValueContainer /// Default constructor. DataValueContainer() noexcept = default; + /// Move constructor. DataValueContainer(DataValueContainer&&) noexcept = default; /// Copy constructor. @@ -240,7 +237,11 @@ class KRATOS_API(KRATOS_CORE) DataValueContainer return mData.end(); } - DataValueContainer& operator=(DataValueContainer&&) noexcept = default; + /** + * @brief Move assignment operator + * @param[in] rOther The temporary or explicitly moved DataValueContainer object to transfer resources from. + */ + DataValueContainer& operator=(DataValueContainer&& rOther) noexcept = default; /** * @brief Assignment operator for copying data from another DataValueContainer. @@ -265,13 +266,11 @@ class KRATOS_API(KRATOS_CORE) DataValueContainer { typename ContainerType::iterator i; - if ((i = std::find_if(mData.begin(), mData.end(), IndexCheck(rThisVariable.SourceKey()))) != mData.end()) + if ((i = std::find_if(mData.begin(), mData.end(), IndexCheck(rThisVariable.SourceKey()))) != mData.end()) { return *(static_cast(i->second) + rThisVariable.GetComponentIndex()); + } -#ifdef KRATOS_DEBUG - if(OpenMPUtils::IsInParallel() != 0) - KRATOS_ERROR << "attempting to do a GetValue for: " << rThisVariable << " unfortunately the variable is not in the database and the operations is not threadsafe (this function is being called from within a parallel region)" << std::endl; -#endif + KRATOS_DEBUG_ERROR_IF(OpenMPUtils::IsInParallel() != 0) << "Attempting to do a GetValue for: " << rThisVariable << " unfortunately the variable is not in the database and the operations is not threadsafe (this function is being called from within a parallel region)" << std::endl; auto p_source_variable = &rThisVariable.GetSourceVariable(); mData.push_back(ValueType(p_source_variable,p_source_variable->Clone(p_source_variable->pZero()))); @@ -291,8 +290,9 @@ class KRATOS_API(KRATOS_CORE) DataValueContainer { typename ContainerType::const_iterator i; - if ((i = std::find_if(mData.begin(), mData.end(), IndexCheck(rThisVariable.SourceKey()))) != mData.end()) + if ((i = std::find_if(mData.begin(), mData.end(), IndexCheck(rThisVariable.SourceKey()))) != mData.end()) { return *(static_cast(i->second) + rThisVariable.GetComponentIndex()); + } return rThisVariable.Zero(); } From 99eb83b4a43359ff6fe8b4906032d0186c7e19ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Thu, 27 Nov 2025 15:54:54 +0100 Subject: [PATCH 2/7] Use `ParallelUtilities::GetNumThreads()` instead of legacy OpenMPUtils --- kratos/containers/data_value_container.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kratos/containers/data_value_container.h b/kratos/containers/data_value_container.h index 065edcfc5f24..504167341a04 100644 --- a/kratos/containers/data_value_container.h +++ b/kratos/containers/data_value_container.h @@ -23,7 +23,7 @@ #include "includes/exception.h" #ifdef KRATOS_DEBUG -#include "utilities/openmp_utils.h" +#include "utilities/parallel_utilities.h" #endif namespace Kratos @@ -270,7 +270,7 @@ class KRATOS_API(KRATOS_CORE) DataValueContainer return *(static_cast(i->second) + rThisVariable.GetComponentIndex()); } - KRATOS_DEBUG_ERROR_IF(OpenMPUtils::IsInParallel() != 0) << "Attempting to do a GetValue for: " << rThisVariable << " unfortunately the variable is not in the database and the operations is not threadsafe (this function is being called from within a parallel region)" << std::endl; + KRATOS_DEBUG_ERROR_IF(ParallelUtilities::GetNumThreads() > 1) << "Attempting to do a GetValue for: " << rThisVariable << " unfortunately the variable is not in the database and the operations is not threadsafe (this function is being called from within a parallel region)" << std::endl; auto p_source_variable = &rThisVariable.GetSourceVariable(); mData.push_back(ValueType(p_source_variable,p_source_variable->Clone(p_source_variable->pZero()))); From 5840b4733f42891da85789fc53023bd0093630c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Thu, 27 Nov 2025 21:09:54 +0100 Subject: [PATCH 3/7] Create I`sInParallel` --- kratos/utilities/parallel_utilities.cpp | 9 +++++++++ kratos/utilities/parallel_utilities.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/kratos/utilities/parallel_utilities.cpp b/kratos/utilities/parallel_utilities.cpp index cb68c38acc17..5e4b03c7e5f0 100644 --- a/kratos/utilities/parallel_utilities.cpp +++ b/kratos/utilities/parallel_utilities.cpp @@ -84,6 +84,15 @@ int ParallelUtilities::GetNumProcs() #endif } +int ParallelUtilities::IsInParallel() +{ +#ifdef KRATOS_SMP_OPENMP + return omp_in_parallel(); +#else + return 0; +#endif +} + int ParallelUtilities::InitializeNumberOfThreads() { #ifdef KRATOS_SMP_NONE diff --git a/kratos/utilities/parallel_utilities.h b/kratos/utilities/parallel_utilities.h index 4f9bdfa2a695..ed187ae08e3b 100644 --- a/kratos/utilities/parallel_utilities.h +++ b/kratos/utilities/parallel_utilities.h @@ -94,6 +94,12 @@ class KRATOS_API(KRATOS_CORE) ParallelUtilities */ [[nodiscard]] static int GetNumProcs(); + /** + * @brief Wrapper for omp_in_parallel() + * @return Maximum number of OpenMP threads that will be used in parallel regions. + */ + [[nodiscard]] static int IsInParallel(); + ///@} /** @brief Returns the global lock From baed6f8684e72618b91a6ada4a9513ec2c4fc4f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Thu, 27 Nov 2025 21:10:36 +0100 Subject: [PATCH 4/7] Using `IsInParallel` --- kratos/containers/data_value_container.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kratos/containers/data_value_container.h b/kratos/containers/data_value_container.h index 504167341a04..b192f81f76a9 100644 --- a/kratos/containers/data_value_container.h +++ b/kratos/containers/data_value_container.h @@ -270,7 +270,7 @@ class KRATOS_API(KRATOS_CORE) DataValueContainer return *(static_cast(i->second) + rThisVariable.GetComponentIndex()); } - KRATOS_DEBUG_ERROR_IF(ParallelUtilities::GetNumThreads() > 1) << "Attempting to do a GetValue for: " << rThisVariable << " unfortunately the variable is not in the database and the operations is not threadsafe (this function is being called from within a parallel region)" << std::endl; + KRATOS_DEBUG_ERROR_IF(ParallelUtilities::IsInParallel() != 0) << "Attempting to do a GetValue for: " << rThisVariable << " unfortunately the variable is not in the database and the operations is not threadsafe (this function is being called from within a parallel region)" << std::endl; auto p_source_variable = &rThisVariable.GetSourceVariable(); mData.push_back(ValueType(p_source_variable,p_source_variable->Clone(p_source_variable->pZero()))); From 8595154276cf0fec1a13fb88d3c08cd095337ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Fri, 28 Nov 2025 11:39:12 +0100 Subject: [PATCH 5/7] Comments --- kratos/containers/data_value_container.h | 2 +- kratos/utilities/parallel_utilities.cpp | 4 ++-- kratos/utilities/parallel_utilities.h | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kratos/containers/data_value_container.h b/kratos/containers/data_value_container.h index b192f81f76a9..3ead8d2dc7a5 100644 --- a/kratos/containers/data_value_container.h +++ b/kratos/containers/data_value_container.h @@ -270,7 +270,7 @@ class KRATOS_API(KRATOS_CORE) DataValueContainer return *(static_cast(i->second) + rThisVariable.GetComponentIndex()); } - KRATOS_DEBUG_ERROR_IF(ParallelUtilities::IsInParallel() != 0) << "Attempting to do a GetValue for: " << rThisVariable << " unfortunately the variable is not in the database and the operations is not threadsafe (this function is being called from within a parallel region)" << std::endl; + KRATOS_DEBUG_ERROR_IF(ParallelUtilities::IsInParallel()) << "Attempting to do a GetValue for: " << rThisVariable << " unfortunately the variable is not in the database and the operations is not threadsafe (this function is being called from within a parallel region)" << std::endl; auto p_source_variable = &rThisVariable.GetSourceVariable(); mData.push_back(ValueType(p_source_variable,p_source_variable->Clone(p_source_variable->pZero()))); diff --git a/kratos/utilities/parallel_utilities.cpp b/kratos/utilities/parallel_utilities.cpp index 5e4b03c7e5f0..0b284081dcc6 100644 --- a/kratos/utilities/parallel_utilities.cpp +++ b/kratos/utilities/parallel_utilities.cpp @@ -87,9 +87,9 @@ int ParallelUtilities::GetNumProcs() int ParallelUtilities::IsInParallel() { #ifdef KRATOS_SMP_OPENMP - return omp_in_parallel(); + return static_cast(omp_in_parallel()); #else - return 0; + return false; #endif } diff --git a/kratos/utilities/parallel_utilities.h b/kratos/utilities/parallel_utilities.h index ed187ae08e3b..b521aaf2b7b2 100644 --- a/kratos/utilities/parallel_utilities.h +++ b/kratos/utilities/parallel_utilities.h @@ -95,10 +95,10 @@ class KRATOS_API(KRATOS_CORE) ParallelUtilities [[nodiscard]] static int GetNumProcs(); /** - * @brief Wrapper for omp_in_parallel() - * @return Maximum number of OpenMP threads that will be used in parallel regions. + * @brief Wrapper for omp_in_parallel(), returns false otherwise. + * @return True if the execution is performed in a parallel loop, false otherwise. */ - [[nodiscard]] static int IsInParallel(); + [[nodiscard]] static bool IsInParallel(); ///@} From 28ad868b7069513226256dbf83d9fc441ba073f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Fri, 28 Nov 2025 11:40:14 +0100 Subject: [PATCH 6/7] Bool --- kratos/utilities/parallel_utilities.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kratos/utilities/parallel_utilities.cpp b/kratos/utilities/parallel_utilities.cpp index 0b284081dcc6..0b7fc6785687 100644 --- a/kratos/utilities/parallel_utilities.cpp +++ b/kratos/utilities/parallel_utilities.cpp @@ -84,7 +84,7 @@ int ParallelUtilities::GetNumProcs() #endif } -int ParallelUtilities::IsInParallel() +bool ParallelUtilities::IsInParallel() { #ifdef KRATOS_SMP_OPENMP return static_cast(omp_in_parallel()); From b7738c52b6ec9f1049771daa7430289f7ee13186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Mon, 1 Dec 2025 11:50:39 +0100 Subject: [PATCH 7/7] Hardcoded it --- kratos/containers/data_value_container.h | 8 +++----- kratos/utilities/parallel_utilities.cpp | 9 --------- kratos/utilities/parallel_utilities.h | 6 ------ 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/kratos/containers/data_value_container.h b/kratos/containers/data_value_container.h index 3ead8d2dc7a5..016e9eb16bfb 100644 --- a/kratos/containers/data_value_container.h +++ b/kratos/containers/data_value_container.h @@ -22,10 +22,6 @@ #include "includes/kratos_components.h" #include "includes/exception.h" -#ifdef KRATOS_DEBUG -#include "utilities/parallel_utilities.h" -#endif - namespace Kratos { @@ -270,7 +266,9 @@ class KRATOS_API(KRATOS_CORE) DataValueContainer return *(static_cast(i->second) + rThisVariable.GetComponentIndex()); } - KRATOS_DEBUG_ERROR_IF(ParallelUtilities::IsInParallel()) << "Attempting to do a GetValue for: " << rThisVariable << " unfortunately the variable is not in the database and the operations is not threadsafe (this function is being called from within a parallel region)" << std::endl; + #ifdef KRATOS_SMP_OPENMP + KRATOS_DEBUG_ERROR_IF(static_cast(omp_in_parallel())) << "Attempting to do a GetValue for: " << rThisVariable << " unfortunately the variable is not in the database and the operations is not threadsafe (this function is being called from within a parallel region)" << std::endl; + #endif auto p_source_variable = &rThisVariable.GetSourceVariable(); mData.push_back(ValueType(p_source_variable,p_source_variable->Clone(p_source_variable->pZero()))); diff --git a/kratos/utilities/parallel_utilities.cpp b/kratos/utilities/parallel_utilities.cpp index 0b7fc6785687..cb68c38acc17 100644 --- a/kratos/utilities/parallel_utilities.cpp +++ b/kratos/utilities/parallel_utilities.cpp @@ -84,15 +84,6 @@ int ParallelUtilities::GetNumProcs() #endif } -bool ParallelUtilities::IsInParallel() -{ -#ifdef KRATOS_SMP_OPENMP - return static_cast(omp_in_parallel()); -#else - return false; -#endif -} - int ParallelUtilities::InitializeNumberOfThreads() { #ifdef KRATOS_SMP_NONE diff --git a/kratos/utilities/parallel_utilities.h b/kratos/utilities/parallel_utilities.h index b521aaf2b7b2..4f9bdfa2a695 100644 --- a/kratos/utilities/parallel_utilities.h +++ b/kratos/utilities/parallel_utilities.h @@ -94,12 +94,6 @@ class KRATOS_API(KRATOS_CORE) ParallelUtilities */ [[nodiscard]] static int GetNumProcs(); - /** - * @brief Wrapper for omp_in_parallel(), returns false otherwise. - * @return True if the execution is performed in a parallel loop, false otherwise. - */ - [[nodiscard]] static bool IsInParallel(); - ///@} /** @brief Returns the global lock