Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisset committed Oct 3, 2020
1 parent 39f11f4 commit 8978345
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
13 changes: 6 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ using namespace indicators;
// first letter of an ecoded sequence is the prepend symbol, last is the append symbol
// there's no need for actually prepending/appending all k symbols
// we also skip sequences shorter than k
void computeMultiKMap(const std::vector<encoded_seq_t>& seqs, size_t nbDatasets,
size_t datasetId, int k, Alphabet alpha, size_t lowerBound,
size_t upperBound, multikmap_t& res) {
void computeMultiKMap(const std::vector<encoded_seq_t>& seqs, size_t datasetId, int k,
Alphabet alpha, size_t lowerBound, size_t upperBound,
multikmap_t& res) {
if (k <= 0) throw std::invalid_argument("k must be > 0 ");
const auto ALPHABET_SIZE = alphaMap.alphabetSizes[alpha];
for (size_t s = lowerBound; s < upperBound; ++s) {
Expand Down Expand Up @@ -57,8 +57,7 @@ void computeDatasetMultiKmap(const std::vector<dataset_t>& datasets, size_t data
auto& dataset = datasets[datasetId];
const size_t lower = i;
const size_t upper = std::min(i + nbSeqPerTask, dataset.size());
computeMultiKMap(dataset, nbDatasets, datasetId, K, alpha, lower, upper,
allmaps[procId]);
computeMultiKMap(dataset, datasetId, K, alpha, lower, upper, allmaps[procId]);
int ticksize = 0;
for (size_t j = lower; j < upper; ++j) ticksize += dataset[j].size();
mainbar.tick(ticksize);
Expand All @@ -67,7 +66,7 @@ void computeDatasetMultiKmap(const std::vector<dataset_t>& datasets, size_t data
tp.waitAll();
mergeMultiMaps(outmap, allmaps);
} else {
computeMultiKMap(datasets[datasetId], datasets.size(), datasetId, K, alpha, 0,
computeMultiKMap(datasets[datasetId], datasetId, K, alpha, 0,
datasets[datasetId].size(), outmap);
for (const auto& d : datasets[datasetId]) mainbar.tick(d.size());
}
Expand Down Expand Up @@ -196,7 +195,6 @@ int main(int argc, char** argv) {
mainbar.set_option(option::PostfixText{" "});
mainbar.mark_as_completed();

// multikmap_t result = mergeMaps(allkmaps);
mergeMultiMaps(allkmaps[0], allkmaps, true, 1);
auto& result = allkmaps[0];

Expand All @@ -213,6 +211,7 @@ int main(int argc, char** argv) {
break;
}

std::cerr << "Done. Cleaning up memory..." << std::endl;
show_console_cursor(true);
return 0;
}
16 changes: 7 additions & 9 deletions utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <memory>
#include <random>
#include <robinhood.hpp>
#include <string_view>
#include <unordered_map>
#include <xhash.hpp>

Expand All @@ -20,13 +21,9 @@ namespace fs = std::filesystem;

using seqview_t = std::basic_string_view<int8_t>;

// template <typename... T> using umap_t = robin_hood::unordered_flat_map<T...>;
template <typename... T> using umap_t = tsl::robin_map<T...>;

template <typename V> using seqmap_t = robin_hood::unordered_map<seqview_t, V>;

using kmap_t = seqmap_t<std::vector<size_t>>; // SeqView -> counts

using multikmap_t = seqmap_t<robin_hood::unordered_map<
size_t, std::vector<size_t>>>; // SeqView -> counts per dataset

Expand Down Expand Up @@ -244,7 +241,7 @@ inline void mergeMultiMaps(multikmap_t& res, std::vector<multikmap_t>& maps,
for (size_t m = startIndex; m < N; ++m) {
for (auto& [kmer, map] : maps[m]) {
if (!res.count(kmer))
res[kmer] = map;
res[kmer] = decltype(map)(std::move(map));
else {
for (auto& [dataset, counts] : map) {
if (res[kmer].count(dataset)) {
Expand All @@ -261,9 +258,9 @@ inline void mergeMultiMaps(multikmap_t& res, std::vector<multikmap_t>& maps,
ticks = 0;
}
}
maps[m].clear(); // avoid wasting memory
// maps[m].clear(); // avoid wasting memory
}

// maps.clear();
if (mainbar) { // spinner update
mainbar->set_option(option::ForegroundColor{Color::green});
mainbar->set_option(option::PrefixText{"" + std::to_string(N) + " kmaps merged (" +
Expand Down Expand Up @@ -405,10 +402,11 @@ inline void dumpMultiMap_sparseMatrix(const multikmap_t& m, int k, Alphabet alph
for (const auto& c : allcounts) buff += std::to_string(c) + ",";
buff.pop_back(); // removes trailing comma
buff += "]\n";
if (++c % CHUNKSIZE == 0) {
if (++c > CHUNKSIZE) {
std::fwrite(buff.c_str(), 1, buff.size(), file);
buff.clear();
mainbar.tick(CHUNKSIZE);
mainbar.tick(c);
c = 0;
}
}
std::fwrite(buff.c_str(), 1, buff.size(), file);
Expand Down

0 comments on commit 8978345

Please sign in to comment.