<email@andreas-eberle.com>
<http://www.gnu.org/licenses/>
#ifndef EBERLE_PARALLEL_LCP_MERGESORT_H_
#define EBERLE_PARALLEL_LCP_MERGESORT_H_
#include <iostream>
#include <utility>
#include "eberle-parallel-lcp-merge.h"
#include "../sequential/eberle-mergesort-lcp-losertree.h"
#include "../tools/eberle-utilities.h"
#include "../tools/jobqueue.h"
#include "../tools/stringtools.h"
#include "../tools/debug.h"
#undef DBGX
#define DBGX DBGX_OMP
namespace eberle_parallel_lcp_mergesort
{
using std::numeric_limits;
using namespace eberle_utils;
using namespace jobqueue;
using namespace stringtools;
using stringtools::string;
static const bool debug_toplevel_merge_duration = true;
static const unsigned MERGESORT_BRANCHES = 64;
void
eberle_parallel_lcp_mergesort(string *strings, size_t n)
{
const unsigned topLevelBranches = omp_get_max_threads();
std::pair<size_t, size_t> ranges[topLevelBranches];
calculateRanges(ranges, topLevelBranches, n);
LcpCacheStringPtr stringPtr[topLevelBranches];
#pragma omp parallel for
for(unsigned k = 0; k < topLevelBranches; k++)
{
const size_t length = ranges[k].second;
stringPtr[k].strings = new string[length];
stringPtr[k].lcps = new lcp_t[length];
stringPtr[k].cachedChars = new char_type[length];
stringPtr[k].size = length;
eberle_mergesort::eberle_mergesort_losertree_lcp_kway<MERGESORT_BRANCHES>(strings + ranges[k].first, stringPtr[k]);
}
ClockTimer timer;
eberle_parallel_lcp_merge::parallelLcpMerge(stringPtr, topLevelBranches, strings, n);
DBG(debug_toplevel_merge_duration, std::endl << "top level merge needed: " << timer.elapsed() << " s" << std::endl);
for(unsigned k = 0; k < topLevelBranches; k++)
{
delete[] stringPtr[k].lcps;
delete[] stringPtr[k].cachedChars;
}
}
CONTESTANT_REGISTER_PARALLEL(eberle_parallel_lcp_mergesort,
"eberle/parallel-lcp-mergesort",
"parallel LCP aware mergesort by Andreas Eberle")
}
#endif