From 1e082db5f91eda9313be7a386e61ab6733934be8 Mon Sep 17 00:00:00 2001 From: Amr ALHOSSARY Date: Thu, 30 Jul 2026 07:38:23 -0400 Subject: [PATCH] PathMSDBase: drop four omp simd pragmas that cannot vectorize Building with clang and OpenMP emits, four times: PathMSDBase.cpp:160:19: warning: loop not vectorized: the optimizer was unable to perform the requested transformation ... [-Wpass-failed=transform-warning] All four remarks are attributed to calculate()'s opening line, which hides which loops are at fault. Isolating them by keeping one pragma at a time shows exactly four contributors, and two pragmas that are fine: line 176 imgVec[i].property = ... ; imgVec[i].index = i; 1 warning line 234 tmp_derivs2[i*nat+j] = tmp_derivs[j]; 1 warning line 244 (the same loop again) 1 warning line 266 (the same loop again) 1 warning line 335 derivs_s[i] += tmp*it.distder[i]; 0 - vectorizes line 340 derivs_z[i] += ...; 0 - vectorizes Neither failing case can be vectorized, and asking for it is misleading: - Line 176 is not merely hard to vectorize, it is meaningless. ImagePath::property is a std::vector, so `imgVec[i].property = indexvec[i]` is a vector copy-assignment that ALLOCATES. There is no SIMD work in that loop. - The other three are the same contiguous copy of Vector elements written out by hand. std::copy_n says what is meant, and lets the compiler emit a memmove instead of an element loop the vectorizer then declines to transform. Fixing the source rather than silencing the diagnostic means the warning is gone for every compiler, and a build using -Werror no longer fails here. Behaviour is unchanged: std::copy_n over [0,nat) is exactly the loop it replaces, and the remaining two pragmas, which do vectorize, are untouched. Verified with clang 20.1.1: clang++ -std=c++17 -O3 -fopenmp -march=skylake-avx512 -Wall \ -c colvar/PathMSDBase.cpp -I. 4 warnings before, 0 after. GCC is unaffected either way (its 17 warnings here are pre-existing -Wunknown-pragmas from `#pragma acc` in headers, which PLUMED's own build silences). --- src/colvar/PathMSDBase.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/colvar/PathMSDBase.cpp b/src/colvar/PathMSDBase.cpp index 65c99b78bd..0cc00b38e3 100644 --- a/src/colvar/PathMSDBase.cpp +++ b/src/colvar/PathMSDBase.cpp @@ -28,6 +28,8 @@ #include "tools/RMSD.h" #include "tools/Tools.h" +#include + namespace PLMD { namespace colvar { @@ -173,7 +175,8 @@ void PathMSDBase::calculate() { // resize the list to full if(imgVec.empty()) { // this is the signal that means: recalculate all imgVec.resize(nframes); - #pragma omp simd + // No `omp simd` here: ImagePath::property is a std::vector, so this body performs a + // vector copy-assignment, i.e. it allocates. There is nothing for a SIMD unit to do. for(unsigned i=0; i