Dear Fipy developers and users,

The official parallel running way works for me, however, I would like to
try an different way shown in the attached script. When running by $time
mpiexec -n 4 python My_Fipy_Parallel.py, it gets stuck at time step 179
without any error message pop out, four cores are full but enough memory
left. The bigger the mesh is, the sooner it will get stuck. Does any
know why and how to solve this problem? Thanks.

Regards
Ronghai
import fipy as fp
# from fipy.solvers.scipy import LinearGMRESSolver, LinearCGSSolver, LinearPCGSolver, LinearLUSolver, LinearBicgstabSolver
# from fipy.solvers.pyAMG import LinearGMRESSolver, LinearCGSSolver, LinearPCGSolver, LinearLUSolver
from fipy.solvers.trilinos import LinearGMRESSolver, LinearCGSSolver, LinearPCGSolver, LinearLUSolver, LinearBicgstabSolver
import numpy as np
from mpi4py import MPI


class Test:
    def __init__(self):

        self.nx = 300
        self.ny = self.nx
        self.dx = 1.
        self.dy = 1.
        self.nt = 100
        self.dt = 10.
        self.mesh = fp.PeriodicGrid2D(nx=self.nx, ny=self.ny, dx=self.dx, dy=self.dy)
        self.x = self.mesh.cellCenters[0]
        self.y = self.mesh.cellCenters[1]
        self.sigma = 0.1*self.nx*self.dx
        self.x0 = 0.5*self.nx*self.dx
        self.y0 = 0.5*self.ny*self.dy
        self.A = 100./(self.sigma*np.sqrt(2.*np.pi))
        self.gauss = self.A*np.exp( -( (self.x-self.x0)**2/(2.*self.sigma**2) + (self.y-self.y0)**2/(2.*self.sigma**2) ) )
        self.phi1_global =self.gauss
        self.phi2_global =self.gauss
        self.phi3_global =self.gauss
        self.phi4_global =self.gauss
        self.solver = LinearBicgstabSolver

    def equation1(self, (phi1_global, phi2_global, phi3_global, phi4_global)):
        phi1 = fp.CellVariable(mesh=self.mesh, value=phi1_global, hasOld=1)
        eq1 = fp.TransientTerm(var=phi1, coeff=1.) == fp.DiffusionTerm(var=phi1, coeff=1.)
        res = 1.e4
        while res > 1.e-1:
            eq1.cacheMatrix()
            eq1.cacheRHSvector()
            res = eq1.sweep(dt=1, solver=self.solver())
            mat = eq1.matrix
            vec = eq1.RHSvector
        phi1.updateOld()
        print 'mat shape  = ', np.shape(mat.matrix)
        print 'phi1 shape = ', np.shape(phi1.value)
        return phi1.value

    def equation2(self, (phi1_global, phi2_global, phi3_global, phi4_global)):
        phi2 = fp.CellVariable(mesh=self.mesh, value=phi2_global, hasOld=1)
        eq2  = fp.TransientTerm(var=phi2, coeff=1.) == fp.DiffusionTerm(var=phi2, coeff=1.)
        res = 1.e4
        while res > 1.e-1:
            res = eq2.sweep(dt=1, solver=self.solver())
        phi2.updateOld()
        return phi2.value

    def equation3(self, (phi1_global, phi2_global, phi3_global, phi4_global)):
        phi3 = fp.CellVariable(mesh=self.mesh, value=phi3_global, hasOld=1)
        eq3  = fp.TransientTerm(var=phi3, coeff=1.) == fp.DiffusionTerm(var=phi3, coeff=1.)
        res = 1.e4
        while res > 1.e-3:
            res = eq3.sweep(dt=1, solver=self.solver())
        phi3.updateOld()
        return phi3.value

    def equation4(self, (phi1_global, phi2_global, phi3_global, phi4_global)):
        phi4 = fp.CellVariable(mesh=self.mesh, value=phi4_global, hasOld=1)
        eq4 = fp.TransientTerm(var=phi4, coeff=1.) == fp.DiffusionTerm(var=phi4, coeff=1.)
        res = 1.e4
        while res > 1.e-3:
            res = eq4.sweep(dt=1, solver=self.solver())
        phi4.updateOld()
        return phi4.value

    def run(self):
        for time_step in range(self.nt):
            print 'time step is:', time_step
            comm = MPI.COMM_WORLD
            rank = comm.Get_rank()
            if rank == 0:
                phi1_value = self.equation1((self.phi1_global, self.phi2_global, self.phi3_global, self.phi4_global))
                self.phi1_global = phi1_value
            if rank == 1:
                phi2_value = self.equation2((self.phi1_global, self.phi2_global, self.phi3_global, self.phi4_global))
                self.phi2_global = phi2_value
            if rank == 2:
                phi3_value = self.equation3((self.phi1_global, self.phi2_global, self.phi3_global, self.phi4_global))
                self.phi3_global = phi3_value
            if rank == 3:
                phi4_value = self.equation4((self.phi1_global, self.phi2_global, self.phi3_global, self.phi4_global))
                self.phi4_global = phi4_value
            comm.bcast(self.phi1_global, root=0)
            comm.bcast(self.phi2_global, root=1)
            comm.bcast(self.phi3_global, root=2)
            comm.bcast(self.phi4_global, root=3)
            
if __name__ == '__main__':
    myclass = Test()
    myclass.run()










_______________________________________________
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

Reply via email to