Commit 4d104a69 authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Halt calculation in case of unrecognized runtime options

parent cd0c79c5
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -231,7 +231,7 @@ void cluster(const string& config_file, const string& data_file, const string& o
    // Sanity check on number of sphere consistency, should always be verified
    if (s_nsph == nsph) {
      char virtual_line[256];
      sprintf(virtual_line, "%.5lg.\n", sconf->get_particle_radius(gconf));
      sprintf(virtual_line, "%.5lg m.\n", sconf->get_particle_radius(gconf));
      message = "INFO: particle radius is " + (string)virtual_line;
      logger->log(message);
      // Overlapping spheres test
@@ -253,7 +253,7 @@ void cluster(const string& config_file, const string& data_file, const string& o
	      "\n";
	    logger->log(message);
	    sprintf(
	      virtual_line, "INFO: overlap is %.5lg (tolerance is %.5lg)\n",
	      virtual_line, "INFO: overlap is %.5lg m (tolerance is %.5lg m)\n",
	      overlap, tolerance
	    );
	    message = (string)virtual_line;
@@ -287,6 +287,11 @@ void cluster(const string& config_file, const string& data_file, const string& o
      sprintf(virtual_line, "%.5lg", requested_ram_gb);
      message = "INFO: code execution needs " + (string)virtual_line + " GiB of RAM.\n";
      logger->log(message);
      // mat_size_bytes = sizeof(dcomplex) * 2 * 2 * NSPH * NSPH * LI * LI * (LI + 2) * (LI + 2)
      long matrix_size_bytes = sizeof(dcomplex)
	* 4 * gconf->number_of_spheres * gconf->number_of_spheres
	* gconf->li * gconf->li * (gconf->li + 2) * (gconf->li + 2);
      double matrix_size_gb = matrix_size_bytes / 1024.0 / 1024.0 / 1024.0;
      if (gconf->host_ram_gb > 0.0) {
	if (requested_ram_gb > gconf->host_ram_gb) {
	  // ERROR: host system does not have the necessary RAM
@@ -301,11 +306,6 @@ void cluster(const string& config_file, const string& data_file, const string& o
	}
      }
      if (gconf->gpu_ram_gb > 0.0) {
	// mat_size_bytes = sizeof(dcomplex) * 2 * 2 * NSPH * NSPH * LI * LI * (LI + 2) * (LI + 2)
	long matrix_size_bytes = sizeof(dcomplex)
	  * 4 * gconf->number_of_spheres * gconf->number_of_spheres
	  * gconf->li * gconf->li * (gconf->li + 2) * (gconf->li + 2);
	double matrix_size_gb = matrix_size_bytes / 1024.0 / 1024.0 / 1024.0;
	int refinement_factor = (gconf->refine_flag) ? 3 : 1;
	if (refinement_factor * omp_wavelength_threads * matrix_size_gb > gconf->gpu_ram_gb) {
	  // ERROR: GPU does not have the necessary RAM
@@ -328,8 +328,10 @@ void cluster(const string& config_file, const string& data_file, const string& o
      ClusterIterationData *cid = new ClusterIterationData(gconf, sconf, mpidata, device_count);
      const int ndi = cid->c1->nsph * cid->c1->nlim;
      np_int ndit = 2 * ndi;
      logger->log("INFO: Size of matrices to invert: " + to_string((int64_t)ndit) + " x " + to_string((int64_t)ndit) +".\n");
      time_logger->log("INFO: Size of matrices to invert: " + to_string((int64_t)ndit) + " x " + to_string((int64_t)ndit) +".\n");
      sprintf(virtual_line, "INFO: Size of matrices to invert: %ld x %ld (%.5lg GiB)\n", (int64_t)ndit, (int64_t)ndit, matrix_size_gb);
      message = string(virtual_line);
      logger->log(message);
      time_logger->log(message);

      str(sconf->_rcf, cid->c1);
      thdps(cid->c1->lm, cid->zpv);
+13 −11
Original line number Diff line number Diff line
@@ -231,7 +231,7 @@ void inclusion(const string& config_file, const string& data_file, const string&
    // Sanity check on number of sphere consistency, should always be verified
    if (s_nsph == nsph) {
      char virtual_line[256];
      sprintf(virtual_line, "%.5lg.\n", sconf->get_particle_radius(gconf));
      sprintf(virtual_line, "%.5lg m.\n", sconf->get_particle_radius(gconf));
      message = "INFO: particle radius is " + (string)virtual_line;
      logger->log(message);
      // Overlapping spheres test
@@ -253,7 +253,7 @@ void inclusion(const string& config_file, const string& data_file, const string&
	      "\n";
	    logger->log(message);
	    sprintf(
	      virtual_line, "INFO: overlap is %.5lg (tolerance is %.5lg)\n",
	      virtual_line, "INFO: overlap is %.5lg m (tolerance is %.5lg m)\n",
	      overlap, tolerance
	    );
	    message = (string)virtual_line;
@@ -287,6 +287,11 @@ void inclusion(const string& config_file, const string& data_file, const string&
      sprintf(virtual_line, "%.5lg", requested_ram_gb);
      message = "INFO: code execution needs " + (string)virtual_line + " GiB of RAM.\n";
      logger->log(message);
      // mat_size_bytes = sizeof(dcomplex) * 2 * 2 * NSPH * NSPH * LI * LI * (LI + 2) * (LI + 2)
      long matrix_size_bytes = sizeof(dcomplex)
	* 4 * gconf->number_of_spheres * gconf->number_of_spheres
	* gconf->li * gconf->li * (gconf->li + 2) * (gconf->li + 2);
      double matrix_size_gb = matrix_size_bytes / 1024.0 / 1024.0 / 1024.0;
      if (gconf->host_ram_gb > 0.0) {
	if (requested_ram_gb > gconf->host_ram_gb) {
	  // ERROR: host system does not have the necessary RAM
@@ -301,11 +306,6 @@ void inclusion(const string& config_file, const string& data_file, const string&
	}
      }
      if (gconf->gpu_ram_gb > 0.0) {
	// mat_size_bytes = sizeof(dcomplex) * 2 * 2 * NSPH * NSPH * LI * LI * (LI + 2) * (LI + 2)
	long matrix_size_bytes = sizeof(dcomplex)
	  * 4 * gconf->number_of_spheres * gconf->number_of_spheres
	  * gconf->li * gconf->li * (gconf->li + 2) * (gconf->li + 2);
	double matrix_size_gb = matrix_size_bytes / 1024.0 / 1024.0 / 1024.0;
	int refinement_factor = (gconf->refine_flag) ? 3 : 1;
	if (refinement_factor * omp_wavelength_threads * matrix_size_gb > gconf->gpu_ram_gb) {
	  // ERROR: GPU does not have the necessary RAM
@@ -325,8 +325,10 @@ void inclusion(const string& config_file, const string& data_file, const string&
      // Open empty virtual ascii file for output
      InclusionOutputInfo *p_output = new InclusionOutputInfo(sconf, gconf, mpidata);
      InclusionIterationData *cid = new InclusionIterationData(gconf, sconf, mpidata, device_count);
      logger->log("INFO: Size of matrices to invert: " + to_string((int64_t)cid->c1->ndm) + " x " + to_string((int64_t)cid->c1->ndm) +".\n");
      time_logger->log("INFO: Size of matrices to invert: " + to_string((int64_t)cid->c1->ndm) + " x " + to_string((int64_t)cid->c1->ndm) +".\n");
      sprintf(virtual_line, "INFO: Size of matrices to invert: %d x %d (%.5lg GiB)\n", cid->c1->ndm, cid->c1->ndm, matrix_size_gb);
      message = string(virtual_line);
      logger->log(message);
      time_logger->log(message);
      
      instr(sconf->_rcf, cid->c1);
      thdps(cid->c1->lm, cid->zpv);
+15 −0
Original line number Diff line number Diff line
@@ -349,39 +349,54 @@ GeometryConfiguration* GeometryConfiguration::from_legacy(const std::string& fil
    fjwtm
  );

  last_read_line++; // skip the end-of-data code
  // Read optional configuration data used only by the C++ code.
  while (num_lines > last_read_line) {
    str_target = file_lines[last_read_line++];
    bool is_parsed = false;
    if (str_target.size() > 15) {
      if (str_target.substr(0, 15).compare("USE_REFINEMENT=") == 0) {
	re = regex("[0-9]+");
	regex_search(str_target, m, re);
	short refine_flag = (short)stoi(m.str());
	conf->_refine_flag = refine_flag;
	is_parsed = true;
      }
      if (str_target.substr(0, 15).compare("USE_DYN_ORDERS=") == 0) {
	re = regex("[0-9]+");
	regex_search(str_target, m, re);
	short dyn_order_flag = (short)stoi(m.str());
	conf->_dyn_order_flag = dyn_order_flag;
	is_parsed = true;
      }
    }
    if (str_target.size() > 12) {
      if (str_target.substr(0, 12).compare("HOST_RAM_GB=") == 0) {
	double ram_gb = (double)stod(str_target.substr(12, str_target.length()));
	conf->_host_ram_gb = ram_gb;
	is_parsed = true;
      }
    }
    if (str_target.size() > 11) {
      if (str_target.substr(0, 11).compare("GPU_RAM_GB=") == 0) {
	double ram_gb = (double)stod(str_target.substr(11, str_target.length()));
	conf->_gpu_ram_gb = ram_gb;
	is_parsed = true;
      }
    }
    if (str_target.size() > 10) {
      if (str_target.substr(0, 10).compare("TOLERANCE=") == 0) {
	double tolerance = (double)stod(str_target.substr(10, str_target.length()));
	conf->_tolerance = tolerance;
	is_parsed = true;
      }
    }
    if (!is_parsed) {
      if (str_target.size() > 0) {
	if (str_target.substr(0, 1).compare("#") != 0) {
	  // ERROR: found an unrecognized option that is not marked as comment
	  throw(UnrecognizedConfigurationException("ERROR: unrecognized option \"" + str_target + "\"!\n"));
	}
      }
    }
  }
+14 −1
Original line number Diff line number Diff line
@@ -284,7 +284,10 @@ void frfme(string data_file, string output_path) {
    int ixi = stoi(m.str());
    string tedf_name = output_path + "/" + namef + ".hd5";
    // Check for run-time options
    bool skip_frfme = false;
    last_read_line++; // skip the end-of-data code
    while (last_read_line < line_count) {
      bool is_parsed = false;
      str_target = file_lines[last_read_line++];
      if (str_target.size() > 12) {
	if (str_target.substr(0, 12).compare("PRECOMPUTED=") == 0) {
@@ -292,10 +295,20 @@ void frfme(string data_file, string output_path) {
	  // TODO: check that the file exists and it is suitable for the calculation.
	  message = "INFO: using precomputed file " + precomp_name + "\n";
	  logger.log(message);
	  return;
	  skip_frfme = true;
	  is_parsed = true;
	}
      }
      if (!is_parsed) {
	if (str_target.size() > 0) {
	  if (str_target.substr(0, 1).compare("#") != 0) {
	    // ERROR: found an unrecognized option that is not marked as comment
	    throw(UnrecognizedConfigurationException("ERROR: unrecognized option \"" + str_target + "\"!\n"));
	  }
	}
      }
    }
    if (skip_frfme) return;
    ScattererConfiguration *tedf = ScattererConfiguration::from_binary(tedf_name, "HDF5");
#ifdef USE_NVTX
    nvtxRangePush("TEDF data import");
+11 −1
Original line number Diff line number Diff line
@@ -129,14 +129,24 @@ void lffft(string data_file, string output_path) {
    else if (mi == 2) jtw = stoi(m.str());
    str_target = m.suffix().str();
  } // mi loop
  int last_read_line = 1;
  int last_read_line = 2; // skip the end-of-data code
  double host_ram_gb = 0.0;
  // Parse runtime options.
  while (last_read_line < num_lines) {
    bool is_parsed = false;
    string str_target = file_lines[last_read_line++];
    if (str_target.size() > 12) {
      if (str_target.substr(0, 12).compare("HOST_RAM_GB=") == 0) {
	host_ram_gb = (double)stod(str_target.substr(12, str_target.length()));
	is_parsed = true;
      }
    }
    if (!is_parsed) {
      if (str_target.size() > 0) {
	if (str_target.substr(0, 1).compare("#") != 0) {
	  // ERROR: found an unrecognized option that is not marked as comment
	  throw(UnrecognizedConfigurationException("ERROR: unrecognized option \"" + str_target + "\"!\n"));
	}
      }
    }
  }