def run(self): """Runs the simulation. Does all the simulation steps, and outputs data to the appropriate files when necessary. Also deals with starting and cleaning up the threads used in the communication between the driver and the PIMD code. """ # registers the softexit routine softexit.register_function(self.softexit) softexit.start(self.ttime) # prints inital configuration -- only if we are not restarting if self.step == 0: self.step = -1 # must use multi-threading to avoid blocking in multi-system runs with WTE if self.threading: stepthreads = [] for o in self.outputs: st = threading.Thread(target=o.write, name=o.filename) st.daemon = True st.start() stepthreads.append(st) for st in stepthreads: while st.is_alive(): # This is necessary as join() without timeout prevents main from receiving signals. st.join(2.0) else: for o in self.outputs: o.write( ) # threaded output seems to cause random hang-ups. should make things properly thread-safe self.step = 0 steptime = 0.0 simtime = time.time() cstep = 0 # tptime = 0.0 # tqtime = 0.0 # tttime = 0.0 ttot = 0.0 # main MD loop for self.step in range(self.step, self.tsteps): # stores the state before doing a step. # this is a bit time-consuming but makes sure that we can honor soft # exit requests without screwing the trajectory steptime = -time.time() if softexit.triggered: break self.chk.store() if self.threading: stepthreads = [] # steps through all the systems for s in self.syslist: # creates separate threads for the different systems st = threading.Thread(target=s.motion.step, name=s.prefix, kwargs={"step": self.step}) st.daemon = True stepthreads.append(st) for st in stepthreads: st.start() for st in stepthreads: while st.is_alive(): # This is necessary as join() without timeout prevents main from receiving signals. st.join(2.0) else: for s in self.syslist: s.motion.step(step=self.step) if softexit.triggered: # Don't continue if we are about to exit. break # does the "super motion" step if self.smotion is not None: # TODO: We need a file where we store the exchanges self.smotion.step(self.step) if softexit.triggered: # Don't write if we are about to exit. break if self.threading: stepthreads = [] for o in self.outputs: st = threading.Thread(target=o.write, name=o.filename) st.daemon = True st.start() stepthreads.append(st) for st in stepthreads: while st.is_alive(): # This is necessary as join() without timeout prevents main from receiving signals. st.join(2.0) else: for o in self.outputs: o.write() steptime += time.time() ttot += steptime cstep += 1 if (verbosity.high or (verbosity.medium and self.step % 100 == 0) or (verbosity.low and self.step % 1000 == 0)): info(" # Average timings at MD step % 7d. t/step: %10.5e" % (self.step, ttot / cstep)) cstep = 0 ttot = 0.0 # info(" # MD diagnostics: V: %10.5e Kcv: %10.5e Ecns: %10.5e" % # (self.properties["potential"], self.properties["kinetic_cv"], self.properties["conserved"] ) ) if os.path.exists("EXIT"): info(" # EXIT file detected! Bye bye!", verbosity.low) break if (self.ttime > 0) and (time.time() - simtime > self.ttime): info(" # Wall clock time expired! Bye bye!", verbosity.low) break self.rollback = False
def run(self): """Runs the simulation. Does all the simulation steps, and outputs data to the appropriate files when necessary. Also deals with starting and cleaning up the threads used in the communication between the driver and the PIMD code. """ # registers the softexit routine softexit.register_function(self.softexit) softexit.start(self.ttime) # for k, f in self.fflist.iteritems(): # f.run() # prints inital configuration -- only if we are not restarting if self.step == 0: self.step = -1 # must use multi-threading to avoid blocking in multi-system runs with WTE if self.threading: stepthreads = [] for o in self.outputs: st = threading.Thread(target=o.write, name=o.filename) st.daemon = True st.start() stepthreads.append(st) for st in stepthreads: while st.isAlive(): # This is necessary as join() without timeout prevents main from receiving signals. st.join(2.0) else: for o in self.outputs: o.write() # threaded output seems to cause random hang-ups. should make things properly thread-safe self.step = 0 steptime = 0.0 simtime = time.time() cstep = 0 #tptime = 0.0 #tqtime = 0.0 #tttime = 0.0 ttot = 0.0 # main MD loop for self.step in xrange(self.step, self.tsteps): # stores the state before doing a step. # this is a bit time-consuming but makes sure that we can honor soft # exit requests without screwing the trajectory steptime = -time.time() if softexit.triggered: break self.chk.store() if self.threading: stepthreads = [] # steps through all the systems for s in self.syslist: # creates separate threads for the different systems st = threading.Thread(target=s.motion.step, name=s.prefix, kwargs={"step": self.step}) st.daemon = True stepthreads.append(st) for st in stepthreads: st.start() for st in stepthreads: while st.isAlive(): # This is necessary as join() without timeout prevents main from receiving signals. st.join(2.0) else: for s in self.syslist: s.motion.step(step=self.step) if softexit.triggered: # Don't continue if we are about to exit. break # does the "super motion" step if self.smotion is not None: # TODO: We need a file where we store the exchanges self.smotion.step(self.step) if softexit.triggered: # Don't write if we are about to exit. break if self.threading: stepthreads = [] for o in self.outputs: st = threading.Thread(target=o.write, name=o.filename) st.daemon = True st.start() stepthreads.append(st) for st in stepthreads: while st.isAlive(): # This is necessary as join() without timeout prevents main from receiving signals. st.join(2.0) else: for o in self.outputs: o.write() steptime += time.time() ttot += steptime cstep += 1 if (verbosity.high or (verbosity.medium and self.step % 100 == 0) or (verbosity.low and self.step % 1000 == 0)): info(" # Average timings at MD step % 7d. t/step: %10.5e" % (self.step, ttot / cstep)) cstep = 0 ttot = 0.0 # info(" # MD diagnostics: V: %10.5e Kcv: %10.5e Ecns: %10.5e" % # (self.properties["potential"], self.properties["kinetic_cv"], self.properties["conserved"] ) ) if os.path.exists("EXIT"): info(" # EXIT file detected! Bye bye!", verbosity.low) break if (self.ttime > 0) and (time.time() - simtime > self.ttime): info(" # Wall clock time expired! Bye bye!", verbosity.low) break self.rollback = False
def run(self): """Runs the simulation. Does all the simulation steps, and outputs data to the appropriate files when necessary. Also deals with starting and cleaning up the threads used in the communication between the driver and the PIMD code. """ # registers the softexit routine softexit.register_function(self.softexit) softexit.start(self.ttime) for k, f in self.fflist.iteritems(): f.run() # prints inital configuration -- only if we are not restarting info("Step:", self.step) if self.step == 0: print # me c*g print "Waiting for all CP2K clients to connect before starting the simulation." # me c*g trials_count = 0 # me c*g trials_max = 2*self.syslist[0].beads.nbeads + 500 # me c*g while self.syslist[0].beads.nbeads != len(self.fflist["cp2k"].socket.clients): # me c*g trials_count += 1 # me c*g print " * Currently " + str(len(self.fflist["cp2k"].socket.clients)) + " of " + str(self.syslist[0].beads.nbeads) + " CP2K clients have connected. Sleeping one second... (trial " + str(trials_count) + " of " + str(trials_max) + ")." # me c*g if trials_count == trials_max: # me c*g softexit.trigger("Sufficiently many CP2K clients failed to connect within the maximum waiting time of " + str(trials_max) + " seconds.") # me c*g time.sleep(1) # me c*g print "All CP2K clients have connected. Continuing..." # me c*g self.step = -1 # must use multi-threading to avoid blocking in multi-system runs with WTE stepthreads = [] for o in self.outputs: o.write() # threaded output seems to cause random hang-ups. should make things properly thread-safe #st = threading.Thread(target=o.write, name=o.filename) #st.daemon = True #st.start() #stepthreads.append(st) for st in stepthreads: while st.isAlive(): # This is necessary as join() without timeout prevents main # from receiving signals. st.join(2.0) if self.mode == "paratemp": self.paratemp.parafile.write("%10d" % (self.step + 1)) for i in self.paratemp.temp_index: self.paratemp.parafile.write(" %5d" % i) self.paratemp.parafile.write("\n") self.paratemp.parafile.flush() os.fsync(self.paratemp.parafile) self.step = 0 steptime = 0.0 simtime = time.time() cstep = 0 #tptime = 0.0 #tqtime = 0.0 #tttime = 0.0 ttot = 0.0 # main MD loop for self.step in range(self.step, self.tsteps): # stores the state before doing a step. # this is a bit time-consuming but makes sure that we can honor soft # exit requests without screwing the trajectory # Checking if no CP2K client has disconnected steptime = -time.time() if softexit.triggered: break self.chk.store() stepthreads = [] # steps through all the systems #for s in self.syslist: # s.motion.step() for s in self.syslist: # creates separate threads for the different systems #st = threading.Thread(target=s.motion.step, name=s.prefix, kwargs={"step":self.step}) #st.daemon = True s.motion.step(step=self.step) #st.start() #stepthreads.append(st) for st in stepthreads: while st.isAlive(): # This is necessary as join() without timeout prevents main # from receiving signals. st.join(2.0) if softexit.triggered: # Don't continue if we are about to exit. break for o in self.outputs: o.write() # does parallel tempering if self.mode == "paratemp": # because of where this is in the loop, we must write out BEFORE doing the swaps. self.paratemp.parafile.write("%10d" % (self.step + 1)) for i in self.paratemp.temp_index: self.paratemp.parafile.write(" %5d" % i) self.paratemp.parafile.write("\n") self.paratemp.parafile.flush() os.fsync(self.paratemp.parafile) self.paratemp.swap(self.step) if softexit.triggered: # Don't write if we are about to exit. break steptime += time.time() ttot += steptime cstep += 1 if (verbosity.high or (verbosity.medium and self.step % 100 == 0) or (verbosity.low and self.step % 1000 == 0)): info(" # Average timings at MD step % 7d. t/step: %10.5e" % (self.step, ttot / cstep)) cstep = 0 ttot = 0.0 #info(" # MD diagnostics: V: %10.5e Kcv: %10.5e Ecns: %10.5e" % # (self.properties["potential"], self.properties["kinetic_cv"], self.properties["conserved"] ) ) if os.path.exists("EXIT"): info(" # EXIT file detected! Bye bye!", verbosity.low) break if (self.ttime > 0) and (time.time() - simtime > self.ttime): info(" # Wall clock time expired! Bye bye!", verbosity.low) break self.rollback = False