Commit 037cc8c1 authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Use separate loops to re-assemble ASCII and binary output files

parent 7c81a958
Loading
Loading
Loading
Loading
+16 −12
Original line number Original line Diff line number Diff line
@@ -615,12 +615,12 @@ void cluster(string config_file, string data_file, string output_path) {
	delete[] am_vector_2;
	delete[] am_vector_2;
	delete[] am_2;
	delete[] am_2;
	
	
      } // jxi488 loop
      } // jxi488 loop and omp parallel
#ifdef _OPENMP
#ifdef _OPENMP
      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
      // 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);
	string partial_file_name = output_path + "/c_OCLU_" + to_string(ri);
	printf("Copying ASCII output of thread %d of %d... ", ri, ompnumthreads);
	printf("Copying ASCII output of thread %d of %d... ", ri, ompnumthreads - 1);
	FILE *partial_output = fopen(partial_file_name.c_str(), "r");
	FILE *partial_output = fopen(partial_file_name.c_str(), "r");
	char c = fgetc(partial_output);
	char c = fgetc(partial_output);
	while (c != EOF) {
	while (c != EOF) {
@@ -630,16 +630,20 @@ void cluster(string config_file, string data_file, string output_path) {
	fclose(partial_output);
	fclose(partial_output);
	remove(partial_file_name.c_str());
	remove(partial_file_name.c_str());
	printf("done.\n");
	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();
      }
      }
      for (int ri = 0; ri < ompnumthreads; ri++) {
	string partial_file_name = output_path + "/c_TPPOAN_" + to_string(ri);
	printf("Copying binary output of thread %d of %d... ", ri, ompnumthreads - 1);
	fstream partial_tppoan;
	partial_tppoan.open(partial_file_name.c_str(), ios::in | ios::binary);
	partial_tppoan.seekg(0, ios::end);
	long buffer_size = partial_tppoan.tellg();
	char *binary_buffer = new char[buffer_size];
	partial_tppoan.seekg(0, ios::beg);
	partial_tppoan.read(binary_buffer, buffer_size);
	tppoan.write(binary_buffer, buffer_size);
	partial_tppoan.close();
	partial_tppoan.close();
	delete[] binary_buffer;
	remove(partial_file_name.c_str());
	remove(partial_file_name.c_str());
	printf("done.\n");
	printf("done.\n");
      }
      }