Commit 77139c78 authored by gbalduzz's avatar gbalduzz
Browse files

Store self energy and chemical potential at each iteration. Close output file...

Store self energy and chemical potential at each iteration. Close output file upon receiving sigint.
parent 02bc73e6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ set(DCA_LIBS
  cluster_domains
  quantum_domains
  time_and_frequency_domains
  signals
  symmetrization
  coarsegraining
  ${DCA_CONCURRENCY_LIB}
+3 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include "dca/io/json/json_reader.hpp"
#include "dca/util/git_version.hpp"
#include "dca/util/modules.hpp"
#include "dca/util/signal_handler.hpp"

int main(int argc, char** argv) {
  if (argc < 2) {
@@ -30,6 +31,8 @@ int main(int argc, char** argv) {
  Concurrency concurrency(argc, argv);

  try {
    dca::util::SignalHandler::init(concurrency.id() == concurrency.first());

    std::string input_file(argv[1]);

    Profiler::start();
+41 −31
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@

#include "dca/function/domains.hpp"
#include "dca/io/hdf5/hdf5_writer.hpp"
#include "dca/io/json/json_writer.hpp"
#include "dca/phys/dca_algorithms/compute_greens_function.hpp"
#include "dca/phys/dca_loop/dca_loop_data.hpp"
#include "dca/phys/dca_step/cluster_mapping/cluster_exclusion.hpp"
@@ -34,6 +33,7 @@
#include "dca/phys/domains/quantum/electron_band_domain.hpp"
#include "dca/phys/domains/quantum/electron_spin_domain.hpp"
#include "dca/util/print_time.hpp"
#include "dca/util/signal_handler.hpp"

namespace dca {
namespace phys {
@@ -91,6 +91,8 @@ protected:

  void update_DCA_loop_data_functions(int DCA_iteration);

  void logSelfEnergy(int i);

  ParametersType& parameters;
  DcaDataType& MOMS;
  concurrency_type& concurrency;
@@ -106,6 +108,9 @@ private:

  update_chemical_potential_type update_chemical_potential_obj;

  std::string file_name_;
  io::HDF5Writer output_file_;

protected:
  MCIntegratorType monte_carlo_integrator_;
};
@@ -128,10 +133,15 @@ DcaLoop<ParametersType, DcaDataType, MCIntegratorType>::DcaLoop(ParametersType&

      update_chemical_potential_obj(parameters, MOMS, cluster_mapping_obj),

      monte_carlo_integrator_(parameters_ref, MOMS_ref) {
  if (concurrency.id() == concurrency.first())
      monte_carlo_integrator_(parameters_ref, MOMS_ref, &output_file_) {
  if (concurrency.id() == concurrency.first()) {
    file_name_ = parameters.get_directory() + parameters.get_filename_dca();
    output_file_.open_file(file_name_);
    dca::util::SignalHandler::registerFile(output_file_);

    std::cout << "\n\n\t" << __FUNCTION__ << " has started \t" << dca::util::print_time() << "\n\n";
  }
}

template <typename ParametersType, typename DcaDataType, typename MCIntegratorType>
void DcaLoop<ParametersType, DcaDataType, MCIntegratorType>::read() {
@@ -141,37 +151,16 @@ void DcaLoop<ParametersType, DcaDataType, MCIntegratorType>::read() {

template <typename ParametersType, typename DcaDataType, typename MCIntegratorType>
void DcaLoop<ParametersType, DcaDataType, MCIntegratorType>::write() {
  const std::string& output_format = parameters.get_output_format();
  const std::string& file_name = parameters.get_directory() + parameters.get_filename_dca();

  std::cout << "\n\n\t\t start writing " << file_name << "\t" << dca::util::print_time() << "\n\n";

  if (output_format == "JSON") {
    dca::io::JSONWriter writer;
    writer.open_file(file_name);

    parameters.write(writer);
    MOMS.write(writer);
    monte_carlo_integrator_.write(writer);
    DCA_info_struct.write(writer);

    writer.close_file();
  }

  else if (output_format == "HDF5") {
    dca::io::HDF5Writer writer;
    writer.open_file(file_name);
  if (concurrency.id() == concurrency.first()) {
    std::cout << "\n\n\t\t start writing " << file_name_ << "\t" << dca::util::print_time() << "\n\n";

    parameters.write(writer);
    MOMS.write(writer);
    monte_carlo_integrator_.write(writer);
    DCA_info_struct.write(writer);
    parameters.write(output_file_);
    MOMS.write(output_file_);
    monte_carlo_integrator_.write(output_file_);
    DCA_info_struct.write(output_file_);

    writer.close_file();
    output_file_.close_file();
  }

  else
    throw std::logic_error(__FUNCTION__);
}

template <typename ParametersType, typename DcaDataType, typename MCIntegratorType>
@@ -199,6 +188,8 @@ void DcaLoop<ParametersType, DcaDataType, MCIntegratorType>::execute() {

    perform_lattice_mapping();

    logSelfEnergy(i);  // Write a check point.

    update_DCA_loop_data_functions(i);

    if (L2_Sigma_difference <
@@ -357,6 +348,25 @@ void DcaLoop<ParametersType, DcaDataType, MCIntegratorType>::update_DCA_loop_dat
          parameters.get_beta() / M_PI;
}

template <typename ParametersType, typename DcaDataType, typename MCIntegratorType>
void DcaLoop<ParametersType, DcaDataType, MCIntegratorType>::logSelfEnergy(int i) {
  if (output_file_) {
    output_file_.open_group("functions");
    output_file_.execute(MOMS.Sigma);
    output_file_.close_group();

    output_file_.open_group("parameters");
    output_file_.open_group("physics");
    output_file_.execute("chemical-potential", parameters.get_chemical_potential());
    output_file_.close_group();
    output_file_.close_group();

    output_file_.open_group("DCA-loop-functions");
    output_file_.execute("completed-iteration", i);
    output_file_.close_group();
  }
}

}  // namespace phys
}  // namespace dca

+38 −0
Original line number Diff line number Diff line
// Copyright (C) 2019 ETH Zurich
// Copyright (C) 2019 UT-Battelle, LLC
// All rights reserved.
// See LICENSE.txt for terms of usage./
//  See CITATION.md for citation guidelines, if DCA++ is used for scientific publications.
//
// Author: Giovanni Balduzzi (gbalduzz@itp.phys.ethz.ch)
//
// This singleton class organizes the handling of signals.

#ifndef DCA_UTIL_SIGNAL_HANDLER_HPP
#define DCA_UTIL_SIGNAL_HANDLER_HPP

#include <vector>

#include "dca/io/hdf5/hdf5_writer.hpp"

namespace dca {
namespace util {
// dca::util::

class SignalHandler{
public:
    static void init(bool verbose = false);

    static void registerFile(io::HDF5Writer& writer);

private:
    static void sigintHandler(int signum);

    static inline bool verbose_;
    static inline std::vector<io::HDF5Writer*> file_ptrs_;
};

}  // namespace util
}  // namespace dca

#endif  // DCA_UTIL_SIGNAL_HANDLER_HPP
+6 −47
Original line number Diff line number Diff line
@@ -80,68 +80,27 @@ std::string HDF5Writer::get_path() {
void HDF5Writer::execute(const std::string& name,
                         const std::string& value)  //, H5File& file, std::string path)
{
  if (value.size() > 0) {
    H5::H5File& file = (*file_);
    std::string path = get_path();

    hsize_t dims[1];

    H5::DataSet* dataset = NULL;
    H5::DataSpace* dataspace = NULL;

    {
      dims[0] = value.size();
      dataspace = new H5::DataSpace(1, dims);
  std::string full_name = get_path() + '/' + name;

      std::string full_name = path + "/" + name;
      dataset = new H5::DataSet(
          file.createDataSet(full_name.c_str(), HDF5_TYPE<char>::get_PredType(), *dataspace));

      H5Dwrite(dataset->getId(), HDF5_TYPE<char>::get(), dataspace->getId(), H5S_ALL, H5P_DEFAULT,
               &value[0]);
    }

    delete dataset;
    delete dataspace;
  }
  write(full_name, std::vector<hsize_t>{value.size()}, HDF5_TYPE<char>::get_PredType(), value.data());
}

void HDF5Writer::execute(const std::string& name,
                         const std::vector<std::string>& value)  //, H5File& file, std::string path)
{
  if (value.size() > 0) {
    H5::H5File& file = (*file_);

    open_group(name);

    execute("size", value.size());  //, file, new_path);
    execute("size", value.size());

    open_group("data");

    hsize_t dims[1];

    H5::DataSet* dataset = NULL;
    H5::DataSpace* dataspace = NULL;

    for (size_t l = 0; l < value.size(); l++) {
      dims[0] = value[l].size();
      dataspace = new H5::DataSpace(1, dims);
    const auto path = get_path();

      std::stringstream ss;
      ss << get_path() << "/" << l;

      dataset = new H5::DataSet(
          file.createDataSet(ss.str().c_str(), HDF5_TYPE<char>::get_PredType(), *dataspace));

      H5Dwrite(dataset->getId(), HDF5_TYPE<char>::get(), dataspace->getId(), H5S_ALL, H5P_DEFAULT,
               &(value[l][0]));
    for (int i = 0; i < value.size(); ++i) {
      execute(get_path() + "/" + std::to_string(i), value[i]);
    }

    close_group();

    delete dataset;
    delete dataspace;

    close_group();
  }
}
Loading