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

Enable a fall-back matrix inversion pipeline if MAGMA is not present

parent 1facab9c
Loading
Loading
Loading
Loading
+49 −61
Original line number Diff line number Diff line
@@ -242,6 +242,10 @@ void cluster(const string& config_file, const string& data_file, const string& o
    int nsph = gconf->number_of_spheres;
    // Sanity check on number of sphere consistency, should always be verified
    if (s_nsph == nsph) {
      message = (gconf->offload_flag) ?
	"INFO: target offload is enabled.\n" :
	"INFO: target offload is disabled.\n";
      logger->log(message);
      char virtual_line[256];
      sprintf(virtual_line, "%.5lg m.\n", sconf->get_particle_radius(gconf));
      message = "INFO: particle radius is " + (string)virtual_line;
@@ -255,13 +259,11 @@ void cluster(const string& config_file, const string& data_file, const string& o
      } else if(gconf->invert_mode == RuntimeSettings::INV_MODE_RBT) {
	message = "INFO: using RBT for inversion.\n";
	logger->log(message);
      } else if(gconf->invert_mode == RuntimeSettings::INV_MODE_SVD) {
	message = "INFO: using SVD for inversion.\n";
	logger->log(message);
	// message = "ERROR: SVD inversion mode not yet implemented!\n";
	// logger->err(message);
	// exit(1);
      }
      // else if(gconf->invert_mode == RuntimeSettings::INV_MODE_SVD) {
      // 	message = "INFO: using SVD for inversion.\n";
      // 	logger->log(message);
      // }
      // Overlapping spheres test
      double tolerance = gconf->tolerance;
      if (tolerance < 0.0) {
@@ -866,10 +868,6 @@ int cluster_jxi488_cycle(
  } // i132 loop
#ifdef USE_NVTX
  nvtxRangePop();
#endif
  interval_start = chrono::high_resolution_clock::now();
#ifdef USE_NVTX
  nvtxRangePush("Calculate inverted matrix");
#endif
#ifdef DEBUG_AM
  /* now, before cms, output am to p_outam0 */
@@ -885,8 +883,8 @@ int cluster_jxi488_cycle(
  outam0->write_to_disk(outam0_name);
  delete outam0;
#endif // DEBUG_AM
#ifdef USE_TARGET_OFFLOAD
  if (rs.use_offload) {
    // whenever rs.use_offload == true, USE_TARGET_OFFLOAD is defined.
#ifdef USE_MAGMA
    magmaDoubleComplex* vec_am = (magmaDoubleComplex *)(cid->am[0]);
    magma_queue_t queue = NULL;
@@ -911,27 +909,17 @@ int cluster_jxi488_cycle(
      }
    }
    magma_queue_destroy(queue);
#else // NO_USE_MAGMA
#else // NO_USE_MAGMA but USE_TARGET_OFFLOAD
    // TODO: implement full offload pipeline without MAGMA
    cms_flat(cid->am[0], cid->c1);
    invert_matrix(cid->am, ndit, jer, output_path, jxi488, mxndm, cid->proc_device, rs);
#endif // USE_MAGMA
  }
#else // NO_USE_TARGET_OFFLOAD
  } else {
#ifdef USE_NVTX
    nvtxRangePush("Calculate inverted matrix");
#endif
    interval_start = chrono::high_resolution_clock::now();
    cms(cid->am[0], cid->c1);
  message = "c_cpu_cms_jxi_" + to_string(jxi488) + ".ppm";
  write_matrix_as_ppm(cid->am[0], ndit, ndit, message, "MAG", 1, 1);
  {
    VirtualAsciiFile *outam1 = new VirtualAsciiFile();
    string outam1_name = output_path + "/c_AM1_JXI" + to_string(jxi488) + ".txt";
    sprintf(virtual_line, " AM matrix after CMS before LUCIN\n");
    outam1->append_line(virtual_line);
    sprintf(virtual_line, " %d\n", ndit);
    outam1->append_line(virtual_line);  
    sprintf(virtual_line, " I1+1   I2+1    Real    Imag\n");
    outam1->append_line(virtual_line);
    write_dcomplex_matrix(outam1, cid->am, ndit, ndit, " %5d %5d (%17.8lE,%17.8lE)\n", 1);
    outam1->write_to_disk(outam1_name);
    delete outam1;
  }
#ifdef DEBUG_AM
    VirtualAsciiFile *outam1 = new VirtualAsciiFile();
    string outam1_name = output_path + "/c_AM1_JXI" + to_string(jxi488) + ".txt";
@@ -983,7 +971,7 @@ int cluster_jxi488_cycle(
      return jer;
      // break; // jxi488 loop: goes to memory clean
    }
#endif // USE_TARGET_OFFLOAD
  }
  interval_start = chrono::high_resolution_clock::now();
#ifdef USE_NVTX
  nvtxRangePush("Average calculation");