Commit d64edcbb authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Implement refinement iteration and accuracy settings

parent d9eb3dea
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -128,6 +128,10 @@ protected:
  double _tolerance;
  //! \brief Inversion algorithm (0 - LU, 1 - SVD, 2 - RBT)
  short _invert_mode;
  //! \brief Desired numerical accuracy for matrix inversion.
  double _accuracy_goal;
  //! \brief Maximum number of refinement iterations.
  int _ref_iters;

public:
  //! \brief Read-only view on number of spherical components.
@@ -188,6 +192,10 @@ public:
  const double& tolerance = _tolerance;
  //! \brief Read-only view on inversion algorithm.
  const short& invert_mode = _invert_mode;
  //! \brief Read-only view on desired numerical accuracy for matrix inversion.
  const double& accuracy_goal = _accuracy_goal;
  //! \brief Read-only view on maximum number of refinement iterations.
  const int& ref_iters = _ref_iters;
  
  /**
   * \brief Build a scattering geometry configuration structure.
+30 −9
Original line number Diff line number Diff line
@@ -109,6 +109,8 @@ GeometryConfiguration::GeometryConfiguration(
  _gpu_ram_gb = 0.0;
  _tolerance = -1.0;
  _invert_mode = 0;
  _accuracy_goal = 1.0e-07;
  _ref_iters = 5;
}

GeometryConfiguration::GeometryConfiguration(const GeometryConfiguration& rhs)
@@ -150,6 +152,8 @@ GeometryConfiguration::GeometryConfiguration(const GeometryConfiguration& rhs)
  _gpu_ram_gb = rhs._gpu_ram_gb;
  _tolerance = rhs._tolerance;
  _invert_mode = rhs._invert_mode;
  _accuracy_goal = rhs._accuracy_goal;
  _ref_iters = rhs._ref_iters;
}

#ifdef MPI_VERSION
@@ -191,6 +195,8 @@ GeometryConfiguration::GeometryConfiguration(const mixMPI *mpidata) {
  MPI_Bcast(&_gpu_ram_gb, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
  MPI_Bcast(&_tolerance, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
  MPI_Bcast(&_invert_mode, 1, MPI_SHORT, 0, MPI_COMM_WORLD);
  MPI_Bcast(&_accuracy_goal, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
  MPI_Bcast(&_ref_iters, 1, MPI_INT, 0, MPI_COMM_WORLD);
}

void GeometryConfiguration::mpibcast(const mixMPI *mpidata) {
@@ -228,6 +234,8 @@ void GeometryConfiguration::mpibcast(const mixMPI *mpidata) {
  MPI_Bcast(&_gpu_ram_gb, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
  MPI_Bcast(&_tolerance, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
  MPI_Bcast(&_invert_mode, 1, MPI_SHORT, 0, MPI_COMM_WORLD);
  MPI_Bcast(&_accuracy_goal, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
  MPI_Bcast(&_ref_iters, 1, MPI_INT, 0, MPI_COMM_WORLD);
}
#endif

@@ -364,7 +372,8 @@ GeometryConfiguration* GeometryConfiguration::from_legacy(const std::string& fil
  while (num_lines > last_read_line) {
    str_target = file_lines[last_read_line++];
    bool is_parsed = false;
    if (str_target.size() > 15) {
    int str_target_size = str_target.size();
    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);
@@ -380,28 +389,33 @@ GeometryConfiguration* GeometryConfiguration::from_legacy(const std::string& fil
	is_parsed = true;
      }
    }
    if (str_target.size() > 12) {
    if (str_target_size > 13) {
      if (str_target.substr(0, 13).compare("INV_ACCURACY=") == 0) {
	int accuracy_goal = (double)stod(str_target.substr(13, str_target.length()));
	conf->_accuracy_goal = accuracy_goal;
	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_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_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 (str_target.size() > 10) {
      if (str_target.substr(0, 10).compare("INVERSION=") == 0) {
	string str_inv_mode = str_target.substr(10, str_target.length());
	short inv_mode = 0;
@@ -415,6 +429,13 @@ GeometryConfiguration* GeometryConfiguration::from_legacy(const std::string& fil
	conf->_invert_mode = inv_mode;
	is_parsed = true;
      }
      if (str_target.substr(0, 10).compare("REF_ITERS=") == 0) {
	int ref_iters = (int)stoi(str_target.substr(10, str_target.length()));
	if (ref_iters > 0) {
	  conf->_ref_iters = ref_iters;
	  is_parsed = true;
	}
      }
    }
    if (!is_parsed) {
      if (str_target.size() > 0) {
@@ -435,7 +456,7 @@ GeometryConfiguration* GeometryConfiguration::from_legacy(const std::string& fil
// >>> RuntimeSettings CLASS IMPLEMENTATION <<<
RuntimeSettings::RuntimeSettings() {
  _invert_mode = RuntimeSettings::INV_MODE_LU;
  _accuracy_goal = 1.0e-14;
  _accuracy_goal = 1.0e-07;
  _gpu_ram_gb = 0.0;
  _host_ram_gb = 0.0;
  _max_ref_iters = 5;
@@ -445,10 +466,10 @@ RuntimeSettings::RuntimeSettings() {

RuntimeSettings::RuntimeSettings(GeometryConfiguration *gconf, Logger *ptr_logger) {
  _invert_mode = gconf->invert_mode;
  _accuracy_goal = 1.0e-14; // TODO: make this option configurable.
  _accuracy_goal = gconf->accuracy_goal; // TODO: make this option configurable.
  _gpu_ram_gb = gconf->gpu_ram_gb;
  _host_ram_gb = gconf->host_ram_gb;
  _max_ref_iters = 5; // TODO: make this option configurable.
  _max_ref_iters = gconf->ref_iters; // TODO: make this option configurable.
  _use_refinement = gconf->refine_flag;
  logger = ptr_logger;
}
+2 −2
Original line number Diff line number Diff line
@@ -411,8 +411,8 @@ magma_int_t magma_newton(
  magma_int_t maxindex = magma_izamax(mm, d_a, 1, queue);
  magmaDoubleComplex magmamax = magma_mone;
  magma_zgetvector(1, d_a + maxindex - 1, 1, &magmamax, 1, queue);
  curmax = cabs(magmamax.x + I * magmamax.y);
  target_residue = curmax * 1.0e-07;
  curmax = MAGMA_Z_ABS(magmamax); //cabs(magmamax.x + I * magmamax.y);
  target_residue = curmax * rs.accuracy_goal;
  sprintf(buffer, "INFO: largest matrix value has modulus %.5le; target residue is %.5le.\n", curmax, target_residue);
  message = buffer;
  rs.logger->log(message);