Skip to content

Commit

Permalink
Add libfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed Jul 10, 2024
1 parent c2a7fcd commit 9e82969
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 39 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(PFFDTD_ENABLE_SYCL "Build with sycl" OFF)

find_package(fmt REQUIRED)
find_package(HDF5 REQUIRED)
find_package(OpenMP REQUIRED)

Expand Down
1 change: 1 addition & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[requires]
fmt/11.0.1
hdf5/1.14.4.3

[options]
Expand Down
15 changes: 9 additions & 6 deletions src/2D/fdtd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "pffdtd/simulation_2d.hpp"
#include "pffdtd/sycl.hpp"

#include <fmt/format.h>
#include <fmt/os.h>

#include <cstdint>
#include <filesystem>
#include <stdexcept>
Expand Down Expand Up @@ -44,10 +47,10 @@ int main(int, char** argv) {
auto out_ixy_buf = sycl::buffer<int64_t, 1>{sim.out_ixy};
auto src_sig_buf = sycl::buffer<double, 1>{sim.src_sig};

std::printf("111111111");
fmt::print(stdout, "111111111");
for (auto i{0UL}; i < sim.Nt; ++i) {
std::printf("\r\r\r\r\r\r\r\r\r");
std::printf("%04d/%04d", int(i), int(sim.Nt));
fmt::print(stdout, "\r\r\r\r\r\r\r\r\r");
fmt::print(stdout, "{:04d}/{:04d}", int(i), int(sim.Nt));
std::fflush(stdout);

queue.submit([&](sycl::handler& cgh) {
Expand Down Expand Up @@ -131,9 +134,9 @@ int main(int, char** argv) {
}
}

std::puts("");
std::printf("MAX: %f\n", max);
std::printf("MIN: %f\n", min);
fmt::println("");
fmt::println("MAX: {}", max);
fmt::println("MIN: {}", min);

auto dir = filePath.parent_path();
auto outfile = dir / "out.h5";
Expand Down
22 changes: 12 additions & 10 deletions src/3D/cpu_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@

#include "cpu_engine.hpp"

#include <fmt/format.h>
#include <fmt/os.h>

#include <vector>

#include <assert.h> //for assert
#include <math.h> //NAN
#include <omp.h>
#include <stdbool.h> //for bool
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h> //for malloc

double runSim(Simulation3D* sd) {
Expand Down Expand Up @@ -84,8 +86,8 @@ double runSim(Simulation3D* sd) {
// can control outside with OMP_NUM_THREADS env variable
int num_workers = omp_get_max_threads();

printf("ENGINE: fcc_flag=%d\n", fcc_flag);
printf("%s", (fcc_flag > 0) ? "fcc=true\n" : "fcc=false\n");
fmt::println("ENGINE: fcc_flag={}", fcc_flag);
fmt::println("{}", (fcc_flag > 0) ? "fcc=true" : "fcc=false");

// for timing
double time_elapsed;
Expand Down Expand Up @@ -328,7 +330,7 @@ double runSim(Simulation3D* sd) {
num_workers
);
}
printf("\n");
fmt::println("");

// timing
double end_time = omp_get_wtime();
Expand All @@ -337,18 +339,18 @@ double runSim(Simulation3D* sd) {
/*------------------------
* RETURN
------------------------*/
printf(
"Air update: %.6fs, %.2f Mvox/s\n",
fmt::println(
"Air update: {:.6}s, {:.2} Mvox/s",
time_elapsed_air,
Npts * Nt / 1e6 / time_elapsed_air
);
printf(
"Boundary loop: %.6fs, %.2f Mvox/s\n",
fmt::println(
"Boundary loop: {:.6}s, {:.2} Mvox/s",
time_elapsed_bn,
Nb * Nt / 1e6 / time_elapsed_bn
);
printf(
"Combined (total): %.6fs, %.2f Mvox/s\n",
fmt::println(
"Combined (total): {:.6}s, {:.2} Mvox/s",
time_elapsed,
Npts * Nt / 1e6 / time_elapsed
);
Expand Down
6 changes: 4 additions & 2 deletions src/3D/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
#include "cpu_engine.hpp"
#endif

#include <fmt/format.h>
#include <fmt/os.h>

#include <chrono>
#include <cstdio>

auto main(int /*argc*/, char** /*argv*/) -> int {
auto const start = std::chrono::steady_clock::now();
Expand All @@ -43,7 +45,7 @@ auto main(int /*argc*/, char** /*argv*/) -> int {

auto const stop = std::chrono::steady_clock::now();
auto const sec = std::chrono::duration<double>(stop - start);
std::printf("--Simulation time: %f s", sec.count());
fmt::println("--Simulation time: %f s", sec.count());

return 0;
}
2 changes: 1 addition & 1 deletion src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(pffdtd)
add_library(pffdtd)
add_library(pffdtd::pffdtd ALIAS pffdtd)
target_include_directories(pffdtd PUBLIC ${PROJECT_SOURCE_DIR})
target_link_libraries(pffdtd PUBLIC HDF5::HDF5)
target_link_libraries(pffdtd PUBLIC fmt::fmt HDF5::HDF5)
target_sources(pffdtd
PRIVATE
pffdtd/hdf.hpp
Expand Down
27 changes: 15 additions & 12 deletions src/cpp/pffdtd/simulation_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "pffdtd/hdf.hpp"

#include <fmt/format.h>
#include <fmt/os.h>

namespace pffdtd {

auto loadSimulation2D(std::filesystem::path const& path) -> Simulation2D {
Expand All @@ -25,18 +28,18 @@ auto loadSimulation2D(std::filesystem::path const& path) -> Simulation2D {
}

auto summary(Simulation2D const& sim) -> void {
std::printf("Nt: %ld\n", static_cast<long>(sim.Nt));
std::printf("Nx: %ld\n", static_cast<long>(sim.Nx));
std::printf("Ny: %ld\n", static_cast<long>(sim.Ny));
std::printf("N: %ld\n", static_cast<long>(sim.Nx * sim.Ny));
std::printf("inx: %ld\n", static_cast<long>(sim.inx));
std::printf("iny: %ld\n", static_cast<long>(sim.iny));
std::printf("in_mask: %ld\n", static_cast<long>(sim.in_mask.size()));
std::printf("bn_ixy: %ld\n", static_cast<long>(sim.bn_ixy.size()));
std::printf("adj_bn: %ld\n", static_cast<long>(sim.adj_bn.size()));
std::printf("out_ixy: %ld\n", static_cast<long>(sim.out_ixy.size()));
std::printf("src_sig: %ld\n", static_cast<long>(sim.src_sig.size()));
std::printf("loss_factor: %f\n", sim.loss_factor);
fmt::println("Nt: {}", sim.Nt);
fmt::println("Nx: {}", sim.Nx);
fmt::println("Ny: {}", sim.Ny);
fmt::println("N: {}", sim.Nx * sim.Ny);
fmt::println("inx: {}", sim.inx);
fmt::println("iny: {}", sim.iny);
fmt::println("in_mask: {}", sim.in_mask.size());
fmt::println("bn_ixy: {}", sim.bn_ixy.size());
fmt::println("adj_bn: {}", sim.adj_bn.size());
fmt::println("out_ixy: {}", sim.out_ixy.size());
fmt::println("src_sig: {}", sim.src_sig.size());
fmt::println("loss_factor: {}", sim.loss_factor);
}

} // namespace pffdtd
18 changes: 10 additions & 8 deletions src/cpp/pffdtd/sycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

#include <sycl/sycl.hpp>

#include <cstdio>
#include <string>

#include <fmt/format.h>
#include <fmt/os.h>

namespace pffdtd {

inline auto toString(sycl::info::device_type type) -> std::string {
Expand All @@ -27,15 +29,15 @@ inline auto summary(sycl::device dev) -> void {
auto type = dev.get_info<sycl::info::device::device_type>();
auto maxAllocSize = dev.get_info<sycl::info::device::max_mem_alloc_size>();

std::printf("----------------------------------------\n");
std::printf("Name: %s\n", name.c_str());
std::printf("Vendor: %s\n", vendor.c_str());
std::printf("Type: %s\n", toString(type).c_str());
std::printf("Max alloc size: %zu MB\n", maxAllocSize / 1024 / 1024);
fmt::println("----------------------------------------");
fmt::println("Name: {}", name.c_str());
fmt::println("Vendor: {}", vendor.c_str());
fmt::println("Type: {}", toString(type).c_str());
fmt::println("Max alloc size: {} MB", maxAllocSize / 1024 / 1024);
for (auto groupSize : dev.get_info<sycl::info::device::sub_group_sizes>()) {
std::printf("Subgroup size: %zu\n", groupSize);
fmt::println("Subgroup size: {}", groupSize);
}
std::printf("\n");
fmt::println("");
}

} // namespace pffdtd

0 comments on commit 9e82969

Please sign in to comment.