vitesh13 / Simulation_runner

Some scripts to control the simulations using python for coupled models
1 stars 0 forks source link

Accessing HDF5 while simulation runs #3

Closed vitesh13 closed 3 years ago

vitesh13 commented 3 years ago

This can be a sample code to access HDF5 while the simulation is running. To avoid the writting of the fly issues, better to pause the simulation when HDF5 is being accessed. The frequency at which HDF5 will be accessed will be equal to output frequency of the simulation.

cmd = "DAMASK_grid -l tensionX.yaml -g 20grains16x16x16.vtr"
with open('check.txt','wb') as f:
    P = subprocess.Popen(cmd,stdout = subprocess.PIPE, stderr = subprocess.PIPE,shell=True)
    r = re.compile(' increment 3 converged')
    record = []
    while P.poll() is None:
      for count,line in enumerate(iter(P.stdout.readline, b'')):
             record.append(line.decode('utf-8'))
             if count > 1 and (count%300) == 0:
               d = damask.Result('20grains16x16x16_tensionX.hdf5')
               print(d.get_dataset_location('F'))
vitesh13 commented 3 years ago

This can be a way to pause the simulation - using SIGSTOP and SIGCONT

cmd = "DAMASK_grid -l tensionX.yaml -g 20grains16x16x16.vtr"
with open('check.txt','wb') as f:
    P = subprocess.Popen(cmd,stdout = subprocess.PIPE, stderr = subprocess.PIPE,shell=True)
    r = re.compile(' increment 3 converged')
    record = []
    while P.poll() is None:
      for count,line in enumerate(iter(P.stdout.readline, b'')):
             record.append(line.decode('utf-8'))
             if count > 1 and (count%300) == 0:
               os.kill(P.pid+1, signal.SIGSTOP)
               d = damask.Result('20grains16x16x16_tensionX.hdf5')
               print(d.get_dataset_location('F'))
               os.kill(P.pid+1, signal.SIGCONT)