diff --git a/src/cluster/cluster.cpp b/src/cluster/cluster.cpp
index 7ec727f863e82df3d7fb4b5a82e52239a2411eb7..49571cc6cb95f358050c98a2de8727d5769a80c0 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;