From 5b8f20c6a6605b6176b310ee2ea5ae0bc493f683 Mon Sep 17 00:00:00 2001 From: "Mulas, Giacomo" <gmulas@oa-cagliari.inaf.it> Date: Tue, 28 May 2024 10:36:16 +0200 Subject: [PATCH] move crucial allocations out of #ifdef USE_OPENMP --- src/cluster/cluster.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cluster/cluster.cpp b/src/cluster/cluster.cpp index 7ec727f8..49571cc6 100644 --- a/src/cluster/cluster.cpp +++ b/src/cluster/cluster.cpp @@ -340,12 +340,12 @@ void cluster(const string& config_file, const string& data_file, const string& o #ifdef _OPENMP // If OpenMP is enabled, give actual values to myompthread and ompnumthreads, and open thread-local output files myompthread = omp_get_thread_num(); + if (myompthread == 0) ompnumthreads = omp_get_num_threads(); +#endif if (myompthread == 0) { - ompnumthreads = omp_get_num_threads(); p_outarray = new VirtualAsciiFile*[ompnumthreads]; vtppoanarray = new VirtualBinaryFile*[ompnumthreads]; } -#endif // To test parallelism, I will now start feeding this function with "clean" copies of the parameters, so that they will not be changed by previous iterations, and each one will behave as the first one. Define all (empty) variables here, so they have the correct scope, then they get different definitions depending on thread number ClusterIterationData *cid_2 = NULL; //FILE *output_2 = NULL; @@ -569,12 +569,12 @@ void cluster(const string& config_file, const string& data_file, const string& o #ifdef _OPENMP // If OpenMP is enabled, give actual values to myompthread and ompnumthreads, and open thread-local output files myompthread = omp_get_thread_num(); + if (myompthread == 0) ompnumthreads = omp_get_num_threads(); +#endif if (myompthread == 0) { - ompnumthreads = omp_get_num_threads(); p_outarray = new VirtualAsciiFile*[ompnumthreads]; vtppoanarray = new VirtualBinaryFile*[ompnumthreads]; } -#endif // To test parallelism, I will now start feeding this function with "clean" copies of the parameters, so that they will not be changed by previous iterations, and each one will behave as the first one. Define all (empty) variables here, so they have the correct scope, then they get different definitions depending on thread number ClusterIterationData *cid_2 = NULL; //FILE *output_2 = NULL; -- GitLab