Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions src/radmeth/radmeth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,25 @@
#include <vector>

struct file_progress {
double one_hundred_over_filesize{};
double one_thousand_over_filesize{};
std::size_t prev_offset{};
explicit file_progress(const std::string &filename) :
one_hundred_over_filesize{100.0 / std::filesystem::file_size(filename)} {}
one_thousand_over_filesize{1000.0 / std::filesystem::file_size(filename)} {}
void
operator()(std::ifstream &in) {
const std::size_t curr_offset =
in.eof() ? 100 : in.tellg() * one_hundred_over_filesize;
in.eof() ? 1000 : in.tellg() * one_thousand_over_filesize;
if (curr_offset <= prev_offset)
return;
std::cerr << "\r[progress: " << std::setw(3) << curr_offset
<< (curr_offset == 100 ? "%]\n" : "%]");
prev_offset = (curr_offset == 100) ? std::numeric_limits<std::size_t>::max()
: curr_offset;
std::ios old_state(nullptr);
old_state.copyfmt(std::cerr);
std::cerr << "\r[progress: " << std::setw(5) << std::fixed
<< std::setprecision(1) << (curr_offset / 10.0)
<< (curr_offset == 1000 ? "%]\n" : "%]");
std::cerr.copyfmt(old_state);
prev_offset = (curr_offset == 1000)
? std::numeric_limits<std::size_t>::max()
: curr_offset;
}
};

Expand Down Expand Up @@ -162,6 +167,9 @@ drop_idx(const std::vector<double> &v, const std::size_t idx_to_drop) {
return u;
}

/// ADS: this function is not currently used, as the threads do not operate in
/// "chunks"
/*
static inline void
get_chunk_bounds(const std::uint32_t n_elements, const std::uint32_t n_chunks,
std::vector<std::pair<std::uint32_t, std::uint32_t>> &chunks) {
Expand All @@ -175,6 +183,7 @@ get_chunk_bounds(const std::uint32_t n_elements, const std::uint32_t n_chunks,
block_start = block_end;
}
}
*/

static void
radmeth(const bool show_progress, const bool more_na_info,
Expand Down Expand Up @@ -224,7 +233,7 @@ that the design matrix and the proportion table are correctly formatted.
std::vector<Regression> alt_models(n_threads, alt_model);
std::vector<Regression> null_models(n_threads, null_model);

std::vector<std::pair<std::uint32_t, std::uint32_t>> chunks(n_threads);
// std::vector<std::pair<std::uint32_t, std::uint32_t>> chunks(n_threads);

// Iterate over rows in the file and do llr test on proportions from
// each. Do this in sets of rows to avoid having to spawn too many threads.
Expand All @@ -235,15 +244,21 @@ that the design matrix and the proportion table are correctly formatted.
if (n_lines == 0)
break;

get_chunk_bounds(n_lines, n_threads, chunks);
/// ADS: chunks not used
// get_chunk_bounds(n_lines, n_threads, chunks);

std::vector<std::thread> threads;
for (auto thread_id = 0u; thread_id < n_threads; ++thread_id) {
threads.emplace_back([&, thread_id] {
const auto &[chunk_beg, chunk_end] = chunks[thread_id];
/// ADS: chunks not used
// const auto &[chunk_beg, chunk_end] = chunks[thread_id];
auto &t_alt_model = alt_models[thread_id];
auto &t_null_model = null_models[thread_id];
for (auto b = chunk_beg; b != chunk_end; ++b) {
/// ADS: chunks not used
// for (auto b = chunk_beg; b != chunk_end; ++b) {
for (auto b = 0u; b < n_lines; ++b) {
if (b % n_threads != thread_id)
continue;
t_alt_model.props.parse(lines[b]);
if (t_alt_model.props_size() != n_samples)
throw std::runtime_error("found row with wrong number of columns");
Expand Down
1 change: 1 addition & 0 deletions src/radmeth/radmeth_optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ static void
neg_gradient(const gsl_vector *params, void *object, gsl_vector *output) {
auto reg = static_cast<Regression *>(object);
gradient(params, *reg, output);
gsl_vector_scale(output, -1.0);
}

static void
Expand Down