From ed32c731902cc2f3627f6d03c2afa30cc47971d8 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Thu, 14 Apr 2022 00:37:50 +0200 Subject: [PATCH 01/23] tmp --- .gitmodules | 3 + CMakeLists.txt | 2 + data_assimilation/data_assimilation.py | 36 +++---- data_assimilation/main.py | 91 +++++++++-------- external/HighFive | 1 + src/dataAssimilation/FieldIO.cpp | 132 ++++++++++++------------- 6 files changed, 131 insertions(+), 134 deletions(-) create mode 160000 external/HighFive diff --git a/.gitmodules b/.gitmodules index d320d5f0..c2f7ee82 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "external/googletest"] path = external/googletest url = https://github.com/google/googletest/ +[submodule "external/HighFive"] + path = external/HighFive + url = https://github.com/BlueBrain/HighFive.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 8402a62b..d10ff13a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,6 +197,7 @@ add_subdirectory(gtests) add_subdirectory(src/dataAssimilation) add_subdirectory(src/TCP) +add_subdirectory(external/HighFive) get_target_property(ARTSS_SOURCE_FILES artss SOURCES) add_executable(artss_data_assimilation_serial ${ARTSS_SOURCE_FILES} src/main.cpp) target_compile_options(artss_data_assimilation_serial PUBLIC ${ARTSS_COMPILE_OPTIONS}) @@ -204,3 +205,4 @@ target_compile_options(artss_data_assimilation_serial PUBLIC -DASSIMILATION) target_link_libraries(artss_data_assimilation_serial PRIVATE spdlog::spdlog) target_link_libraries(artss_data_assimilation_serial PRIVATE fmt::fmt) target_link_libraries(artss_data_assimilation_serial PRIVATE MPI::MPI_CXX) +target_link_libraries(artss_data_assimilation_serial PRIVATE HighFive) diff --git a/data_assimilation/data_assimilation.py b/data_assimilation/data_assimilation.py index 0d8c6f41..50d5857c 100644 --- a/data_assimilation/data_assimilation.py +++ b/data_assimilation/data_assimilation.py @@ -1,5 +1,9 @@ -import wsgiref.validate +#!/usr/bin/env python3 + +import struct from datetime import datetime + +import wsgiref.validate import numpy as np @@ -8,16 +12,17 @@ def get_date_now() -> str: def write_field_data(file_name: str, data: dict, field_keys: list): - file = open(file_name, 'w') - for key in field_keys: - if key in data.keys(): + n = len(set(data.keys()).intersection(field_keys)) + m = len(data[list(data.keys())[0]]) + with open(file_name, 'wb') as out: + out.write(struct.pack('qq', n, m)) + for key in field_keys: + if key not in data.keys(): + continue + field = data[key] - line = '' - for number in field: - line += f'{number};' - line += '\n' - file.write(line) - file.close() + for i in field: + out.write(struct.pack('d', i)) class FieldReader: @@ -115,13 +120,4 @@ def read_field_data(self, time_step: float) -> dict: return fields def write_field_data(self, file_name: str, data: dict): - file = open(file_name, 'w') - for key in self.fields: - if key in data.keys(): - field = data[key] - line = '' - for number in field: - line += f'{number};' - line += '\n' - file.write(line) - file.close() + write_field_data(file_name=file_name, data=data, field_keys=self.fields) diff --git a/data_assimilation/main.py b/data_assimilation/main.py index a6fec78c..f5ece15f 100644 --- a/data_assimilation/main.py +++ b/data_assimilation/main.py @@ -60,6 +60,49 @@ def create_gradient_field(Nx: int, Ny: int, Nz: int) -> ndarray: return field +def gradient_tmp(): + reader = FieldReader() + reader.print_header() + + xml = XML(reader.get_xml_file_name()) + xml.read_xml() + domain = Domain(xml.domain, xml.obstacles) + domain.print_info() + domain.print_debug() + + dt = reader.dt + + t_cur = reader.get_t_current() + + n = int(t_cur/dt) + i = 300 + j = 15 + k = 16 + sensor_data= [] + print('iter') + f = open('visualisation.dat', 'r') + for i in range(6): + f.readline() + for i in range(1,34): + print(i, i * dt) + fields = [] + for i in range(6): + fields.append(np.fromstring(f.readline(), dtype=np.float, sep=';')) + sensor_data.append(fields[4][domain.calculate_index(i, j, k)]) + f.readline() + f.close() + print("plot") + f = open('tmp.tmp', 'w') + for i in sensor_data: + f.write(str(i) + "\n") + f.close() + #f = open('tmp.tmp', 'r') + #for i in f: + # sensor_data.append(float(i)) + plt.plot(sensor_data) + plt.show() + + def main(dry_run=False): cwd = os.getcwd() print(cwd) @@ -99,6 +142,8 @@ def main(dry_run=False): fields['T'] = field field_file_name = f'T_{t_cur}.dat' if dry_run: + for k in fields: + print((k, len(fields[k]))) data_assimilation.write_field_data(file_name=field_file_name, data=fields, field_keys=['u', 'v', 'w', 'p', 'T', 'C']) else: @@ -122,51 +167,5 @@ def main(dry_run=False): client.send_message(create_message(t, config_file_name)) -def gradient_tmp(): - - reader = FieldReader() - reader.print_header() - - xml = XML(reader.get_xml_file_name()) - xml.read_xml() - domain = Domain(xml.domain, xml.obstacles) - domain.print_info() - domain.print_debug() - - dt = reader.dt - - t_cur = reader.get_t_current() - - n = int(t_cur/dt) - i = 300 - j = 15 - k = 16 - sensor_data= [] - print('iter') - f = open('visualisation.dat', 'r') - for i in range(6): - f.readline() - for i in range(1,34): - print(i, i * dt) - fields = [] - for i in range(6): - fields.append(np.fromstring(f.readline(), dtype=np.float, sep=';')) - sensor_data.append(fields[4][domain.calculate_index(i, j, k)]) - f.readline() - f.close() - print("plot") - f = open('tmp.tmp', 'w') - for i in sensor_data: - f.write(str(i) + "\n") - f.close() - #f = open('tmp.tmp', 'r') - #for i in f: - # sensor_data.append(float(i)) - plt.plot(sensor_data) - plt.show() - - - if __name__ == '__main__': - #gradient_tmp() main(dry_run=False) diff --git a/external/HighFive b/external/HighFive new file mode 160000 index 00000000..8200f8f6 --- /dev/null +++ b/external/HighFive @@ -0,0 +1 @@ +Subproject commit 8200f8f6faa24bb46a38f6150671ba865403ec14 diff --git a/src/dataAssimilation/FieldIO.cpp b/src/dataAssimilation/FieldIO.cpp index 5d2ba69d..ad44e7eb 100644 --- a/src/dataAssimilation/FieldIO.cpp +++ b/src/dataAssimilation/FieldIO.cpp @@ -12,6 +12,10 @@ #include #include + +#include +#include + #include "../domain/DomainData.h" @@ -90,9 +94,8 @@ void FieldIO::read_fields(real t_cur, Field &u, Field &v, Field &w, Field &p, Fi long pos = m_positions[n]; m_logger->debug("times: {:>10d} read from: {:>20d}", n, m_positions[n]); std::string line; - input_file.seekg(pos); + // input_file.seekg(pos); - std::getline(input_file, line); m_logger->debug("read time step {}", line); read_field(input_file, u); @@ -132,24 +135,32 @@ std::string FieldIO::create_header(const std::string &xml_file_name) { } void FieldIO::read_field(std::ifstream &file_stream, Field &field) { - std::string line; - auto to_double = [](const auto &v) { return std::stod(v); }; + int n; + m_logger->info("attempting to read m{} doubls from stream", n); + file_stream.read((char *)&n, sizeof(n)); + std::cout << "n" << sizeof(n) << ":" << n << ":" << file_stream.tellg() << std::endl; + m_logger->info("attempting to read {} doubls from stream", n); + for(int i=0; i divided_string = Utility::split(line, ';'); - std::transform(divided_string.begin(), divided_string.end(), field.data, to_double); + } } void FieldIO::read_fields(const Settings::data_assimilation::field_changes &field_changes, Field &u, Field &v, Field &w, Field &p, Field &T, Field &C) { + int n; std::string line; if (!field_changes.changed) { return; } // no changes -> read original file + m_logger->info("opening dat file {}", field_changes.file_name); std::ifstream file_changes(field_changes.file_name, std::ifstream::binary); + + m_logger->info("dat file contains {} fields", n); if (file_changes.is_open()) { // could not open file -> read original file + warning + file_changes.read((char *)&n, sizeof(n)); if (field_changes.u_changed) { read_field(file_changes, u); m_logger->debug("read changed u Field"); @@ -184,71 +195,56 @@ void FieldIO::read_fields(const real t_cur, const Settings::data_assimilation::field_changes &field_changes, Field &u, Field &v, Field &w, Field &p, Field &T, Field &C) { - std::ifstream file_original(m_file_name, std::ifstream::binary); - size_t n = static_cast(std::round(t_cur / DomainData::getInstance()->get_physical_parameters().dt)) - 1; - file_original.seekg(m_positions[n]); + m_logger->debug("read time step {}", t_cur); + if (field_changes.changed) { // no changes -> read original file + m_logger->debug("no field changes"); + read_fields(t_cur, u, v, w, p, T, C); + return; + } - std::string line; - std::getline(file_original, line); - m_logger->debug("read time step {}", line); + try { + HighFive::File org_file(m_file_name, HighFive::File::ReadOnly); + HighFive::File new_file(field_changes.file_name, HighFive::File::ReadOnly); - if (field_changes.changed) { // no changes -> read original file - std::ifstream file_changes(field_changes.file_name, std::ifstream::binary); - if (file_changes.is_open()) { // could not open file -> read original file + warning - if (field_changes.u_changed) { - read_field(file_changes, u); - std::getline(file_original, line); - m_logger->debug("read changed u Field"); - } else { - read_field(file_original, u); - std::getline(file_changes, line); - } - if (field_changes.v_changed) { - read_field(file_changes, v); - std::getline(file_original, line); - m_logger->debug("read changed v Field"); - } else { - read_field(file_original, v); - std::getline(file_changes, line); - } - if (field_changes.w_changed) { - read_field(file_changes, w); - std::getline(file_original, line); - m_logger->debug("read changed w Field"); - } else { - read_field(file_original, w); - std::getline(file_changes, line); - } - if (field_changes.p_changed) { - read_field(file_changes, p); - std::getline(file_original, line); - m_logger->debug("read changed p Field"); - } else { - read_field(file_original, p); - std::getline(file_changes, line); - } - if (field_changes.T_changed) { - read_field(file_changes, T); - std::getline(file_original, line); - m_logger->debug("read changed T Field"); - } else { - read_field(file_original, T); - std::getline(file_changes, line); - } - if (field_changes.C_changed) { - read_field(file_changes, C); - std::getline(file_original, line); - m_logger->debug("read changed C Field"); - } else { - read_field(file_original, C); - std::getline(file_changes, line); - } + if (field_changes.u_changed) { + read_field(new_file, u); + m_logger->debug("read changed u Field"); } else { - m_logger->warn(fmt::format("File '{}' could not be opened, original data will be loaded", field_changes.file_name)); - read_fields(t_cur, u, v, w, p, T, C); + read_field(org_file, u); } - } else { - m_logger->debug("no field changes"); + if (field_changes.v_changed) { + read_field(new_file, v); + m_logger->debug("read changed v Field"); + } else { + read_field(org_file, v); + } + if (field_changes.w_changed) { + read_field(new_file, w); + m_logger->debug("read changed w Field"); + } else { + read_field(org_file, w); + } + if (field_changes.p_changed) { + read_field(new_file, p); + m_logger->debug("read changed p Field"); + } else { + read_field(org_file, p); + } + if (field_changes.T_changed) { + read_field(new_file, T); + m_logger->debug("read changed T Field"); + } else { + read_field(org_file, T); + } + if (field_changes.C_changed) { + read_field(new_file, C); + m_logger->debug("read changed C Field"); + } else { + read_field(org_file, C); + } + } catch (const std::exception &ex) { + m_logger->warn(fmt::format("File '{}' could not be opened, original data will be loaded", field_changes.file_name)); + m_logger->warn(fmt::format("Exception during reading {}", ex.what())); read_fields(t_cur, u, v, w, p, T, C); } } From 5cb30f0a6fa3c071a4a094251cad0fc846788c1a Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Thu, 14 Apr 2022 03:49:41 +0200 Subject: [PATCH 02/23] field 'p' has wrong typ? --- data_assimilation/data_assimilation.py | 35 +++----- src/dataAssimilation/FieldIO.cpp | 118 +++++++++++-------------- src/dataAssimilation/FieldIO.h | 9 +- 3 files changed, 73 insertions(+), 89 deletions(-) diff --git a/data_assimilation/data_assimilation.py b/data_assimilation/data_assimilation.py index 50d5857c..f40cf1eb 100644 --- a/data_assimilation/data_assimilation.py +++ b/data_assimilation/data_assimilation.py @@ -3,6 +3,7 @@ import struct from datetime import datetime +import h5py import wsgiref.validate import numpy as np @@ -12,17 +13,14 @@ def get_date_now() -> str: def write_field_data(file_name: str, data: dict, field_keys: list): - n = len(set(data.keys()).intersection(field_keys)) - m = len(data[list(data.keys())[0]]) - with open(file_name, 'wb') as out: - out.write(struct.pack('qq', n, m)) + with h5py.File(file_name, 'w') as out: for key in field_keys: if key not in data.keys(): continue + print(key) field = data[key] - for i in field: - out.write(struct.pack('d', i)) + out.create_dataset(key, (len(field), ), dtype='d') class FieldReader: @@ -37,23 +35,14 @@ def __init__(self): self.read_header() def read_header(self): - fname = open(self.file_name, 'r') - # first line - line = fname.readline() - self.dt = float(line.split(';')[3]) - # second line - line = fname.readline().split(';')[1:] - self.grid_resolution = {'Nx': int(line[0]), 'Ny': int(line[1]), 'Nz': int(line[2])} - # third line - line = fname.readline().strip() - self.fields = line.split(';')[1:] - # fourth line - line = fname.readline().strip() - self.date = datetime.strptime(line.split(';')[1], '%a %b %d %H:%M:%S %Y') - # fifth line - line = fname.readline().strip() - self.xml_file_name = line.split(';')[1] - fname.close() + with h5py.File(self.file_name, 'r') as inp: + print(inp.keys()) + metadata = inp['metadata'] + self.dt = metadata['dt'][()] + self.grid_resolution = list(metadata['domain'][:]) + self.fields = list(metadata['fields'].asstr()[:]) + self.date = datetime.strptime(metadata['date'].asstr()[()][0].strip(), '%a %b %d %H:%M:%S %Y') + self.xml_file_name = metadata['xml'][()][0] def print_header(self): print(f'dt: {self.dt}') diff --git a/src/dataAssimilation/FieldIO.cpp b/src/dataAssimilation/FieldIO.cpp index ad44e7eb..88bcf975 100644 --- a/src/dataAssimilation/FieldIO.cpp +++ b/src/dataAssimilation/FieldIO.cpp @@ -13,10 +13,8 @@ #include #include -#include -#include - #include "../domain/DomainData.h" +#include "../utility/Mapping.h" FieldIO::FieldIO(const std::string &xml_file_name, const std::string &output_file_name) : @@ -29,12 +27,8 @@ FieldIO::FieldIO(const std::string &xml_file_name, const std::string &output_fil size_t n = static_cast(std::round(t_end / domain_data->get_physical_parameters().dt)) + 1; m_positions = new long[n]; - std::string header = create_header(xml_file_name); - m_positions[0] = static_cast(header.length()) + 1; - - std::ofstream output_file(m_file_name, std::ios_base::out); - output_file.write(header.c_str(), m_positions[0]); - output_file.close(); + HighFive::File out_file(m_file_name, HighFive::File::ReadWrite | HighFive::File::Create); + create_header(out_file, xml_file_name); } @@ -50,30 +44,24 @@ FieldIO::FieldIO(const std::string &xml_file_name, const std::string &output_fil /// \param C data of field C to be written out // ************************************************************************************************* void FieldIO::write_fields(real t_cur, Field &u, Field &v, Field &w, Field &p, Field &T, Field &C) { - std::string output = fmt::format("{:.5e}\n", t_cur); - Field fields[] = {u, v, w, p, T, C}; + HighFive::File out_file(m_file_name, HighFive::File::ReadWrite); + auto group_name = fmt::format("{:.5e}", t_cur); + m_logger->error("attempt to write @t:{}", t_cur); + + if (out_file.exist(group_name)) { + out_file.unlink(group_name); + } + + HighFive::Group t_group = out_file.createGroup(group_name); + // Field fields[] = {u, v, w, p, T, C}; + Field fields[] = {u, v, w, T, C}; size_t size = u.get_size(); + std::vector dims{1, size}; for (Field &f: fields) { - for (size_t i = 0; i < size - 1; i++) { - output.append(fmt::format(("{};"), f[i])); - } - output.append(fmt::format(("{}\n"), f[size - 1])); + auto field_name = Mapping::get_field_type_name(f.get_type()); + m_logger->error("attempt to write @t:{}:{}", t_cur, field_name); + t_group.createDataSet(field_name, HighFive::DataSpace(dims)); } - size_t n = static_cast(std::round(t_cur / DomainData::getInstance()->get_physical_parameters().dt)) - 1; - long length = static_cast(output.length()); - m_positions[n + 1] = m_positions[n] + length; - - std::fstream output_file(m_file_name); - // write field at position dependent on time step - m_logger->debug("times: {:>10d} write to: {:>20d}", n, m_positions[n]); - output_file.seekp(m_positions[n], std::ios_base::beg); - output_file.write(output.c_str(), length); - - // overwrite current time step - output_file.seekp(m_pos_time_step, std::ios_base::beg); - output_file.write(fmt::format("{:.5e}", t_cur).c_str(), 11); - - output_file.close(); } // ========================================== read ================================================= @@ -89,14 +77,7 @@ void FieldIO::write_fields(real t_cur, Field &u, Field &v, Field &w, Field &p, F // ************************************************************************************************* void FieldIO::read_fields(real t_cur, Field &u, Field &v, Field &w, Field &p, Field &T, Field &C) { m_logger->debug("read original data"); - std::ifstream input_file(m_file_name, std::ifstream::binary); - size_t n = static_cast(std::round(t_cur / DomainData::getInstance()->get_physical_parameters().dt)) - 1; - long pos = m_positions[n]; - m_logger->debug("times: {:>10d} read from: {:>20d}", n, m_positions[n]); - std::string line; - // input_file.seekg(pos); - - m_logger->debug("read time step {}", line); + HighFive::File input_file(m_file_name, HighFive::File::ReadOnly); read_field(input_file, u); read_field(input_file, v); @@ -114,36 +95,46 @@ void FieldIO::read_fields(real t_cur, Field &u, Field &v, Field &w, Field &p, Fi /// ###FIELDS;u;v;w;p;T;concentration /// ###DATE:;XML: // ************************************************************************************************* -std::string FieldIO::create_header(const std::string &xml_file_name) { +void FieldIO::create_header(HighFive::File &file, const std::string &xml_file_name) { auto end = std::chrono::system_clock::now(); std::time_t end_time = std::chrono::system_clock::to_time_t(end); + if (file.exist("metadata")) { + file.unlink("metadata"); + } + HighFive::Group meta_group = file.createGroup("metadata"); + auto domain_data = DomainData::getInstance(); + + auto dt = domain_data->get_physical_parameters().dt; + HighFive::DataSet dt_set = meta_group.createDataSet("dt", HighFive::DataSpace::From(dt)); + dt_set.write(dt); + size_t Nx = domain_data->get_number_of_cells(CoordinateAxis::X); size_t Ny = domain_data->get_number_of_cells(CoordinateAxis::Y); size_t Nz = domain_data->get_number_of_cells(CoordinateAxis::Z); - std::string string_t_cur_text = "Current time step;"; - m_pos_time_step = static_cast(string_t_cur_text.length()); - std::string header = fmt::format("{}{:.5e};dt;{}\n", string_t_cur_text, 0.0, - DomainData::getInstance()->get_physical_parameters().dt); - header.append(fmt::format("###DOMAIN;{};{};{}\n", Nx, Ny, Nz)); - header.append(fmt::format("###FIELDS;u;v;w;p;T;concentration\n")); - header.append(fmt::format("###DATE;{}", std::ctime(&end_time))); - header.append(fmt::format("###XML;{}\n", xml_file_name)); - return header; -} + size_t domain[3] = {Nx, Ny, Nz}; + HighFive::DataSet domain_set = meta_group.createDataSet("domain", HighFive::DataSpace::From(domain)); + domain_set.write(domain); -void FieldIO::read_field(std::ifstream &file_stream, Field &field) { - int n; - m_logger->info("attempting to read m{} doubls from stream", n); - file_stream.read((char *)&n, sizeof(n)); - std::cout << "n" << sizeof(n) << ":" << n << ":" << file_stream.tellg() << std::endl; - m_logger->info("attempting to read {} doubls from stream", n); - for(int i=0; i fields{"u" , "v", "w", "p", "T", "concentration"}; + HighFive::DataSet fields_set = meta_group.createDataSet("fields", HighFive::DataSpace::From(fields)); + fields_set.write(fields); - } + std::string date[1] = {std::ctime(&end_time)}; + HighFive::DataSet date_set = meta_group.createDataSet("date", HighFive::DataSpace::From(date)); + date_set.write(date); + + std::string xml[1] = {xml_file_name}; + HighFive::DataSet xml_set = meta_group.createDataSet("xml", HighFive::DataSpace::From(date)); + xml_set.write(xml); +} + +void FieldIO::read_field(HighFive::File &file, Field &field) { + auto field_name = Mapping::get_field_type_name(field.get_type()); + auto ds = file.getDataSet(field_name); + ds.read(field.data); } void FieldIO::read_fields(const Settings::data_assimilation::field_changes &field_changes, @@ -154,17 +145,15 @@ void FieldIO::read_fields(const Settings::data_assimilation::field_changes &fiel if (!field_changes.changed) { return; } + // no changes -> read original file m_logger->info("opening dat file {}", field_changes.file_name); - std::ifstream file_changes(field_changes.file_name, std::ifstream::binary); + try { + HighFive::File file_changes(field_changes.file_name, HighFive::File::ReadOnly); - m_logger->info("dat file contains {} fields", n); - if (file_changes.is_open()) { // could not open file -> read original file + warning - file_changes.read((char *)&n, sizeof(n)); if (field_changes.u_changed) { read_field(file_changes, u); m_logger->debug("read changed u Field"); - std::getline(file_changes, line); } if (field_changes.v_changed) { read_field(file_changes, v); @@ -186,8 +175,9 @@ void FieldIO::read_fields(const Settings::data_assimilation::field_changes &fiel read_field(file_changes, C); m_logger->debug("read changed C Field"); } - } else { + } catch (const std::exception &ex) { m_logger->warn(fmt::format("File '{}' could not be opened. No changes will be applied.", field_changes.file_name)); + m_logger->warn(fmt::format("Exception during reading {}", ex.what())); } } diff --git a/src/dataAssimilation/FieldIO.h b/src/dataAssimilation/FieldIO.h index 1eb9ae7a..1833afc9 100644 --- a/src/dataAssimilation/FieldIO.h +++ b/src/dataAssimilation/FieldIO.h @@ -9,6 +9,11 @@ #include #include +#include + +#include +#include + #include "../field/FieldController.h" #include "../utility/Utility.h" #include "../solver/SolverController.h" @@ -27,7 +32,7 @@ class FieldIO { Field &p, Field &T, Field &C); private: - std::string create_header(const std::string &xml_file_name); + void create_header(HighFive::File &file, const std::string &xml_file_name); void read_fields(real t_cur, Field &u, Field &v, Field &w, Field &p, Field &T, Field &C); long *m_positions; @@ -36,7 +41,7 @@ class FieldIO { long m_pos_time_step; std::shared_ptr m_logger; - void read_field(std::ifstream &file_stream, Field &field); + void read_field(HighFive::File &file, Field &field); }; #endif /* ARTSS_VISUALISATION_FIELDIO_H */ From 338b3484206d89f797e559346873e130831097c5 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Thu, 21 Apr 2022 17:30:35 +0200 Subject: [PATCH 03/23] reading/writing of visualation.dat working --- data_assimilation/data_assimilation.py | 56 +++++++++----------------- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/data_assimilation/data_assimilation.py b/data_assimilation/data_assimilation.py index f40cf1eb..693d5678 100644 --- a/data_assimilation/data_assimilation.py +++ b/data_assimilation/data_assimilation.py @@ -8,6 +8,14 @@ import numpy as np +def is_float(x: str) -> bool: + try: + float(x) + return True + except ValueError: + return False + + def get_date_now() -> str: return datetime.now().strftime('%a %b %d %H:%M:%S %Y') @@ -51,37 +59,13 @@ def print_header(self): print(f'date: {self.date}') print(f'xml file name: {self.xml_file_name}') - def get_line_from_file(self, line_number: int) -> str: - return self.get_lines_from_file([line_number])[0] - - def get_pos_from_all_time_steps(self, line_numbers: list) -> list: - lines = [] - max_val = max(line_numbers) - file = open(self.file_name, 'r') - for i, line in enumerate(file): - if i in line_numbers: - lines.append(line) - if i > max_val: - break - file.close() - return lines - - def get_lines_from_file(self, line_numbers: list) -> list: - lines = [] - max_val = max(line_numbers) - file = open(self.file_name, 'r') - for i, line in enumerate(file): - if i in line_numbers: - lines.append(line) - if i > max_val: - break - file.close() - return lines + + def get_ts(self) -> [float]: + with h5py.File(self.file_name, 'r') as inp: + return sorted([float(x) for x in inp if is_float(x)]) def get_t_current(self) -> float: - first_line = self.get_line_from_file(0) - t_cur = first_line.split(';')[1] - return float(t_cur) + return self.get_ts()[-1] def get_xml_file_name(self) -> str: return self.xml_file_name @@ -98,14 +82,14 @@ def read_field_data(self, time_step: float) -> dict: print(f'cannot read time step {time_step} as the current time step is {t_cur}') return {} else: - number_of_fields = len(self.fields) - steps = int(time_step / self.dt) - 1 - - starting_line = 5 + (number_of_fields + 1) * steps + 1 - lines = self.get_lines_from_file(list(range(starting_line, starting_line + number_of_fields + 1))) fields = {} - for i in range(number_of_fields): - fields[self.fields[i]] = np.fromstring(lines[i], dtype=np.float, sep=';') + print(f'read time step {time_step}') + with h5py.File(self.file_name, 'r') as inp: + inp = inp[f'/{time_step:.5e}'] + for i in inp: + fields[i] = np.array(inp[i][0]) + print(f'read field: {i} {fields[i].shape}') + return fields def write_field_data(self, file_name: str, data: dict): From a873400723cbb0f1e563c128be0f199949d73208 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Thu, 21 Apr 2022 18:20:36 +0200 Subject: [PATCH 04/23] reading/writing of org and vis file working --- data_assimilation/data_assimilation.py | 2 -- src/dataAssimilation/FieldIO.cpp | 36 ++++++++++++++++---------- src/dataAssimilation/FieldIO.h | 1 + 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/data_assimilation/data_assimilation.py b/data_assimilation/data_assimilation.py index 693d5678..6edab3c9 100644 --- a/data_assimilation/data_assimilation.py +++ b/data_assimilation/data_assimilation.py @@ -26,7 +26,6 @@ def write_field_data(file_name: str, data: dict, field_keys: list): if key not in data.keys(): continue - print(key) field = data[key] out.create_dataset(key, (len(field), ), dtype='d') @@ -44,7 +43,6 @@ def __init__(self): def read_header(self): with h5py.File(self.file_name, 'r') as inp: - print(inp.keys()) metadata = inp['metadata'] self.dt = metadata['dt'][()] self.grid_resolution = list(metadata['domain'][:]) diff --git a/src/dataAssimilation/FieldIO.cpp b/src/dataAssimilation/FieldIO.cpp index 88bcf975..e5d910f7 100644 --- a/src/dataAssimilation/FieldIO.cpp +++ b/src/dataAssimilation/FieldIO.cpp @@ -46,7 +46,7 @@ FieldIO::FieldIO(const std::string &xml_file_name, const std::string &output_fil void FieldIO::write_fields(real t_cur, Field &u, Field &v, Field &w, Field &p, Field &T, Field &C) { HighFive::File out_file(m_file_name, HighFive::File::ReadWrite); auto group_name = fmt::format("{:.5e}", t_cur); - m_logger->error("attempt to write @t:{}", t_cur); + m_logger->debug("attempt to write @t:{}", t_cur); if (out_file.exist(group_name)) { out_file.unlink(group_name); @@ -59,7 +59,7 @@ void FieldIO::write_fields(real t_cur, Field &u, Field &v, Field &w, Field &p, F std::vector dims{1, size}; for (Field &f: fields) { auto field_name = Mapping::get_field_type_name(f.get_type()); - m_logger->error("attempt to write @t:{}:{}", t_cur, field_name); + m_logger->debug("attempt to write @t:{}:{}", t_cur, field_name); t_group.createDataSet(field_name, HighFive::DataSpace(dims)); } } @@ -79,12 +79,12 @@ void FieldIO::read_fields(real t_cur, Field &u, Field &v, Field &w, Field &p, Fi m_logger->debug("read original data"); HighFive::File input_file(m_file_name, HighFive::File::ReadOnly); - read_field(input_file, u); - read_field(input_file, v); - read_field(input_file, w); - read_field(input_file, p); - read_field(input_file, T); - read_field(input_file, C); + read_vis_field(input_file, u, t_cur); + read_vis_field(input_file, v, t_cur); + read_vis_field(input_file, w, t_cur); + // read_vis_field(input_file, p, t_cur); + read_vis_field(input_file, T, t_cur); + read_vis_field(input_file, C, t_cur); } // ================================= write header ================================================== @@ -137,6 +137,14 @@ void FieldIO::read_field(HighFive::File &file, Field &field) { ds.read(field.data); } +void FieldIO::read_vis_field(HighFive::File &file, Field &field, const real t) { + auto field_name = Mapping::get_field_type_name(field.get_type()); + auto full_name = fmt::format("/{:.5e}/{}", t, field_name); + m_logger->info("opening vis file at {}", full_name); + auto ds = file.getDataSet(full_name); + ds.read(field.data); +} + void FieldIO::read_fields(const Settings::data_assimilation::field_changes &field_changes, Field &u, Field &v, Field &w, Field &p, Field &T, Field &C) { @@ -200,37 +208,37 @@ void FieldIO::read_fields(const real t_cur, read_field(new_file, u); m_logger->debug("read changed u Field"); } else { - read_field(org_file, u); + read_vis_field(org_file, u, t_cur); } if (field_changes.v_changed) { read_field(new_file, v); m_logger->debug("read changed v Field"); } else { - read_field(org_file, v); + read_vis_field(org_file, v, t_cur); } if (field_changes.w_changed) { read_field(new_file, w); m_logger->debug("read changed w Field"); } else { - read_field(org_file, w); + read_vis_field(org_file, w, t_cur); } if (field_changes.p_changed) { read_field(new_file, p); m_logger->debug("read changed p Field"); } else { - read_field(org_file, p); + read_vis_field(org_file, p, t_cur); } if (field_changes.T_changed) { read_field(new_file, T); m_logger->debug("read changed T Field"); } else { - read_field(org_file, T); + read_vis_field(org_file, T, t_cur); } if (field_changes.C_changed) { read_field(new_file, C); m_logger->debug("read changed C Field"); } else { - read_field(org_file, C); + read_vis_field(org_file, C, t_cur); } } catch (const std::exception &ex) { m_logger->warn(fmt::format("File '{}' could not be opened, original data will be loaded", field_changes.file_name)); diff --git a/src/dataAssimilation/FieldIO.h b/src/dataAssimilation/FieldIO.h index 1833afc9..055a1604 100644 --- a/src/dataAssimilation/FieldIO.h +++ b/src/dataAssimilation/FieldIO.h @@ -42,6 +42,7 @@ class FieldIO { std::shared_ptr m_logger; void read_field(HighFive::File &file, Field &field); + void read_vis_field(HighFive::File &file, Field &field, const real t); }; #endif /* ARTSS_VISUALISATION_FIELDIO_H */ From 587edf0014d04dd5b0a83207ae34f25f7da96b73 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Thu, 5 May 2022 11:54:02 +0200 Subject: [PATCH 05/23] added mpich for githubworflow --- .github/workflows/ccpp.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index b013dfc9..4eddb4f3 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -16,6 +16,7 @@ jobs: - name: compile run: | git submodule update --init + sudo apt-get install -y mpich ./compile.sh --jobs 4 --gcc -s --checkout build-gcc-serial-benchmarking: @@ -27,6 +28,7 @@ jobs: - name: compile run: | git submodule update --init + sudo apt-get install -y mpich ./compile.sh --jobs 4 --gcc --sb --checkout build-pgi-multicore: From 9eabbd45e8b13bbf045fb921824f17e6e2fbfff4 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Thu, 5 May 2022 11:59:28 +0200 Subject: [PATCH 06/23] added hdf5 libs for githubworflow --- .github/workflows/ccpp.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 4eddb4f3..8d3018b3 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -16,7 +16,7 @@ jobs: - name: compile run: | git submodule update --init - sudo apt-get install -y mpich + sudo apt-get install -y mpich libhdf5-dev ./compile.sh --jobs 4 --gcc -s --checkout build-gcc-serial-benchmarking: @@ -28,7 +28,7 @@ jobs: - name: compile run: | git submodule update --init - sudo apt-get install -y mpich + sudo apt-get install -y mpich libhdf5-dev ./compile.sh --jobs 4 --gcc --sb --checkout build-pgi-multicore: From 09eb985e7fdc9fdb613734399e6578ed37c25900 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Thu, 5 May 2022 12:03:55 +0200 Subject: [PATCH 07/23] removed Boost support for HighFive --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d10ff13a..1cf05d0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -198,6 +198,8 @@ add_subdirectory(gtests) add_subdirectory(src/dataAssimilation) add_subdirectory(src/TCP) add_subdirectory(external/HighFive) +set(HIGHFIVE_USE_BOOST OFF) + get_target_property(ARTSS_SOURCE_FILES artss SOURCES) add_executable(artss_data_assimilation_serial ${ARTSS_SOURCE_FILES} src/main.cpp) target_compile_options(artss_data_assimilation_serial PUBLIC ${ARTSS_COMPILE_OPTIONS}) From 7316692ab636a395b02e363409be9b343d9a93ce Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Thu, 5 May 2022 12:05:33 +0200 Subject: [PATCH 08/23] removed Boost support for HighFive --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cf05d0b..56a11219 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,8 +197,9 @@ add_subdirectory(gtests) add_subdirectory(src/dataAssimilation) add_subdirectory(src/TCP) -add_subdirectory(external/HighFive) + set(HIGHFIVE_USE_BOOST OFF) +add_subdirectory(external/HighFive) get_target_property(ARTSS_SOURCE_FILES artss SOURCES) add_executable(artss_data_assimilation_serial ${ARTSS_SOURCE_FILES} src/main.cpp) From bbc468c758019105bc5261d18e7ae5a932ef8f54 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 14:05:37 +0200 Subject: [PATCH 09/23] added benchmark support --- .github/workflows/benchmark.yml | 34 ++++++++++++++++++++ .gitmodules | 3 ++ CMakeLists.txt | 13 ++++++++ benchmarks/CMakeLists.txt | 13 ++++++++ benchmarks/Environment.h | 25 +++++++++++++++ benchmarks/field/CMakeLists.txt | 4 +++ benchmarks/field/Field.cpp | 56 +++++++++++++++++++++++++++++++++ external/benchmark | 1 + external/googletest | 2 +- 9 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/benchmark.yml create mode 100644 benchmarks/CMakeLists.txt create mode 100644 benchmarks/Environment.h create mode 100644 benchmarks/field/CMakeLists.txt create mode 100644 benchmarks/field/Field.cpp create mode 160000 external/benchmark diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 00000000..a798ce0e --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,34 @@ +name: Benchmark +on: + push: + branches: + - test_benchmarking + +jobs: + benchmark: + name: Benchmark + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + - name: compile + run: | + git submodule update --init + mkdir build + ./compile.sh --docker-build + docker run -i --rm -v $(pwd):/host_pwd -w /host_pwd artss_docker sh -c "cd build && cmake .. && make artss_bench && ./benchmarks/bin/artss_bench --benchmark_format=json | tee ../benchmark_result.json" + - name: Download previous benchmark data + uses: actions/cache@v1 + with: + path: ./cache + key: ${{ runner.os }}-benchmark + + - name: Store benchmark result + uses: benchmark-action/github-action-benchmark@v1 + with: + # What benchmark tool the output.txt came from + tool: 'googlecpp' + # Where the output from the benchmark tool is stored + output-file-path: benchmark_result.json + # Where the previous data file is stored + external-data-json-path: ./cache/benchmark-data.json diff --git a/.gitmodules b/.gitmodules index c2f7ee82..f4532dd2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "external/HighFive"] path = external/HighFive url = https://github.com/BlueBrain/HighFive.git +[submodule "external/benchmark"] + path = external/benchmark + url = https://github.com/google/benchmark diff --git a/CMakeLists.txt b/CMakeLists.txt index 56a11219..f217ee46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,6 +146,15 @@ if(NOT TARGET gtest::gtest) add_subdirectory(external/googletest) endif() +if(NOT TARGET benchmark::benchmark) + # Stand-alone build + find_package(benchmark::benchmark QUIET) +endif() +# use local fallback +if(NOT TARGET benchmark::benchmark) + add_subdirectory(external/benchmark) +endif() + if(NOT TARGET MPI) find_package(MPI) endif() @@ -209,3 +218,7 @@ target_link_libraries(artss_data_assimilation_serial PRIVATE spdlog::spdlog) target_link_libraries(artss_data_assimilation_serial PRIVATE fmt::fmt) target_link_libraries(artss_data_assimilation_serial PRIVATE MPI::MPI_CXX) target_link_libraries(artss_data_assimilation_serial PRIVATE HighFive) + + +set(BENCHMARK_ENABLE_TESTING OFF) +add_subdirectory(benchmarks) diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt new file mode 100644 index 00000000..759b9345 --- /dev/null +++ b/benchmarks/CMakeLists.txt @@ -0,0 +1,13 @@ +add_executable(artss_bench ${ARTSS_SOURCE_FILES}) + +add_subdirectory(field) + +target_include_directories(artss_bench PRIVATE ${CMAKE_SOURCE_DIR}) +target_link_libraries(artss_bench benchmark::benchmark) +target_link_libraries(artss_bench gtest) +target_link_libraries(artss_bench spdlog::spdlog) +target_link_libraries(artss_bench fmt::fmt) +target_link_libraries(artss_bench MPI::MPI_CXX) +target_link_libraries(artss_bench HighFive) + +add_test(NAME artss_bench COMMAND artss_bench) diff --git a/benchmarks/Environment.h b/benchmarks/Environment.h new file mode 100644 index 00000000..05b2410d --- /dev/null +++ b/benchmarks/Environment.h @@ -0,0 +1,25 @@ +/// \file Environment.cpp +/// \brief +/// \date Dec 10, 2021 +/// \author My Linh Wuerzburger +/// \copyright <2015-2021> Forschungszentrum Juelich All rights reserved. + + +#ifndef BENCH_ENVIRONMENT_H_ +#define BENCH_ENVIRONMENT_H_ + +#include +#include "src/utility/Utility.h" + +static int setup_done = 0; + +// Override this to define how to set up the environment. +static void DoSetup(const benchmark::State& state) { + if (setup_done) + return; + + Utility::create_logger("info", "gtest.log"); + setup_done = 1; +} + +#endif /* BENCH_FIELD_FIELD_H_ */ diff --git a/benchmarks/field/CMakeLists.txt b/benchmarks/field/CMakeLists.txt new file mode 100644 index 00000000..a6357d3e --- /dev/null +++ b/benchmarks/field/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(artss_bench + PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/Field.cpp +) diff --git a/benchmarks/field/Field.cpp b/benchmarks/field/Field.cpp new file mode 100644 index 00000000..1fe14546 --- /dev/null +++ b/benchmarks/field/Field.cpp @@ -0,0 +1,56 @@ +#include + +#include "../Environment.h" +#include "src/field/Field.h" + +#include + + +static void BM_AddScalar(benchmark::State &state) { + // Utility::create_logger("info", "bench.log"); + size_t size = state.range(0); + + for (auto _ : state) { + Field a(UNKNOWN_FIELD, 0.0, 0, size); + a += M_E; + } +} + +static void BM_AddFields(benchmark::State &state) { + // Utility::create_logger("info", "bench.log"); + size_t size = state.range(0); + + for (auto _ : state) { + Field a(UNKNOWN_FIELD, 0.0, 0, size); + Field b(UNKNOWN_FIELD, 0.0, 0, size); + a += b; + } +} + +static void BM_MulScalar(benchmark::State &state) { + // Utility::create_logger("info", "bench.log"); + size_t size = state.range(0); + + for (auto _ : state) { + Field a(UNKNOWN_FIELD, 0.0, 0, size); + a *= M_E; + } +} + +static void BM_MulFields(benchmark::State &state) { + // Utility::create_logger("info", "bench.log"); + size_t size = state.range(0); + + for (auto _ : state) { + Field a(UNKNOWN_FIELD, 0.0, 0, size); + Field b(UNKNOWN_FIELD, 0.0, 0, size); + a *= b; + } +} + +BENCHMARK(BM_AddScalar)->Range(8, 8<<20)->Setup(DoSetup); +BENCHMARK(BM_AddFields)->Range(8, 8<<20)->Setup(DoSetup); +BENCHMARK(BM_MulScalar)->Range(8, 8<<20)->Setup(DoSetup); +BENCHMARK(BM_MulFields)->Range(8, 8<<20)->Setup(DoSetup); + +BENCHMARK_MAIN(); diff --git a/external/benchmark b/external/benchmark new file mode 160000 index 00000000..8d86026c --- /dev/null +++ b/external/benchmark @@ -0,0 +1 @@ +Subproject commit 8d86026c67e41b1f74e67c1b20cc8f73871bc76e diff --git a/external/googletest b/external/googletest index e2239ee6..2fe3bd99 160000 --- a/external/googletest +++ b/external/googletest @@ -1 +1 @@ -Subproject commit e2239ee6043f73722e7aa812a459f54a28552929 +Subproject commit 2fe3bd994b3189899d93f1d5a881e725e046fdc2 From 39e9e2ef2ab83faa649997785d497e9d20e18cf8 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 14:28:04 +0200 Subject: [PATCH 10/23] added github-token --- .github/workflows/benchmark.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index a798ce0e..ea1a24ea 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -32,3 +32,4 @@ jobs: output-file-path: benchmark_result.json # Where the previous data file is stored external-data-json-path: ./cache/benchmark-data.json + github-token: ${{ secrets.GITHUB_TOKEN }} From 8176b113f8193d7ea0f4a52ea1d9e02f37b6558a Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 14:53:31 +0200 Subject: [PATCH 11/23] added gpu benchmark version --- .github/workflows/benchmark.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index ea1a24ea..c0b5e5b2 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -33,3 +33,31 @@ jobs: # Where the previous data file is stored external-data-json-path: ./cache/benchmark-data.json github-token: ${{ secrets.GITHUB_TOKEN }} + + name: Benchmark-GPU + runs-on: gpu + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + - name: compile + run: | + git submodule update --init + mkdir build + ./compile.sh --docker-build + docker run --gpus all -i --rm -v $(pwd):/host_pwd -w /host_pwd artss_docker sh -c "./compile.sh --jobs 32 --gpu_benchmark && cd build && make artss_bench && ./benchmarks/bin/artss_bench --benchmark_format=json | tee ../benchmark_result_gb.json" + - name: Download previous benchmark data + uses: actions/cache@v1 + with: + path: ./cache + key: ${{ runner.os }}-benchmark + + - name: Store benchmark result + uses: benchmark-action/github-action-benchmark@v1 + with: + # What benchmark tool the output.txt came from + tool: 'googlecpp' + # Where the output from the benchmark tool is stored + output-file-path: benchmark_result_gb.json + # Where the previous data file is stored + external-data-json-path: ./cache/benchmark-data.json + github-token: ${{ secrets.GITHUB_TOKEN }} From 17dcd68c2562a2fe641cf96fe92798184870c435 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 14:56:13 +0200 Subject: [PATCH 12/23] fix syntaxx error workflow missing - --- .github/workflows/benchmark.yml | 54 ++++++++++++++++----------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index c0b5e5b2..25c2a988 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -6,35 +6,35 @@ on: jobs: benchmark: - name: Benchmark - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - - name: compile - run: | - git submodule update --init - mkdir build - ./compile.sh --docker-build - docker run -i --rm -v $(pwd):/host_pwd -w /host_pwd artss_docker sh -c "cd build && cmake .. && make artss_bench && ./benchmarks/bin/artss_bench --benchmark_format=json | tee ../benchmark_result.json" - - name: Download previous benchmark data - uses: actions/cache@v1 - with: - path: ./cache - key: ${{ runner.os }}-benchmark + - name: Benchmark + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + - name: compile + run: | + git submodule update --init + mkdir build + ./compile.sh --docker-build + docker run -i --rm -v $(pwd):/host_pwd -w /host_pwd artss_docker sh -c "cd build && cmake .. && make artss_bench && ./benchmarks/bin/artss_bench --benchmark_format=json | tee ../benchmark_result.json" + - name: Download previous benchmark data + uses: actions/cache@v1 + with: + path: ./cache + key: ${{ runner.os }}-benchmark - - name: Store benchmark result - uses: benchmark-action/github-action-benchmark@v1 - with: - # What benchmark tool the output.txt came from - tool: 'googlecpp' - # Where the output from the benchmark tool is stored - output-file-path: benchmark_result.json - # Where the previous data file is stored - external-data-json-path: ./cache/benchmark-data.json - github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Store benchmark result + uses: benchmark-action/github-action-benchmark@v1 + with: + # What benchmark tool the output.txt came from + tool: 'googlecpp' + # Where the output from the benchmark tool is stored + output-file-path: benchmark_result.json + # Where the previous data file is stored + external-data-json-path: ./cache/benchmark-data.json + github-token: ${{ secrets.GITHUB_TOKEN }} - name: Benchmark-GPU + - name: Benchmark-GPU runs-on: gpu steps: - uses: actions/checkout@v2 From b907a42230cba47a0954b301dcdc2564b84ce0f5 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 14:57:52 +0200 Subject: [PATCH 13/23] fix syntax error --- .github/workflows/benchmark.yml | 55 +++++++++++++++++---------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 25c2a988..cfc32962 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -6,35 +6,36 @@ on: jobs: benchmark: - - name: Benchmark - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - - name: compile - run: | - git submodule update --init - mkdir build - ./compile.sh --docker-build - docker run -i --rm -v $(pwd):/host_pwd -w /host_pwd artss_docker sh -c "cd build && cmake .. && make artss_bench && ./benchmarks/bin/artss_bench --benchmark_format=json | tee ../benchmark_result.json" - - name: Download previous benchmark data - uses: actions/cache@v1 - with: - path: ./cache - key: ${{ runner.os }}-benchmark + name: Benchmark + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + - name: compile + run: | + git submodule update --init + mkdir build + ./compile.sh --docker-build + docker run -i --rm -v $(pwd):/host_pwd -w /host_pwd artss_docker sh -c "cd build && cmake .. && make artss_bench && ./benchmarks/bin/artss_bench --benchmark_format=json | tee ../benchmark_result.json" + - name: Download previous benchmark data + uses: actions/cache@v1 + with: + path: ./cache + key: ${{ runner.os }}-benchmark - - name: Store benchmark result - uses: benchmark-action/github-action-benchmark@v1 - with: - # What benchmark tool the output.txt came from - tool: 'googlecpp' - # Where the output from the benchmark tool is stored - output-file-path: benchmark_result.json - # Where the previous data file is stored - external-data-json-path: ./cache/benchmark-data.json - github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Store benchmark result + uses: benchmark-action/github-action-benchmark@v1 + with: + # What benchmark tool the output.txt came from + tool: 'googlecpp' + # Where the output from the benchmark tool is stored + output-file-path: benchmark_result.json + # Where the previous data file is stored + external-data-json-path: ./cache/benchmark-data.json + github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Benchmark-GPU + benchmark-gpu: + name: Benchmark-GPU runs-on: gpu steps: - uses: actions/checkout@v2 From 66ff4a4966e90c28dc5c6bc6d159ed7ffc2033c4 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 15:02:56 +0200 Subject: [PATCH 14/23] fix std::exception in OpenACC code -> commented --- src/domain/Coordinate.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/domain/Coordinate.h b/src/domain/Coordinate.h index c655e538..95c54342 100644 --- a/src/domain/Coordinate.h +++ b/src/domain/Coordinate.h @@ -47,7 +47,7 @@ class Coordinate { if (i == CoordinateAxis::Z) { return z; } - throw std::runtime_error("unknown axis"); + // throw std::runtime_error("unknown axis"); } const inline numeral &operator[](size_t i) const { @@ -60,7 +60,7 @@ class Coordinate { if (i == CoordinateAxis::Z) { return z; } - throw std::runtime_error("unknown axis"); + // throw std::runtime_error("unknown axis"); } Coordinate &operator+=(const Coordinate &rhs) { From 760e075f78f79f402487a7f7d225d067f45c27c5 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 15:06:41 +0200 Subject: [PATCH 15/23] fix running docker as user --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index cfc32962..25c1ba17 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -45,7 +45,7 @@ jobs: git submodule update --init mkdir build ./compile.sh --docker-build - docker run --gpus all -i --rm -v $(pwd):/host_pwd -w /host_pwd artss_docker sh -c "./compile.sh --jobs 32 --gpu_benchmark && cd build && make artss_bench && ./benchmarks/bin/artss_bench --benchmark_format=json | tee ../benchmark_result_gb.json" + docker run --gpus all -i --rm -v $(pwd):/host_pwd -w /host_pwd --user 1000:1000 artss_docker sh -c "./compile.sh --jobs 32 --gpu_benchmark && cd build && make artss_bench && ./benchmarks/bin/artss_bench --benchmark_format=json | tee ../benchmark_result_gb.json" - name: Download previous benchmark data uses: actions/cache@v1 with: From ce2e71231b936f3bb8b8c4856a0639942670445c Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 15:16:38 +0200 Subject: [PATCH 16/23] added gpu cmake test --- .github/workflows/ccpp.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 8d3018b3..9dd901d0 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -99,6 +99,16 @@ jobs: ./compile.sh --docker-build docker run -i --rm -v $(pwd):/host_pwd -w /host_pwd artss_docker sh -c "./compile.sh --jobs 4 -s -m -d && cd build && ctest --output-on-failure -E 'gpu|gtest' --checkout" + cmake-tests-gpu: + + runs-on: gpu + steps: + - uses: actions/checkout@v2 + - name: compile + run: | + git submodule update --init + ./compile.sh --docker-build + docker run -i --rm -v $(pwd):/host_pwd -w /host_pwd --user 1000:1000 artss_docker sh -c "./compile.sh --jobs 32 -g -m -d && cd build && ctest --output-on-failure --checkout" unit-tests_serial: runs-on: ubuntu-latest From dfc386120181ef5d4e8fe3d9a6668ad471ad5593 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 15:41:51 +0200 Subject: [PATCH 17/23] added dummy loop to Field mul --- src/field/Field.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/field/Field.h b/src/field/Field.h index 9c925dde..def06021 100644 --- a/src/field/Field.h +++ b/src/field/Field.h @@ -128,7 +128,10 @@ class Field { auto rhs_data = rhs.data; #pragma acc parallel loop independent present(this->data[:m_size], rhs_data[:m_size]) async for (size_t i = 0; i < m_size; ++i) { - this->data[i] *= rhs_data[i]; + this->data[i] *= rhs_data[i] * rhs_data[i]; + } + for (size_t i = 0; i < m_size; ++i) { + this->data[i] /= rhs_data[i]; } #pragma acc wait return *this; From 46695d30308b124f933086f7823fa6874ca386d5 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 16:09:40 +0200 Subject: [PATCH 18/23] added auto push --- .github/workflows/benchmark.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 25c1ba17..8a8f5224 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -33,6 +33,7 @@ jobs: # Where the previous data file is stored external-data-json-path: ./cache/benchmark-data.json github-token: ${{ secrets.GITHUB_TOKEN }} + auto-push: true benchmark-gpu: name: Benchmark-GPU From 73f0a71a38bce121573e6e150f5a12062441655c Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 16:19:50 +0200 Subject: [PATCH 19/23] added comment always --- .github/workflows/benchmark.yml | 35 +++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 8a8f5224..a081a123 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -5,7 +5,7 @@ on: - test_benchmarking jobs: - benchmark: + master-benchmark: name: Benchmark runs-on: ubuntu-latest steps: @@ -31,10 +31,40 @@ jobs: # Where the output from the benchmark tool is stored output-file-path: benchmark_result.json # Where the previous data file is stored - external-data-json-path: ./cache/benchmark-data.json + output-file-path: ./cache/benchmark-data.json github-token: ${{ secrets.GITHUB_TOKEN }} auto-push: true + benchmark: + name: Benchmark + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + - name: compile + run: | + git submodule update --init + mkdir build + ./compile.sh --docker-build + docker run -i --rm -v $(pwd):/host_pwd -w /host_pwd artss_docker sh -c "cd build && cmake .. && make artss_bench && ./benchmarks/bin/artss_bench --benchmark_format=json | tee ../benchmark_result.json" + - name: Download previous benchmark data + uses: actions/cache@v1 + with: + path: ./cache + key: ${{ runner.os }}-benchmark + + - name: Store benchmark result + uses: benchmark-action/github-action-benchmark@v1 + with: + # What benchmark tool the output.txt came from + tool: 'googlecpp' + # Where the output from the benchmark tool is stored + output-file-path: benchmark_result.json + # Where the previous data file is stored + output-file-path: ./cache/benchmark-data.json + github-token: ${{ secrets.GITHUB_TOKEN }} + comment-always: true + benchmark-gpu: name: Benchmark-GPU runs-on: gpu @@ -63,3 +93,4 @@ jobs: # Where the previous data file is stored external-data-json-path: ./cache/benchmark-data.json github-token: ${{ secrets.GITHUB_TOKEN }} + comment-always: true From 6a1500c0325af8782d5935728c3a17d1768c1bb1 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 16:21:22 +0200 Subject: [PATCH 20/23] fixed double output-file --- .github/workflows/benchmark.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index a081a123..04b25822 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -31,7 +31,6 @@ jobs: # Where the output from the benchmark tool is stored output-file-path: benchmark_result.json # Where the previous data file is stored - output-file-path: ./cache/benchmark-data.json github-token: ${{ secrets.GITHUB_TOKEN }} auto-push: true From 283bfd4d70b328c840e69271f93de156d5c563eb Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 16:21:59 +0200 Subject: [PATCH 21/23] fixed double output-file --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 04b25822..34f36a92 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -60,7 +60,7 @@ jobs: # Where the output from the benchmark tool is stored output-file-path: benchmark_result.json # Where the previous data file is stored - output-file-path: ./cache/benchmark-data.json + external-data-json-path: ./cache/benchmark-data.json github-token: ${{ secrets.GITHUB_TOKEN }} comment-always: true From 05b0b6fcefa53027e472af8811f4ad5456a7ddf1 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 16:37:47 +0200 Subject: [PATCH 22/23] removed dummy loop to Field mul --- .github/workflows/benchmark.yml | 2 +- src/field/Field.h | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 34f36a92..d1471385 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -6,7 +6,7 @@ on: jobs: master-benchmark: - name: Benchmark + name: Benchmark Master runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/src/field/Field.h b/src/field/Field.h index def06021..9c925dde 100644 --- a/src/field/Field.h +++ b/src/field/Field.h @@ -128,10 +128,7 @@ class Field { auto rhs_data = rhs.data; #pragma acc parallel loop independent present(this->data[:m_size], rhs_data[:m_size]) async for (size_t i = 0; i < m_size; ++i) { - this->data[i] *= rhs_data[i] * rhs_data[i]; - } - for (size_t i = 0; i < m_size; ++i) { - this->data[i] /= rhs_data[i]; + this->data[i] *= rhs_data[i]; } #pragma acc wait return *this; From abc78455c44076785f50863f00ddd0970c60c4a4 Mon Sep 17 00:00:00 2001 From: Christian von Mach Date: Sun, 8 May 2022 17:02:18 +0200 Subject: [PATCH 23/23] multiple threads --- benchmarks/field/Field.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/benchmarks/field/Field.cpp b/benchmarks/field/Field.cpp index 1fe14546..94d14404 100644 --- a/benchmarks/field/Field.cpp +++ b/benchmarks/field/Field.cpp @@ -48,9 +48,9 @@ static void BM_MulFields(benchmark::State &state) { } } -BENCHMARK(BM_AddScalar)->Range(8, 8<<20)->Setup(DoSetup); -BENCHMARK(BM_AddFields)->Range(8, 8<<20)->Setup(DoSetup); -BENCHMARK(BM_MulScalar)->Range(8, 8<<20)->Setup(DoSetup); -BENCHMARK(BM_MulFields)->Range(8, 8<<20)->Setup(DoSetup); +BENCHMARK(BM_AddScalar)->ThreadRange(1, 8)->Range(8, 8<<20)->Setup(DoSetup); +BENCHMARK(BM_AddFields)->ThreadRange(1, 8)->Range(8, 8<<20)->Setup(DoSetup); +BENCHMARK(BM_MulScalar)->ThreadRange(1, 8)->Range(8, 8<<20)->Setup(DoSetup); +BENCHMARK(BM_MulFields)->ThreadRange(1, 8)->Range(8, 8<<20)->Setup(DoSetup); BENCHMARK_MAIN();