igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] parallel processing


From: Tamás Nepusz
Subject: Re: [igraph] parallel processing
Date: Tue, 9 Oct 2012 11:27:44 +0200

Hi, 

Well, I'm not too familiar with either of these packages so I don't know 
anything about its internals, but here are a few things to consider:

1. You cannot modify the same variable in multiple parallel execution branches. 
For instance, even the following simple function does not work in parallel:

x <- 0
foreach (i=1:10) %dopar% { x <- x+1 }

What happens is that _inside_ each branch, x is increased by 1 and then stored 
back to x, but each parallel branch has its own copy of x (I guess), so the 
output will print "1" ten times. Then, when the execution goes back to the top 
level, you will still have x = 0 because %dopar% was working on _copies_ of x 
in _each_ branch and none of the copies referred to the "original" x at the top 
level. At least that's what I think happened. 

Also, I don't quite understand why you would like to build a graph in such a 
convoluted way. You can just create the edge list in advance and then add all 
the edges in a single batch:

g <- graph(c(t(expand.grid(1:10, 11:20)))

-- 
T.


On Monday, 8 October 2012 at 21:10, Bita Shams wrote:

> I want to add edges to an empty graph . I could do it sequentially but<b> no 
> edge is added</b> to the graph when I tried to add edges parallel!!!! ( I 
> tested both "doMC" and "doParallel" Package)
> I wrote my parallel and sequential commands and I'll be really thankful if 
> anybody helps me.
> 
> 
> parallel code 
> parConvert<- function(){
> g<-graph.empty(100);
> 
> foreach(i= 1:10)%dopar%{<nabble_img src="2.png" border="0"/>
> for( j in (1:10)){ 
> 
> g<-g+edges(i,(j+10));
> 
> } 
> 
> }
> 
> return(g); 
> }
> cl<- makeCluster(4);
> registerDoParallel();
> clusterExport(cl,"edges")
> g<- parConvert();
> 
> # sequential code: 
> convert<- function(){
> g<-graph.empty(100);
> 
> foreach(i= 1:10)%do%{
> for( j in (1:10)){ g<-g+edges(i,(j+10));} }
> 
> return(g); 
> }
> p<- convert();
> _______________________________________________
> igraph-help mailing list
> address@hidden (mailto:address@hidden)
> https://lists.nongnu.org/mailman/listinfo/igraph-help






reply via email to

[Prev in Thread] Current Thread [Next in Thread]