{
computeSynchronesChunk = function(indices)
{
+ if (verbose)
+ cat(paste("--- Compute synchrones for ",length(indices)," lines\n", sep=""))
ref_series = getRefSeries(indices)
#get medoids indices for this chunk of series
for (i in seq_len(nrow(ref_series)))
m <- synchronicity::boost.mutex()
indices_workers = .spreadIndices(seq_len(nb_ref_curves), nb_series_per_chunk)
- for (inds in indices_workers)
- {
- if (verbose)
- cat(paste("--- Compute synchrones for ",length(inds)," lines\n", sep=""))
+ ignored <-
if (parll)
- ignored <- parallel::mcparallel(computeSynchronesChunk(inds))
+ {
+ parallel::mclapply(indices_workers, computeSynchronesChunk,
+ mc.cores=ncores_clust, mc.allow.recursive=FALSE)
+ }
else
- computeSynchronesChunk(inds)
- }
- if (parll)
- parallel::mccollect()
+ lapply(indices_workers, computeSynchronesChunk)
mat_syncs = matrix(nrow=K, ncol=ncol(medoids))
vec_count = rep(NA, K)
if (parll)
m <- synchronicity::boost.mutex()
- for (i in 1:(n-1))
- {
+ ignored <-
if (parll)
- ignored <- parallel::mcparallel(computeDistancesLineI(i))
+ {
+ parallel::mclapply(seq_len(n-1), computeDistancesLineI,
+ mc.cores=ncores_clust, mc.allow.recursive=FALSE)
+ }
else
- computeDistancesLineI(i)
- }
+ lapply(seq_len(n-1), computeDistancesLineI)
Xwer_dist[n,n] = 0.
- if (parll)
- parallel::mccollect()
-
mat_dists = matrix(nrow=n, ncol=n)
#TODO: avoid this loop?
for (i in 1:n)
if (nb_series_per_task < min_series_per_chunk)
stop("Too many tasks: less series in one task than min_series_per_chunk!")
- # Cluster contributions in parallel (by nb_series_per_chunk)
- indices_all = if (random) sample(nb_curves) else seq_len(nb_curves)
- indices_tasks = lapply(seq_len(ntasks), function(i) {
- upper_bound = ifelse( i<ntasks, min(nb_series_per_task*i,nb_curves), nb_curves )
- indices_all[((i-1)*nb_series_per_task+1):upper_bound]
- })
- if (verbose)
- cat(paste("...Run ",ntasks," x stage 1 in parallel\n",sep=""))
- if (parll)
- {
- cl = parallel::makeCluster(ncores_tasks)
- parallel::clusterExport(cl, varlist=c("getSeries","getContribs","K1","K2","verbose","parll",
- "nb_series_per_chunk","ncores_clust","synchrones_file","sep","nbytes","endian"),
- envir = environment())
- }
-
runTwoStepClustering = function(inds)
{
if (parll)
indices_medoids
}
+ # Cluster contributions in parallel (by nb_series_per_chunk)
+ indices_all = if (random) sample(nb_curves) else seq_len(nb_curves)
+ indices_tasks = lapply(seq_len(ntasks), function(i) {
+ upper_bound = ifelse( i<ntasks, min(nb_series_per_task*i,nb_curves), nb_curves )
+ indices_all[((i-1)*nb_series_per_task+1):upper_bound]
+ })
+ if (verbose)
+ cat(paste("...Run ",ntasks," x stage 1 in parallel\n",sep=""))
+ if (WER=="mix")
+ {synchrones_file = paste(bin_dir,"synchrones",sep="") ; unlink(synchrones_file)}
+ if (parll)
+ {
+ cl = parallel::makeCluster(ncores_tasks)
+ varlist = c("getSeries","getContribs","K1","K2","verbose","parll",
+ "nb_series_per_chunk","ncores_clust","sep","nbytes","endian")
+ if (WER=="mix")
+ varlist = c(varlist, "synchrones_file")
+ parallel::clusterExport(cl, varlist=varlist, envir = environment())
+ }
+
# 1000*K1 indices [if WER=="end"], or empty vector [if WER=="mix"] --> series on file
if (parll)
indices = unlist( parallel::parLapply(cl, indices_tasks, runTwoStepClustering) )
parallel::stopCluster(cl)
getRefSeries = getSeries
- synchrones_file = paste(bin_dir,"synchrones",sep="") ; unlink(synchrones_file)
if (WER=="mix")
{
indices = seq_len(ntasks*K2)