  The parallel computation will be slower for two reasons: the time to
launch the threads/tasks and re-assemble the list of returned results, and
time lost to resource contention while running. For this task, the
launch/reassemble will be small (but you'd see perhaps tens of ms), since
there is no copying of large data structures.
   I believe you're mostly seeing resource contention for the matrix
building. The non-mc method builds a large matrix 4 times in turn, while
the mc method is building it 4 time simultaneously. This multiply will be a
memory- rather than computation- intensive operation. Allocating the 1G
matrix isn't a big deal, but sifting through it with a multiply in this
style is going to exercise the memory system.
  Was t(m)%*%m intended instead, for a 100x100 result rather than 1e4x1e4?
For a computation-intensive quick test, try det() on a smaller matrix, like
det(matrix(rnorm(1e6),1e3)) [not well-posed, but causes computation]

    --j


On Wed, Feb 12, 2014 at 8:56 PM, Xuening Zhu <puddingnnn529@gmail.com>wrote:

> I am learning about parallel computing in R , and I found this happening in
> my experiments.
>
> Briefly, in the following example, why are most values of user time in
> t smaller
> than that in mc_t ? My machine has 32GB memory, 2 cpus with 4 cores and 8
> hyper threads in total. Tools such as BLAS to enhance performance aren't
> installed as well.
>
> system.time({t = lapply(1:4,function(i) {
>     m = matrix(1:10^6,ncol=100)
>     t = system.time({
>         m%*%t(m)
>     })
>     return(t)})})
>
>
> library(multicore)
> system.time({
>     mc_t = mclapply(1:4,function(m){
>         m = matrix(1:10^6,ncol=100)
>         t = system.time({
>             m%*%t(m)
>         })
>         return(t)
>     },mc.cores=4)})
> > t[[1]]
> user  system elapsed11.136   0.548  11.703
> [[2]]
> user  system elapsed11.533   0.548  12.098
> [[3]]
> user  system elapsed11.665   0.432  12.115
> [[4]]
> user  system elapsed11.580   0.512  12.115
> > mc_t[[1]]
> user  system elapsed16.677   0.496  17.199
> [[2]]
> user  system elapsed16.741   0.428  17.198
> [[3]]
> user  system elapsed16.653   0.520  17.198
> [[4]]
> user  system elapsed11.056   0.444  11.520
>
> mc_t and t measures pure computation time according to my comprehension.
>  Such things happens to parLapply in parallel package as well. The memory
> in my machine is enough for that computation. (It just takes a few percent
> of that).
>
> Also I try to run 4 similar Rscript as below by hand using command
> 'Rscript' at the same time on the same machine and save the results. The
> elapsed time for each of them is about 12s as well. So I think it may not
> be the contention of cores.
>
> system.time({t = lapply(1,function(i) {
>     m = matrix(1:10^6,ncol=100)
>     t = system.time({
>         m%*%t(m)
>     })
>     return(t)})})
>
> So what happened during the parallel? Does mc_t really measure the pure
> computation time? Can someone explain the whole process by step in detail?
>
> Thanks.
>
>
> --
> 朱雪宁
> --------------------------------------------------------
> 北京大学 光华管理学院
> 商务统计（2013级硕士）
> 手机：15600608462
>
> Xuening Zhu
> Guanghua School of Management, Peking University
> Tel:+86 15600608462
>
>         [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-hpc mailing list
> R-sig-hpc@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-hpc
>
>

	[[alternative HTML version deleted]]

