Commit c997cecf authored by cianciosa's avatar cianciosa
Browse files

Make file writing asyncronous so kernels can be submitted while IO ioperations are being performed.

parent 991eee52
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ template<typename T, bool SAFE_MATH=false>
void trace_ray(const size_t num_times,
               const size_t sub_steps,
               const size_t num_rays) {
    const timeing::measure_diagnostic total("Total Ray Time");
    
    std::vector<std::thread> threads(std::max(std::min(static_cast<unsigned int> (jit::context<T, SAFE_MATH>::max_concurrency()),
                                                       static_cast<unsigned int> (num_rays)),
@@ -191,6 +192,8 @@ void trace_ray(const size_t num_times,
    for (std::thread &t : threads) {
        t.join();
    }

    total.print();
}

//------------------------------------------------------------------------------
@@ -203,6 +206,8 @@ template<typename T, bool SAFE_MATH=false>
void calculate_power(const size_t num_times,
                     const size_t sub_steps,
                     const size_t num_rays) {
    const timeing::measure_diagnostic total("Power Time");

    std::vector<std::thread> threads(std::max(std::min(static_cast<unsigned int> (jit::context<T, SAFE_MATH>::max_concurrency()),
                                                       static_cast<unsigned int> (num_rays)),
                                              static_cast<unsigned int> (1)));
@@ -259,6 +264,8 @@ void calculate_power(const size_t num_times,
    for (std::thread &t : threads) {
        t.join();
    }

    total.print();
}

//------------------------------------------------------------------------------
+18 −2
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@
#ifndef absorption_h
#define absorption_h

#include <thread>

#include "newton.hpp"

namespace absorption {
@@ -66,6 +68,9 @@ namespace absorption {
///  Output dataset.
        output::data_set<typename DISPERSION_FUNCTION::base> dataset;

///  Async thread to write data files.
        std::thread sync;

    public:
//------------------------------------------------------------------------------
///  @brief Constructor for root finding.
@@ -108,7 +113,7 @@ namespace absorption {
                    const size_t num_rays=0,
                    const size_t index=0) :
        kamp(kamp), w(w), kx(kx), ky(ky), kz(kz), x(x), y(y), z(z), t(t),
        file(filename), dataset(file), index(index), work(index) {
        file(filename), dataset(file), index(index), work(index), sync([]{}) {
            auto kvec = graph::vector(kx, ky, kz);
            auto kunit = kvec->unit();
            auto klen = kvec->length();
@@ -142,6 +147,13 @@ namespace absorption {
            solver::newton(work, {kamp}, inputs, {D.get_d()});
        }

//------------------------------------------------------------------------------
///  @brief Destructor.
//------------------------------------------------------------------------------
        ~root_finder() {
            sync.join();
        }

//------------------------------------------------------------------------------
///  @brief Compile the workitems.
//------------------------------------------------------------------------------
@@ -179,7 +191,11 @@ namespace absorption {

            work.run();
            work.wait();
            dataset.write(file, time_index);
            
            sync.join();
            sync = std::thread([this] (const size_t index) -> void {
                dataset.write(file, index);
            }, time_index);
        }
    };
}
+19 −4
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@
#ifndef solver_h
#define solver_h

#include <thread>

#include "dispersion.hpp"
#include "output.hpp"

@@ -88,6 +90,9 @@ namespace solver {
///  Output dataset.
        output::data_set<typename DISPERSION_FUNCTION::base> dataset;

///  Async thread to write data files.
        std::thread sync;

    public:
//------------------------------------------------------------------------------
///  @brief Construct a new solver_interface with inital conditions.
@@ -127,9 +132,16 @@ namespace solver {
                         const size_t num_rays=0,
                         const size_t index=0) :
        D(w, kx, ky, kz, x, y, z, t, eq), w(w),
        kx(kx), ky(ky), kz(kz),
        x(x), y(y), z(z), t(t), file(filename, num_rays), dataset(file),
        index(index), work(index) {}
        kx(kx), ky(ky), kz(kz), x(x), y(y), z(z), t(t),
        file(filename, num_rays), dataset(file),
        index(index), work(index), sync([]{}) {}

//------------------------------------------------------------------------------
///  @brief Destructor.
//------------------------------------------------------------------------------
        ~solver_interface() {
            sync.join();
        }
        
//------------------------------------------------------------------------------
///  @brief Method to initalize the rays.
@@ -281,7 +293,10 @@ namespace solver {
//------------------------------------------------------------------------------
        void write_step() {
            work.wait();
            sync.join();
            sync = std::thread([this] {
                dataset.write(file);
            });
        }

//------------------------------------------------------------------------------