yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #15365
Re: [Question #647852]: Using openmp in a python script.
Question #647852 on Yade changed:
https://answers.launchpad.net/yade/+question/647852
Status: Open => Answered
Gary Pekmezi proposed the following answer:
Deepak,
I think you will need to load a multiprocessing library first, then you
can loop through Yade objects using a multiprocessing pool [1] instead
of the single-threaded sequential for loop you are currently using.
For example, instead of:
for b in O.bodies:
pvel.append(b.state.vel); prot.append(b.state.angVel)
you would do something like (please note it's just a sample, I haven't
tested it):
import multiprocessing as mp
def appVel(i):
pvel[i] = (O.bodies)[i].state.vel
prot[i] = (O.bodies)[i].state.angVel
if __name__=="__main__":
numBods = len(O.bodies)
pvel = mp.Array('d',range(numBods))
prot = mp.Array('d',range(numBods))
p=mp.Pool(numThreads)
p.map(appVel,range(0,numBods))
[1] https://docs.python.org/2/library/multiprocessing.html
--
You received this question notification because your team yade-users is
an answer contact for Yade.