parallel scenes

Asked by zhou qian

Hi:
Follow the question 225080. I created 2 yade files and tried to run their scenes independently. But the 2files seems to use 1 omega?

I use the following codes to control my 2 files:
import liboofem
import threading, multiprocessing
import time

def solve1(n):
 for i in range(500):
  omega1.switchToScene(i+n)
  omega1.step()
def solve2(n):
 for i in range(500):
  omega2.switchToScene(i+n)
  omega2.step()

filename1='testyade1'
filename2='testyade2'
m1 = __import__(filename1)
m2 = __import__(filename2)

omega1 = m1.O
omega2 = m2.O
omega1.dt = 0.0001
print(omega2.dt)
#omega2.dt = 0.0001

for i in range(500):
 m1.GenScene(i)
 m2.GenScene(i)

the 2 yade files are exactly the same, and the following codes are one of them(Box.Sphere can be replaced by any sphere pack):
from libyade import yade
from yade import *
from yade import pack, Vector3, Vector3

def readsphere():
 filename = 'Box.Sphere'
 sphere=[]
 a=open(filename).read().split()
 for i in range(int(len(a)/4)):
  s = ((float(a[4*i]),float(a[4*i+1]),float(a[4*i+2])),float(a[4*i+3]))
  sphere.append(s)
 return sphere

SP = readsphere()
cellsize = Vector3.Ones

def randomPeriPack(radius,initSize,seed):
 O.switchScene(); O.resetThisScene()
 O.periodic=True
 O.cell.setBox(initSize)
 O.engines=[ForceResetter(),InsertionSortCollider([Bo1_Sphere_Aabb()],verletDist=.05*radius),InteractionLoop([Ig2_Sphere_Sphere_ScGeom()],[Ip2_FrictMat_FrictMat_FrictPhys()],[Law2_ScGeom_FrictPhys_CundallStrack()]),PeriIsoCompressor(charLen=2*radius,stresses=[-100e9,-1e8],maxUnbalanced=1e-2,doneHook='O.pause();',globalUpdateInt=20,keepProportions=True),NewtonIntegrator(damping=.8)]
 O.materials.append(FrictMat(young=30e9,frictionAngle=.1,poisson=.3,density=1e3))
 sp=SP
 for s in sp: O.bodies.append(utils.sphere(s[0],s[1]))
 O.dt=utils.PWaveTimeStep()
 O.timingEnabled=True
 O.run();
 O.wait()
 cellsize = O.cell.size
 for b in O.bodies: b.state.pos = O.cell.wrap(b.state.pos)
 ret=pack.SpherePack()
 ret.fromSimulation()
 O.switchScene()
 print('pre-pocessing done')
 return ret

spack = randomPeriPack(.01,.1*Vector3.Ones,10)

def GenScene(i):
 if i != 0:
  newScene = O.addScene()
  O.switchToScene(newScene)
  print('scene',newScene,'created')
 O.switchScene(); O.resetThisScene()
 O.periodic = True
 O.cell.setBox(cellsize)
 O.materials.append(CohFrictMat(young=2e11,frictionAngle=0.3,poisson=.1,density=15.8e7,normalCohesion=1.e6,shearCohesion=0.2e6,alphaKr=0.1,isCohesive=True,momentRotationLaw=True,etaRoll=0.2,label='m2'))
 spack.toSimulation()

 O.engines = [
  ForceResetter(),
  InsertionSortCollider([Bo1_Sphere_Aabb(aabbEnlargeFactor=1.5,label='is2aabb')],allowBiggerThanPeriod=True),
  InteractionLoop(
   [Ig2_Sphere_Sphere_ScGeom6D(interactionDetectionFactor=1.5,label='ss2d3dg')],
   [Ip2_CohFrictMat_CohFrictMat_CohFrictPhys(label = 'm2')],
   [Law2_ScGeom6D_CohFrictPhys_CohesionMoment(
    useIncrementalForm=True,
    always_use_moment_law=True,
    )]),
  NewtonIntegrator(damping=.3,gravity=(0,0,0.0)),
 ]
 O.dt = 0.
 O.step()
 is2aabb.aabbEnlargeFactor = 1.
 ss2d3dg.interactionDetectionFactor = 1.

if the 2 files run independently, the output should be:
scene 1 created
scene 1 created
scene 2 created
scene 2 created
...

but the output is:
scene 1 created
scene 2 created
scene 3 created
...

why the 2 omegas are not independent? how can I parallel them? using different versions of YADE?

Yours,
Joe

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
zhou qian
Solved:
Last query:
Last reply:
Revision history for this message
Jan Stránský (honzik) said :
#1

Hi Joe

> But the 2files seems to use 1 omega?

yes, Omega is designed as a singleton and in one python session there can be only one Omega instance..
I am afraid that without modifying the source code, there is no solution..

Have a look at [1] (I have no personal experience)

Jan

[1] https://yade-dem.org/doc/FEMxDEM.html

Revision history for this message
zhou qian (zhoug15) said :
#2

Hi:
There is another way to parallel these scenes.
Just use O.sceneToString() and O.stringToScene() and load it in the process like Ning did.
I did a simple test using 1000 scenes and it takes less time when paralleled.
Thanks for your replay!
Yours,
Joe