def Compute(workerFn, cf): """Run parallel workerFn using compute configuration""" if cf.compute.useMPI and 'OMPI_COMM_WORLD_LOCAL_RANK' not in os.environ: # is it is not already started as an MPI process # get hostlists from hostfile and pass it to Spawn Spawn(nproc=min(cf.compute.numProcesses, cf.study.numSubjects), hostList=ReadHostFile(cf.compute.hostFile)) elif 'OMPI_COMM_WORLD_LOCAL_RANK' in os.environ: # if already running as an MPI process, may be from outside python # behave as if started from inside cf.compute.useMPI = True cf.compute.numProcesses = GetMPIInfo()['size'] if cf.compute.useMPI: # so that exceptions raised by mpi threads are # properly handled sys.excepthook = mpi_excepthook if cf.compute.useMPI: # Simple check that we're not using more host processes than GPUs mpiLocalRank = GetMPIInfo()['local_rank'] if cf.compute.useCUDA: if mpiLocalRank >= ca.GetNumberOfCUDADevices(): #MPI.COMM_WORLD.Abort(1) raise Exception("Please don't use more host processes " + "than GPUs") ca.SetCUDADevice(mpiLocalRank) # run the worker process workerFn(cf)
def __init__(self, methodName='runTest'): super(MiscTestCase, self).__init__(methodName) self.cudaEnabled = (ca.GetNumberOfCUDADevices() > 0) # image size self.sz = np.array([128, 120]) # spacing self.sp = [1.5, 2.1] # Vec3D versions self.imSz = ca.Vec3Di(int(self.sz[0]), int(self.sz[1]), 1) self.imSp = ca.Vec3Df(float(self.sp[0]), float(self.sp[1]), 1.0) # set up grid self.grid = ca.GridInfo(self.imSz, self.imSp)
plt.draw() plt.show() # end plot # end iteration # end scale return (Idef, u, energy) # end function if __name__ == '__main__': plt.close('all') if ca.GetNumberOfCUDADevices() > 0: mType = ca.MEM_DEVICE else: print "No CUDA devices found, running on CPU" mType = ca.MEM_HOST imagedir = './Images/' # # Run lena images # I0 = common.LoadPNGImage(imagedir + 'lena_deformed.png', mType) I1 = common.LoadPNGImage(imagedir + 'lena_orig.png', mType) (Idef, u, energy) = \