Hello,
I have an object composed of other objects inside, (Graph, Nodes). I want to run an operation on the nodes that modifies the node, adjacent nodes, and the graph. What is the best workflow to do it in parallel. I tried pmap, and I think it moves the objects to the workers all the time. Here is a minimal example
Module
module GraphModule
export MyGraph, MyNode, addnode, addedge
mutable struct MyGraph
numnodes
nodes
edges
MyGraph() = new(0,[],[])
end
mutable struct MyNode
label
childlabel
parentlabel
end
function addnode(g::MyGraph)
n = g.numnodes += 1
node = MyNode("MyNode$n","","")
push!(g.nodes, node)
return node
end
function addedge(g::MyGraph,n1::MyNode,n2::MyNode)
n1.childlabel = n2.label
push!(g.edges,(n1.label,n2.label))
end
function setparentlabel(g::MyGraph,n::MyNode)
for (n1,n2) in g.edges
if n == n1
n2.parent = n1
end
end
end
end
Code
push!(LOAD_PATH,".")
addprocs()
using GraphModule
g = MyGraph()
n1 = addnode(g)
n2 = addnode(g)
n3 = addnode(g)
addedge(g,n1,n2)
addedge(g,n2,n3)
n1.parentlabel
# Apply setparentlabel function to every node in parallel. Note that the function modifies an adjacent node
I’ve read the documentation around 5 times and I am very confused on what should I do.
thanks!