Skip to content
Snippets Groups Projects
Commit 8800239f authored by Eric Dalissier's avatar Eric Dalissier
Browse files

resolution of bug

parent d625a4a6
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@ class SynchronizeGhosts(Operator):
self.config = other_config
@debug
def setUp(self):
def setUp(self, ghosts):
"""
SynchroGhost operator discretization method.
Create an discrete SynchroGhost operator from given specifications.
......@@ -42,11 +42,12 @@ class SynchronizeGhosts(Operator):
# the topology for v ...
topo = self.domain.getOrCreateTopology(self.domain.dimension,
self.resolution[v])
topo.ghosts = ghosts
# ... and the corresponding discrete field
self.discreteFields[v] = v.discretize(topo)
self.discreteOperator = \
SynchronizeGhosts_d(self.discreteFields[v], topo,
transferMethod=self.method, **self.config)
self.method)
self.discreteOperator.setUp()
self._isUpToDate = True
......
......@@ -6,6 +6,7 @@ Update ghost points for some fields defined on a specific topology.
from parmepy.constants import debug, ORDER, PARMES_INTEGER, PARMES_REAL
from parmepy.mpi.main_var import main_comm, main_size, main_rank, MPI
from parmepy.operator.discrete import DiscreteOperator
import numpy as np
import time
......@@ -24,7 +25,7 @@ class SynchronizeGhosts_d(DiscreteOperator):
@param topology : the topology common to all fields.
@param transferMethod : which type of exchange is used.
"""
DiscreteOperator.__init__(self, fieldslist, method=transferMethod)
# DiscreteOperator.__init__(self, fieldslist, method=transferMethod)
self.input = fieldslist
self.output = fieldslist
self.compute_time = 0.
......@@ -39,11 +40,15 @@ class SynchronizeGhosts_d(DiscreteOperator):
Create an discrete Transport operator from given specifications.
"""
Operator.setUp(self)
ghost = self.topology.ghosts
resolution = self.topology.resolution
# Operator.setUp(self)
self.topoMPI = \
self.topology.comm.Create_cart(
self.topology.dims,
periods=self.topology.periods
)
ghosts = self.topology.ghosts
resolution = self.topology.localGridResolution
if (self.transferMethod == 'SendRecv'):
topoMpi = self.topology
# Allocation of space for reciev data
self.dataRecvX = np.zeros((
ghosts[0], resolution[1], resolution[2]),
......@@ -66,12 +71,12 @@ class SynchronizeGhosts_d(DiscreteOperator):
self.topology.Shift(2, 1)
if (self.transferMethod == 'greaterSend'):
self.tabSort = self.topology.neightbours
self.down, self.up = self.topo.Shift(XDIR, 1)
if(self.dim > 1):
self.west, self.east = self.topo.Shift(YDIR, 1)
if(self.dim > 2):
self.south, self.north = self.topo.Shift(ZDIR, 1)
self.tabSort = self.topology.neighbours
self.down, self.up = self.topoMPI.Shift(0, 1)
if(self.topology.dim > 1):
self.west, self.east = self.topoMPI.Shift(1, 1)
if(self.topology.dim > 2):
self.south, self.north = self.topoMPI.Shift(2, 1)
self.tabSort = np.array(
[[self.up, 0], [self.down, 1], [self.east, 2], [self.west, 3],
[self.north, 4], [self.south, 5]])
......@@ -103,20 +108,21 @@ class SynchronizeGhosts_d(DiscreteOperator):
# 4 - find what is to be send/recv, the size of the arrays and
# allocate buffers if required
# 5 - set send/recv order
self.discreteOperator.setUp()
#self.discreteOperator.setUp()
@debug
def apply(self, *args):
resolution = self.topology.resolution
self.resolution = self.topology.localGridResolution
resolution = self.topology.localGridResolution
ghosts = self.topology.ghosts
dim = self.topology.dim
self.compute_time = time.time()
# Do the send/recv as defined in setup.
if args is None:
args = self.listFields
args = self.fieldslist
self.fieldslist = np.asarray([self.fieldslist])
if (self.transferMethod == 'SendRecv'):
for f in listFields:
for f in fieldslist:
# DOWN
if (main_rank != self.SendRecvList[0]):
self.dataSendZ = f[j][:, :, ghosts[2]:2. * ghosts[2]]
......@@ -138,7 +144,6 @@ class SynchronizeGhosts_d(DiscreteOperator):
:, :,
resolution[2] - ghosts[2]:resolution[2]],
order=ORDER, dtype=PARMES_REAL))
print 'test main comm', dir(main_comm)
main_comm.Sendrecv(
self.dataSendZ,
dest=self.SendRecvList[1],
......@@ -217,17 +222,16 @@ class SynchronizeGhosts_d(DiscreteOperator):
f[j][resolution[0] - ghosts[0]:resolution[0], :, :]
if (self.transferMethod == 'greaterSend'):
for f in listFields:
for f in self.fieldslist:
for i in xrange(self.tabSort[:, 0].shape[0]):
if (main_rank == self.tabSort[i, 0]):
## Without communication
# UP DOWN
if (self.tabSort[i, 1] == 0):
for j in xrange(dim):
f[j][
resolution[0] - ghosts[0]: resolution[0],
:, :] = f[j][ghosts[0]:2 * ghosts[0],
:, :]
f[j][resolution[0] - ghosts[0]: resolution[0],
:, :] =\
f[j][ghosts[0]:2 * ghosts[0], :, :]
if (self.tabSort[i, 1] == 1):
for j in xrange(dim):
......@@ -266,13 +270,13 @@ class SynchronizeGhosts_d(DiscreteOperator):
# UP
if(self.tabSort[i, 1] == 0):
if (main_rank < self.tabSort[i, 0]):
self.UPsend(self.tabSort[i, 0], f)
self.UPsend(self.tabSo.mesh.coords)
else:
self.UPrecv(self.tabSort[i, 0], f)
# DOWN
if (self.tabSort[i, 1] == 1):
if (main_rank < self.tabSort[i, 0]):
self.DOWNsend(self.tabSort[i, 0], f)
self.DOWNsend(self.tab.mesh.coords)
else:
self.DOWNrecv(self.tabSort[i, 0], f)
# NORTH
......@@ -299,13 +303,13 @@ class SynchronizeGhosts_d(DiscreteOperator):
self.WESTsend(self.tabSort[i, 0], f)
else:
self.WESTrecv(self.tabSort[i, 0], f)
self.compute_time = time.time() - self.compute_time
self.total_time += self.compute_time
return self.discreteOperator.apply(*args)
# self.compute_time = time.time() - self.compute_time
# self.total_time += self.compute_time
# return self.discreteOperator.apply(*args)
def UPsend(self, proc, listFields):
ghosts = self.topology.ghosts
resolution = self.topology.resolution
resolution = self.resolution
for i in xrange(self.topology.dim):
self.dataSendZ = np.array(np.copy(listFields[i][:, :,
resolution[2] - 2 * ghosts[2]:resolution[2] - ghosts[2],
......@@ -318,7 +322,7 @@ class SynchronizeGhosts_d(DiscreteOperator):
def DOWNsend(self, proc, listFields):
ghosts = self.topology.ghosts
resolution = self.topology.resolution
resolution = self.resolution
for i in xrange(self.topology.dim):
self.dataSendZ = np.array(np.copy(listFields[i][
:, :, ghosts[2]:2 * ghosts[2]]), order=ORDER)
......@@ -328,7 +332,7 @@ class SynchronizeGhosts_d(DiscreteOperator):
def EASTsend(self, proc, listFields):
ghosts = self.topology.ghosts
resolution = self.topology.resolution
resolution = self.resolution
for i in xrange(self.topology.dim):
self.dataSendX = np.array(np.copy(listFields[i][
resolution[0] - 2 * ghosts[0]:resolution[0] - ghosts[0],
......@@ -341,7 +345,7 @@ class SynchronizeGhosts_d(DiscreteOperator):
def WESTsend(self, proc, listFields):
ghosts = self.topology.ghosts
resolution = self.topology.resolution
resolution = self.resolution
for i in xrange(self.topology.dim):
self.dataSendX = np.array(np.copy(listFields[i][
ghosts[0]:ghosts[0] * 2, :, :]), order=ORDER)
......@@ -351,7 +355,7 @@ class SynchronizeGhosts_d(DiscreteOperator):
def NORTHsend(self, proc, listFields):
ghosts = self.topology.ghosts
resolution = self.topology.resolution
resolution = self.resolution
for i in xrange(self.topology.dim):
self.dataSendY = np.array(np.copy(listFields[i][
:,
......@@ -364,7 +368,7 @@ class SynchronizeGhosts_d(DiscreteOperator):
def SOUTHsend(self, proc, listFields):
ghosts = self.topology.ghosts
resolution = self.topology.resolution
resolution = self.resolution
for i in xrange(self.topology.dim):
self.dataSendY = np.array(np.copy(listFields[i][
:, ghosts[1]:2 * ghosts[1], :]), order=ORDER)
......@@ -374,7 +378,7 @@ class SynchronizeGhosts_d(DiscreteOperator):
def UPrecv(self, proc, listFields):
ghosts = self.topology.ghosts
resolution = self.topology.resolution
resolution = self.resolution
for i in xrange(self.topology.dim):
main_comm.Recv(self.dataSendZ, source=proc, tag=22)
listFields[i][:, :, resolution[2] - ghosts[2]:resolution[2]] =\
......@@ -388,7 +392,7 @@ class SynchronizeGhosts_d(DiscreteOperator):
def DOWNrecv(self, proc, listFields):
ghosts = self.topology.ghosts
resolution = self.topology.resolution
resolution = self.resolution
for i in xrange(self.topology.dim):
main_comm.Recv(self.dataSendZ, source=proc, tag=11)
listFields[i][:, :, 0:self.topo.ghosts[2]] = self.dataSendZ
......@@ -398,20 +402,20 @@ class SynchronizeGhosts_d(DiscreteOperator):
def EASTrecv(self, proc, listFields):
ghosts = self.topology.ghosts
resolution = self.topology.resolution
resolution = self.resolution
for i in xrange(self.topology.dim):
main_comm.Recv(self.dataSendX, source=proc, tag=44)
listFields[i][:, resolution[0] - ghosts[0]:resolution[0], :] =\
listFields[i][resolution[0] - ghosts[0]:resolution[0], :, :] =\
self.dataSendX
self.dataSendX = np.array(np.copy(listFields[i][
resolution[0] - 2 * ghosts[0]:resolution[0] - ghosts[0],
resolution[0] - 2 * ghosts[0]:resolution[0] - ghosts[0],\
:, :]),
order=ORDER)
main_comm.Ssend(self.dataSendX, dest=proc, tag=44)
def WESTrecv(self, proc, listFields):
ghosts = self.topology.ghosts
resolution = self.topology.resolution
resolution = self.resolution
for i in xrange(self.topology.dim):
main_comm.Recv(self.dataSendX, source=proc, tag=33)
listFields[i][0:ghosts[0], :, :] = self.dataSendX
......@@ -421,7 +425,7 @@ class SynchronizeGhosts_d(DiscreteOperator):
def NORTHrecv(self, proc, listFields):
ghosts = self.topology.ghosts
resolution = self.topology.resolution
resolution = self.resolution
for i in xrange(self.topology.dim):
main_comm.Recv(self.dataSendY, source=proc, tag=66)
listFields[i][:, resolution[1] - ghosts[1]:resolution[1], :] =\
......@@ -434,7 +438,7 @@ class SynchronizeGhosts_d(DiscreteOperator):
def SOUTHrecv(self, proc, listFields):
ghosts = self.topology.ghosts
resolution = self.topology.resolution
resolution = self.resolution
for i in xrange(self.topology.dim):
main_comm.Recv(self.dataSendY, source=proc, tag=55)
listFields[i][:, 0:ghosts[1], :] = self.dataSendY
......@@ -447,6 +451,10 @@ class SynchronizeGhosts_d(DiscreteOperator):
s = " Exchange operator"
return s + "\n"
def printComputeTime(self):
print "Velocity total time : ", self.compute_time
if (__name__ == "__main__"):
print __doc__
print "- Provided class : SynchronizeGhosts"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment