示例#1
0
    def map(self, f, tasks):
        N = len(tasks)
        P = self.P
        Pless1 = P - 1
        if self.rank != 0:
            self.wait()
            return

        if f is not self.f:
            self.f = f
            requests = []
            for p in range(1, self.P):
                r = COMM_WORLD.isend(f, dest=p)
                requests.append(r)
            MPI.Request.waitall(requests)

        requests = []
        for i, task in enumerate(tasks):
            r = COMM_WORLD.isend(task, dest=(i%Pless1)+1, tag=i)
            requests.append(r)
        MPI.Request.waitall(requests)

        results = []
        for i in range(N):
            result = COMM_WORLD.recv(source=(i%Pless1)+1, tag=i)
            results.append(result)
        return results
示例#2
0
    def map(self, f, tasks):
        N = len(tasks)
        P = self.P
        Pless1 = P - 1
        if self.rank != 0:
            self.wait()
            return

        if f is not self.f:
            self.f = f
            requests = []
            for p in range(1, self.P):
                r = COMM_WORLD.isend(f, dest=p)
                requests.append(r)
            MPI.Request.waitall(requests)

        requests = []
        for i, task in enumerate(tasks):
            r = COMM_WORLD.isend(task, dest=(i % Pless1) + 1, tag=i)
            requests.append(r)
        MPI.Request.waitall(requests)

        results = []
        for i in range(N):
            result = COMM_WORLD.recv(source=(i % Pless1) + 1, tag=i)
            results.append(result)
        return results
示例#3
0
 def wait(self):
     if self.rank == 0:
         raise RuntimeError("Proc 0 cannot wait!")
     status = MPI.Status()
     while True:
         task = COMM_WORLD.recv(source=0, tag=MPI.ANY_TAG, status=status)
         if not task:
             break
         if isinstance(task, FunctionType):
             self.f = task
             continue
         result = self.f(task)
         COMM_WORLD.isend(result, dest=0, tag=status.tag)
示例#4
0
 def wait(self):
     if self.rank == 0:
         raise RuntimeError("Proc 0 cannot wait!")
     status = MPI.Status()
     while True:
         task = COMM_WORLD.recv(source=0, tag=MPI.ANY_TAG, status=status)
         if not task:
             break
         if isinstance(task, FunctionType):
             self.f = task
             continue
         result = self.f(task)
         COMM_WORLD.isend(result, dest=0, tag=status.tag)
示例#5
0
def exchange_guard_cells( physical_F_left, physical_F_right ):
    # MPI exchanges of guard cells
    # Send physical cell to left proc
    req1 = mpi_comm.isend( physical_F_left,
                dest=(mpi_comm.rank-1)%mpi_comm.size )
    # Send physical cell to right proc
    req2 = mpi_comm.isend( physical_F_right,
                dest=(mpi_comm.rank+1)%mpi_comm.size )
    # Receive value from right proc
    req3 = mpi_comm.irecv( source=(mpi_comm.rank+1)%mpi_comm.size )
    # Receive value from left proc
    req4 = mpi_comm.irecv( source=(mpi_comm.rank-1)%mpi_comm.size )
    # Wait for the processors to finish sending/receiving
    req1.wait()
    req2.wait()
    F_from_right = req3.wait()
    F_from_left = req4.wait()

    return F_from_left, F_from_right
示例#6
0
 def __del__(self):
     if self.rank == 0:
         for p in range(1, self.P):
             COMM_WORLD.isend(False, dest=p)
示例#7
0
 def __del__(self):
     if self.rank == 0:
         for p in range(1, self.P):
             COMM_WORLD.isend(False, dest=p)