diff --git a/src/cluster/cluster.cpp b/src/cluster/cluster.cpp
index c0158f912aba9d8aa23fb76b777b2fb9cfef2722..f0135268694741bc938af0efd387522769a4cad3 100644
--- a/src/cluster/cluster.cpp
+++ b/src/cluster/cluster.cpp
@@ -604,8 +604,31 @@ void cluster(string config_file, string data_file, string output_path) {
 	delete[] am_2;
 	
       } // jxi488 loop
-      for (int ri=0; ri<ompnumthreads; ri++) {
+      for (int ri = 0; ri < ompnumthreads; ri++) {
       // Giovanni, please add here in this loop code to reopen the temporary files, reread them and append them respectively to the global output and tppoan, before closing them
+	string partial_file_name = output_path + "/c_OCLU_" + to_string(ri);
+	printf("Copying ASCII output of thread %d of %d... ", ri, ompnumthreads);
+	FILE *partial_output = fopen(partial_file_name.c_str(), "r");
+	char c = fgetc(partial_output);
+	while (c != EOF) {
+	  fputc(c, output);
+	  c = fgetc(partial_output);
+	}
+	fclose(partial_output);
+	remove(partial_file_name.c_str());
+	printf("done.\n");
+	partial_file_name = output_path + "/c_TPPOAN_" + to_string(ri);
+	printf("Copying binary output of thread %d of %d... ", ri, ompnumthreads);
+	fstream partial_tppoan;
+	partial_tppoan.open((output_path + "/c_TPPOAN_" + to_string(ri)).c_str(), ios::in | ios::binary);
+	c = partial_tppoan.get();
+	while(!partial_tppoan.eof()) {
+	  tppoan.put(c);
+	  c = partial_tppoan.get();
+	}
+	partial_tppoan.close();
+	remove(partial_file_name.c_str());
+	printf("done.\n");
       }
       tppoan.close();
     } else { // In case TPPOAN could not be opened. Should never happen.