diff --git a/include/IO/HDF5/impl/dataset.hpp b/include/IO/HDF5/impl/dataset.hpp index 28cfe450..8b914c19 100644 --- a/include/IO/HDF5/impl/dataset.hpp +++ b/include/IO/HDF5/impl/dataset.hpp @@ -2,9 +2,8 @@ #define SPECFEM_IO_HDF5_IMPL_DATASET_HPP #include "H5Cpp.h" -#include "file.hpp" -#include "group.hpp" #include "native_type.hpp" +#include "native_type.tpp" #include #include @@ -23,7 +22,7 @@ template class Dataset { const static int rank; using value_type = typename ViewType::non_const_value_type; - const static H5::PredType native_type; + using native_type = typename specfem::IO::impl::HDF5::native_type; using MemSpace = typename ViewType::memory_space; Dataset(std::unique_ptr &file, const std::string &name, @@ -37,6 +36,7 @@ template class Dataset { private: ViewType data; + // native_type datatype; std::unique_ptr dataset; std::unique_ptr dataspace; }; diff --git a/include/IO/HDF5/impl/dataset.tpp b/include/IO/HDF5/impl/dataset.tpp index 6a9ae622..9c10df4b 100644 --- a/include/IO/HDF5/impl/dataset.tpp +++ b/include/IO/HDF5/impl/dataset.tpp @@ -6,11 +6,6 @@ #include "native_type.hpp" #include -template -const H5::PredType specfem::IO::impl::HDF5::Dataset::native_type = - specfem::IO::impl::HDF5::native_type< - typename ViewType::non_const_value_type>::type; - // check if Kokkos version is < 4.1 #if KOKKOS_VERSION < 40100 template @@ -32,10 +27,11 @@ specfem::IO::impl::HDF5::Dataset::Dataset( dims[i] = data.extent(i); } return dims; - }())), - dataset(std::make_unique( - file->createDataSet(name, native_type, *dataspace))) { - ASSERT(data.span_is_contiguous() == true, "ViewType must be contiguous"); + }())) { + + this->dataset = std::make_unique( + file->createDataSet(name, native_type::type(), *dataspace)); + ASSERT(data.span_is_contiguous(), "ViewType must be contiguous"); } template @@ -50,22 +46,22 @@ specfem::IO::impl::HDF5::Dataset::Dataset( dims[i] = data.extent(i); } return dims; - }())), - dataset(std::make_unique( - group->createDataSet(name, native_type, *dataspace))) { + }())) { - ASSERT(data.span_is_contiguous() == true, "ViewType must be contiguous"); + this->dataset = std::make_unique( + group->createDataSet(name, native_type::type(), *dataspace)); + ASSERT(data.span_is_contiguous(), "ViewType must be contiguous"); } template void specfem::IO::impl::HDF5::Dataset::write() { if (std::is_same_v) { - dataset->write(data.data(), native_type); + dataset->write(data.data(), native_type::type()); return; } else if (std::is_same_v) { auto host_data = Kokkos::create_mirror_view(data); Kokkos::deep_copy(host_data, data); - dataset->write(host_data.data(), native_type); + dataset->write(host_data.data(), native_type::type()); return; } else { throw std::runtime_error("Unknown memory space"); diff --git a/include/IO/HDF5/impl/file.hpp b/include/IO/HDF5/impl/file.hpp index b9df652f..6ad163e6 100644 --- a/include/IO/HDF5/impl/file.hpp +++ b/include/IO/HDF5/impl/file.hpp @@ -3,7 +3,6 @@ #include "H5Cpp.h" #include "dataset.hpp" -#include "dataset.tpp" #include "group.hpp" #include #include diff --git a/include/IO/HDF5/impl/group.hpp b/include/IO/HDF5/impl/group.hpp index 72adf910..34f73f04 100644 --- a/include/IO/HDF5/impl/group.hpp +++ b/include/IO/HDF5/impl/group.hpp @@ -3,8 +3,6 @@ #include "H5Cpp.h" #include "dataset.hpp" -#include "dataset.tpp" -#include "file.hpp" #include #include diff --git a/include/IO/HDF5/impl/native_type.hpp b/include/IO/HDF5/impl/native_type.hpp index 985654ce..e44e25ba 100644 --- a/include/IO/HDF5/impl/native_type.hpp +++ b/include/IO/HDF5/impl/native_type.hpp @@ -8,7 +8,7 @@ namespace IO { namespace impl { namespace HDF5 { -template struct native_type { const static H5::PredType type; }; +template struct native_type {}; } // namespace HDF5 } // namespace impl } // namespace IO diff --git a/include/IO/HDF5/impl/native_type.tpp b/include/IO/HDF5/impl/native_type.tpp new file mode 100644 index 00000000..0c25fdce --- /dev/null +++ b/include/IO/HDF5/impl/native_type.tpp @@ -0,0 +1,112 @@ +#ifndef SPECFEM_IO_HDF5_IMPL_NATIVE_TYPE_TPP +#define SPECFEM_IO_HDF5_IMPL_NATIVE_TYPE_TPP + +#include "H5Cpp.h" +#include "native_type.hpp" +#include + +template <> struct specfem::IO::impl::HDF5::native_type { + static H5::IntType& type() { + static H5::IntType type(H5::PredType::NATIVE_INT); + type.setOrder(H5T_ORDER_LE); + return type; + } +}; + +template <> struct specfem::IO::impl::HDF5::native_type { + static H5::FloatType& type() { + static H5::FloatType type(H5::PredType::NATIVE_FLOAT); + type.setOrder(H5T_ORDER_LE); + return type; + } +}; + +template <> struct specfem::IO::impl::HDF5::native_type { + static H5::FloatType& type() { + static H5::FloatType type(H5::PredType::NATIVE_DOUBLE); + type.setOrder(H5T_ORDER_LE); + return type; + } +}; + +template <> struct specfem::IO::impl::HDF5::native_type { + static H5::IntType& type() { + static H5::IntType type(H5::PredType::NATIVE_LONG); + type.setOrder(H5T_ORDER_LE); + return type; + } +}; + +template <> struct specfem::IO::impl::HDF5::native_type { + static H5::IntType& type() { + static H5::IntType type(H5::PredType::NATIVE_LLONG); + type.setOrder(H5T_ORDER_LE); + return type; + } +}; + +template <> struct specfem::IO::impl::HDF5::native_type { + static H5::IntType& type() { + static H5::IntType type(H5::PredType::NATIVE_UINT); + type.setOrder(H5T_ORDER_LE); + return type; + } +}; + +template <> struct specfem::IO::impl::HDF5::native_type { + static H5::IntType& type() { + static H5::IntType type(H5::PredType::NATIVE_ULONG); + type.setOrder(H5T_ORDER_LE); + return type; + } +}; + +template <> struct specfem::IO::impl::HDF5::native_type { + static H5::IntType& type() { + static H5::IntType type(H5::PredType::NATIVE_ULLONG); + type.setOrder(H5T_ORDER_LE); + return type; + } +}; + +template <> struct specfem::IO::impl::HDF5::native_type { + static H5::IntType& type() { + static H5::IntType type(H5::PredType::NATIVE_UCHAR); + type.setOrder(H5T_ORDER_LE); + return type; + } +}; + +template <> struct specfem::IO::impl::HDF5::native_type { + static H5::IntType& type() { + static H5::IntType type(H5::PredType::NATIVE_CHAR); + type.setOrder(H5T_ORDER_LE); + return type; + } +}; + +template <> struct specfem::IO::impl::HDF5::native_type { + static H5::IntType& type() { + static H5::IntType type(H5::PredType::NATIVE_SHORT); + type.setOrder(H5T_ORDER_LE); + return type; + } +}; + +template <> struct specfem::IO::impl::HDF5::native_type { + static H5::IntType& type() { + static H5::IntType type(H5::PredType::NATIVE_USHORT); + type.setOrder(H5T_ORDER_LE); + return type; + } +}; + +template <> struct specfem::IO::impl::HDF5::native_type { + static H5::IntType& type() { + static H5::IntType type(H5::PredType::NATIVE_HBOOL); + type.setOrder(H5T_ORDER_LE); + return type; + } +}; + +#endif diff --git a/src/IO/HDF5/native_type.cpp b/src/IO/HDF5/native_type.cpp index cb616416..9ac03f2a 100644 --- a/src/IO/HDF5/native_type.cpp +++ b/src/IO/HDF5/native_type.cpp @@ -1,55 +1,31 @@ #include "IO/HDF5/impl/native_type.hpp" #include "H5Cpp.h" +#include "IO/HDF5/impl/native_type.tpp" -template <> -const H5::PredType specfem::IO::impl::HDF5::native_type::type = - H5::PredType::NATIVE_FLOAT; +// Explicit instantiation -template <> -const H5::PredType specfem::IO::impl::HDF5::native_type::type = - H5::PredType::NATIVE_DOUBLE; +template struct specfem::IO::impl::HDF5::native_type; -template <> -const H5::PredType specfem::IO::impl::HDF5::native_type::type = - H5::PredType::NATIVE_INT; +template struct specfem::IO::impl::HDF5::native_type; -template <> -const H5::PredType specfem::IO::impl::HDF5::native_type::type = - H5::PredType::NATIVE_LONG; +template struct specfem::IO::impl::HDF5::native_type; -template <> -const H5::PredType specfem::IO::impl::HDF5::native_type::type = - H5::PredType::NATIVE_LLONG; +template struct specfem::IO::impl::HDF5::native_type; -template <> -const H5::PredType specfem::IO::impl::HDF5::native_type::type = - H5::PredType::NATIVE_UINT; +template struct specfem::IO::impl::HDF5::native_type; -template <> -const H5::PredType specfem::IO::impl::HDF5::native_type::type = - H5::PredType::NATIVE_ULONG; +template struct specfem::IO::impl::HDF5::native_type; -template <> -const H5::PredType - specfem::IO::impl::HDF5::native_type::type = - H5::PredType::NATIVE_ULLONG; +template struct specfem::IO::impl::HDF5::native_type; -template <> -const H5::PredType specfem::IO::impl::HDF5::native_type::type = - H5::PredType::NATIVE_SHORT; +template struct specfem::IO::impl::HDF5::native_type; -template <> -const H5::PredType specfem::IO::impl::HDF5::native_type::type = - H5::PredType::NATIVE_USHORT; +template struct specfem::IO::impl::HDF5::native_type; -template <> -const H5::PredType specfem::IO::impl::HDF5::native_type::type = - H5::PredType::NATIVE_CHAR; +template struct specfem::IO::impl::HDF5::native_type; -template <> -const H5::PredType specfem::IO::impl::HDF5::native_type::type = - H5::PredType::NATIVE_UCHAR; +template struct specfem::IO::impl::HDF5::native_type; -template <> -const H5::PredType specfem::IO::impl::HDF5::native_type::type = - H5::PredType::NATIVE_HBOOL; +template struct specfem::IO::impl::HDF5::native_type; + +template struct specfem::IO::impl::HDF5::native_type; diff --git a/src/specfem2d.cpp b/src/specfem2d.cpp index fd2f7dd7..b19ebf57 100644 --- a/src/specfem2d.cpp +++ b/src/specfem2d.cpp @@ -145,6 +145,8 @@ void execute(const std::string ¶meter_file, const std::string &default_file, // -------------------------------------------------------------- // Generate Assembly // -------------------------------------------------------------- + mpi->cout("Generating assembly:"); + mpi->cout("-------------------------------"); const int nsteps = it->get_max_timestep(); const int max_seimogram_time_step = it->get_max_seismogram_step(); const specfem::compute::assembly assembly( @@ -155,6 +157,8 @@ void execute(const std::string ¶meter_file, const std::string &default_file, // -------------------------------------------------------------- // Instantiate Kernels // -------------------------------------------------------------- + mpi->cout("Instantiating Kernels:"); + mpi->cout("-------------------------------"); specfem::enums::element::quadrature::static_quadrature_points<5> qp5; specfem::domain::domain< @@ -234,143 +238,6 @@ void execute(const std::string ¶meter_file, const std::string &default_file, // -------------------------------------------------------------- return; - - // // Generate compute structs to be used by the solver - // specfem::compute::compute compute(mesh.coorg, mesh.material_ind.knods, - // gllx, - // gllz); - // specfem::compute::partial_derivatives partial_derivatives( - // mesh.coorg, mesh.material_ind.knods, gllx, gllz); - // specfem::compute::properties material_properties( - // mesh.material_ind.kmato, materials, mesh.nspec, gllx->get_N(), - // gllz->get_N()); - // specfem::compute::coupled_interfaces::coupled_interfaces - // coupled_interfaces( - // compute.h_ibool, compute.coordinates.coord, - // material_properties.h_ispec_type, mesh.coupled_interfaces); - // specfem::compute::boundaries boundary_conditions( - // mesh.material_ind.kmato, materials, mesh.acfree_surface, - // mesh.abs_boundary); - - // // Print spectral element information - // mpi->cout(mesh.print(materials)); - - // // Locate the sources - // for (auto &source : sources) - // source->locate(compute.coordinates.coord, compute.h_ibool, - // gllx->get_hxi(), - // gllz->get_hxi(), mesh.nproc, mesh.coorg, - // mesh.material_ind.knods, mesh.npgeo, - // material_properties.h_ispec_type, mpi); - - // for (auto &receiver : receivers) - // receiver->locate(compute.coordinates.coord, compute.h_ibool, - // gllx->get_hxi(), gllz->get_hxi(), mesh.nproc, - // mesh.coorg, mesh.material_ind.knods, mesh.npgeo, - // material_properties.h_ispec_type, mpi); - - // mpi->cout("Source Information:"); - // mpi->cout("-------------------------------"); - // if (mpi->main_proc()) { - // std::cout << "Number of sources : " << sources.size() << "\n" << - // std::endl; - // } - - // for (auto &source : sources) { - // mpi->cout(source->print()); - // } - - // mpi->cout("Receiver Information:"); - // mpi->cout("-------------------------------"); - // if (mpi->main_proc()) { - // std::cout << "Number of receivers : " << receivers.size() << "\n" - // << std::endl; - // } - - // for (auto &receiver : receivers) { - // mpi->cout(receiver->print()); - // } - - // // Update solver intialization time - // setup.update_t0(-1.0 * t0); - - // // Instantiate the solver and timescheme - // auto it = setup.instantiate_solver(); - - // // Setup solver compute struct - - // const type_real xmax = compute.coordinates.xmax; - // const type_real xmin = compute.coordinates.xmin; - // const type_real zmax = compute.coordinates.zmax; - // const type_real zmin = compute.coordinates.zmin; - - // specfem::compute::sources compute_sources(sources, gllx, gllz, xmax, xmin, - // zmax, zmin, mpi); - - // specfem::compute::receivers compute_receivers( - // receivers, setup.get_seismogram_types(), gllx, gllz, xmax, xmin, zmax, - // zmin, it->get_max_seismogram_step(), mpi); - - // // Instantiate domain classes - // const int nglob = specfem::utilities::compute_nglob(compute.h_ibool); - - // specfem::enums::element::quadrature::static_quadrature_points<5> qp5; - // specfem::domain::domain< - // specfem::enums::element::medium::acoustic, - // specfem::enums::element::quadrature::static_quadrature_points<5> > - // acoustic_domain_static(nglob, qp5, &compute, material_properties, - // partial_derivatives, boundary_conditions, - // compute_sources, compute_receivers, gllx, gllz); - // specfem::domain::domain< - // specfem::enums::element::medium::elastic, - // specfem::enums::element::quadrature::static_quadrature_points<5> > - // elastic_domain_static(nglob, qp5, &compute, material_properties, - // partial_derivatives, boundary_conditions, - // compute_sources, compute_receivers, gllx, gllz); - - // // Instantiate coupled interfaces - // specfem::coupled_interface::coupled_interface acoustic_elastic_interface( - // acoustic_domain_static, elastic_domain_static, coupled_interfaces, qp5, - // partial_derivatives, compute.ibool, gllx->get_w(), gllz->get_w()); - - // specfem::coupled_interface::coupled_interface elastic_acoustic_interface( - // elastic_domain_static, acoustic_domain_static, coupled_interfaces, qp5, - // partial_derivatives, compute.ibool, gllx->get_w(), gllz->get_w()); - - // // Instantiate the writer - // auto writer = - // setup.instantiate_seismogram_writer(receivers, compute_receivers); - - // std::shared_ptr solver = - // std::make_shared > - // >( acoustic_domain_static, elastic_domain_static, - // acoustic_elastic_interface, elastic_acoustic_interface, it); - - // mpi->cout("Executing time loop:"); - // mpi->cout("-------------------------------"); - - // const auto solver_start_time = std::chrono::high_resolution_clock::now(); - // solver->run(); - // const auto solver_end_time = std::chrono::high_resolution_clock::now(); - - // std::chrono::duration solver_time = - // solver_end_time - solver_start_time; - - // // Write only if a writer object has been defined - // if (writer) { - // mpi->cout("Writing seismogram files:"); - // mpi->cout("-------------------------------"); - - // writer->write(); - // } - - // mpi->cout("Cleaning up:"); - // mpi->cout("-------------------------------"); - - // mpi->cout(print_end_message(start_time, solver_time)); - - return; } int main(int argc, char **argv) {