+
+ K = nrow(medoids)
+ # Use bigmemory (shared==TRUE by default) + synchronicity to fill synchrones in //
+ # TODO: if size > RAM (not our case), use file-backed big.matrix
+ synchrones = bigmemory::big.matrix(nrow=K,ncol=ncol(medoids),type="double",init=0.)
+ counts = bigmemory::big.matrix(nrow=K,ncol=1,type="double",init=0)
+ # synchronicity is only for Linux & MacOS; on Windows: run sequentially
+ parll = (requireNamespace("synchronicity",quietly=TRUE)
+ && parll && Sys.info()['sysname'] != "Windows")
+ if (parll)
+ m <- synchronicity::boost.mutex()
+
+ if (parll)
+ {
+ cl = parallel::makeCluster(ncores_clust)
+ parallel::clusterExport(cl,
+ varlist=c("synchrones","counts","verbose","medoids","getRefSeries"),
+ envir=environment())
+ }
+
+ indices_workers = .spreadIndices(seq_len(nb_ref_curves), nb_series_per_chunk)
+ ignored <-
+ if (parll)
+ parallel::parLapply(indices_workers, computeSynchronesChunk)
+ else
+ lapply(indices_workers, computeSynchronesChunk)
+
+ if (parll)
+ parallel::stopCluster(cl)
+
+ #TODO: can we avoid this loop? ( synchrones = sweep(synchrones, 1, counts, '/') )
+ for (i in seq_len(K))
+ synchrones[i,] = synchrones[i,] / counts[i,1]