コード例 #1
0
    def __init__(self, gpuf, core, direction):
        common.check_type('gpuf', gpuf, Fields)
        common.check_value('direction', direction, ('+', '-', '+-'))

        if '+' in direction:
            self.gf_h = gf_h = GetFields(gpuf, ['hy', 'hz'], (-1, 0, 0), (-1, -1, -1)) 
            self.sf_e = SetFields(gpuf, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1), True) 

            target = 0 if rank == size-1 else rank+1
            self.req_send_h = comm.Send_init(gf_h.host_array, target, tag=0)
            self.tmp_recv_e = np.zeros(gf_h.host_array.shape, gpuf.dtype)
            self.req_recv_e = comm.Recv_init(self.tmp_recv_e, target, tag=1)

        if '-' in direction:
            self.gf_e = gf_e = GetFields(gpuf, ['ey', 'ez'], (0, 0, 0), (0, -1, -1)) 
            self.sf_h = SetFields(gpuf, ['hy', 'hz'], (0, 0, 0), (0, -1, -1), True)

            target = size-1 if rank == 0 else rank-1
            self.req_send_e = comm.Send_init(gf_e.host_array, target, tag=1)
            self.tmp_recv_h = np.zeros(gf_e.host_array.shape, gpuf.dtype)
            self.req_recv_h = comm.Recv_init(self.tmp_recv_h, target, tag=0)

        # global variables
        self.core = core
        self.direction = direction
コード例 #2
0
    def __init__(self, gpuf, core, direction, tmax):
        common.check_type('gpuf', gpuf, Fields)
        common.check_value('direction', direction, ('+', '-', '+-'))

        if '+' in direction:
            self.gf_h = gf_h = GetFields(gpuf, ['hy', 'hz'], (-1, 0, 0), (-1, -1, -1)) 
            self.sf_e = SetFields(gpuf, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1), True) 

            self.req_send_h = comm.Send_init(gf_h.host_array, rank+1, tag=0)
            self.tmp_recv_e_list = [np.zeros(gf_h.host_array.shape, gpuf.dtype) for i in range(2)]
            self.req_recv_e_list = [comm.Recv_init(tmp_recv_e, rank+1, tag=1) for tmp_recv_e in self.tmp_recv_e_list]
            self.switch_e = 0

        if '-' in direction:
            self.gf_e = gf_e = GetFields(gpuf, ['ey', 'ez'], (0, 0, 0), (0, -1, -1)) 
            self.sf_h = SetFields(gpuf, ['hy', 'hz'], (0, 0, 0), (0, -1, -1), True)

            self.req_send_e = comm.Send_init(gf_e.host_array, rank-1, tag=1)
            self.tmp_recv_h_list = [np.zeros(gf_e.host_array.shape, gpuf.dtype) for i in range(2)]
            self.req_recv_h_list = [comm.Recv_init(tmp_recv_h, rank-1, tag=0) for tmp_recv_h in self.tmp_recv_h_list]
            self.switch_h = 0

        # global variables
        self.gpuf = gpuf
        self.core = core
        self.direction = direction

        self.tmax = tmax
        self.tstep = 1
コード例 #3
0
    def __init__(self, gpuf, core, direction):
        common.check_type('gpuf', gpuf, Fields)
        common.check_value('direction', direction, ('+', '-', '+-'))

        if '+' in direction:
            self.gf_h = gf_h = GetFields(gpuf, ['hy', 'hz'], (-1, 0, 0),
                                         (-1, -1, -1))
            self.sf_e = SetFields(gpuf, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1),
                                  True)

            target = 0 if rank == size - 1 else rank + 1
            self.req_send_h = comm.Send_init(gf_h.host_array, target, tag=0)
            self.tmp_recv_e = np.zeros(gf_h.host_array.shape, gpuf.dtype)
            self.req_recv_e = comm.Recv_init(self.tmp_recv_e, target, tag=1)

        if '-' in direction:
            self.gf_e = gf_e = GetFields(gpuf, ['ey', 'ez'], (0, 0, 0),
                                         (0, -1, -1))
            self.sf_h = SetFields(gpuf, ['hy', 'hz'], (0, 0, 0), (0, -1, -1),
                                  True)

            target = size - 1 if rank == 0 else rank - 1
            self.req_send_e = comm.Send_init(gf_e.host_array, target, tag=1)
            self.tmp_recv_h = np.zeros(gf_e.host_array.shape, gpuf.dtype)
            self.req_recv_h = comm.Recv_init(self.tmp_recv_h, target, tag=0)

        # global variables
        self.core = core
        self.direction = direction
コード例 #4
0
    def __init__(self, node_fields, target_rank, direction):
        common.check_type('node_fields', node_fields, Fields)
        common.check_type('target_rank', target_rank, int)

        # local variables
        nodef = node_fields
        dtype = nodef.dtype

        assert rank != target_rank, 'The target_rank %d is same as the my_rank %d.' % (
            target_rank, rank)

        # create instances (getf, setf and mpi requests)
        if '+' in direction:
            mainf = nodef.mainf_list[-1]
            nx, ny, nz = mainf.ns
            getf = GetFields(mainf, ['hy', 'hz'], (nx - 1, 0, 0),
                             (nx - 1, ny - 1, nz - 1))
            setf = SetFields(mainf, ['ey', 'ez'], (nx - 1, 0, 0),
                             (nx - 1, ny - 1, nz - 1), True)

            if rank < target_rank:
                tag_send, tag_recv = 0, 1
            elif rank > target_rank:
                tag_send, tag_recv = 2, 3

        elif '-' in direction:
            mainf = nodef.mainf_list[0]
            nx, ny, nz = mainf.ns
            getf = GetFields(mainf, ['ey', 'ez'], (0, 0, 0),
                             (0, ny - 1, nz - 1))
            setf = SetFields(mainf, ['hy', 'hz'], (0, 0, 0),
                             (0, ny - 1, nz - 1), True)

            if rank > target_rank:
                tag_send, tag_recv = 1, 0
            elif rank < target_rank:  # pbc
                tag_send, tag_recv = 3, 2

        # global variables
        self.target_rank = target_rank
        self.getf = getf
        self.setf = setf
        self.tag_send = tag_send
        self.tag_recv = tag_recv
        self.tmp_recv = np.zeros(getf.host_array.shape, dtype)

        # global functions
        self.update_e = self.recv if '+' in direction else self.send
        self.update_h = self.send if '+' in direction else self.recv

        # append instance
        self.priority_type = 'mpi'
        nodef.append_instance(self)
コード例 #5
0
ファイル: pbc.py プロジェクト: xj361685640/fdtd_accelerate
    def __init__(s, fields_list, axis):
        emf_list = fields_list

        e_strfs, h_strfs, pt0, pt1 = common_gpu.get_strfs_pts(
            axis, *emf_list[0].ns)

        s.e_getf = GetFields(emf_list[0], e_strfs, pt0['-'], pt1['-'])
        s.h_setf = SetFields(emf_list[0], h_strfs, pt0['-'], pt1['-'],
                             np.ndarray, True)

        s.h_getf = GetFields(emf_list[-1], h_strfs, pt0['+'], pt1['+'])
        s.e_setf = SetFields(emf_list[-1], e_strfs, pt0['+'], pt1['+'],
                             np.ndarray, True)
コード例 #6
0
    def verify(s, pt0, pt1):
        print('pt0 = %s, pt1 = %s' % (pt0, pt1))
        slidx = s.get_slidx(pt0, pt1)

        for strf in s.strf_list:
            # non-spatial
            fset = SetFields(s.fdtd, strf, pt0, pt1)
            value = np.random.rand()
            fset.set_fields(value)

            fget = GetFields(s.fdtd, strf, pt0, pt1)
            fget.get_event().wait()
            copy = fget.get_fields(strf)

            assert np.linalg.norm(value - copy) == 0

        if pt0 != pt1:
            for strf in s.strf_list:
                # spatial
                fset = SetFields(s.fdtd, strf, pt0, pt1, np.ndarray)
                values = np.random.rand(*fset.rplist['shape']).astype(
                    s.fdtd.dtype)
                fset.set_fields(values)

                fget = GetFields(s.fdtd, strf, pt0, pt1)
                fget.get_event().wait()
                copy = fget.get_fields(strf)

                assert np.linalg.norm(values - copy) == 0
コード例 #7
0
    def __init__(s, fields_list, axis):
        emf_list = fields_list

        e_strfs, h_strfs, pt0, pt1 = common.get_strfs_pts_for_boundary(
            axis, *emf_list[0].ns)

        s.e_getfs, s.h_getfs = [], []
        s.e_setfs, s.h_setfs = [], []
        for emf in emf_list[1:]:
            s.e_getfs.append(GetFields(emf, e_strfs, pt0['-'], pt1['-']))
            s.h_setfs.append(
                SetFields(emf, h_strfs, pt0['-'], pt1['-'], np.ndarray))

        for emf in emf_list[:-1]:
            s.h_getfs.append(GetFields(emf, h_strfs, pt0['+'], pt1['+']))
            s.e_setfs.append(
                SetFields(emf, e_strfs, pt0['+'], pt1['+'], np.ndarray))
コード例 #8
0
    def test_boundary(s):
        print('\n-- test boundary (two fields) --')
        shape_dict = {
            'x': (s.ny * 2, s.nz),
            'y': (s.nx * 2, s.nz),
            'z': (s.nx * 2, s.ny)
        }

        print('E fields')
        str_fs_dict = {'x': ['ey', 'ez'], 'y': ['ex', 'ez'], 'z': ['ex', 'ey']}
        pt0_dict = {
            'x': (s.nx - 1, 0, 0),
            'y': (0, s.ny - 1, 0),
            'z': (0, 0, s.nz - 1)
        }
        pt1 = (s.nx - 1, s.ny - 1, s.nz - 1)

        for axis in str_fs_dict.keys():
            print('direction : %s' % axis)
            str_fs = str_fs_dict[axis]
            pt0 = pt0_dict[axis]
            slidx = s.get_slidx(pt0, pt1)
            fset = SetFields(s.fdtd, str_fs, pt0, pt1, np.ndarray)
            values = np.random.rand(*shape_dict[axis]).astype(s.fdtd.dtype)
            fset.set_fields(values)

            fget = GetFields(s.fdtd, str_fs, pt0, pt1)
            fget.get_event().wait()
            copy = fget.get_fields()

            assert np.linalg.norm(values - copy) == 0

        print('H fields')
        str_fs_dict = {'x': ['hy', 'hz'], 'y': ['hx', 'hz'], 'z': ['hx', 'hy']}
        pt0 = (0, 0, 0)
        pt1_dict = {
            'x': (0, s.ny - 1, s.nz - 1),
            'y': (s.nx - 1, 0, s.nz - 1),
            'z': (s.nx - 1, s.ny - 1, 0)
        }

        for axis in str_fs_dict.keys():
            print('direction : %s' % axis)
            str_fs = str_fs_dict[axis]
            pt1 = pt1_dict[axis]
            slidx = s.get_slidx(pt0, pt1)
            fset = SetFields(s.fdtd, str_fs, pt0, pt1, np.ndarray)
            values = np.random.rand(*shape_dict[axis]).astype(s.fdtd.dtype)
            fset.set_fields(values)

            fget = GetFields(s.fdtd, str_fs, pt0, pt1)
            fget.get_event().wait()
            copy = fget.get_fields()

            assert np.linalg.norm(values - copy) == 0
コード例 #9
0
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1, is_array = self.args

        slidx = common.slices_two_points(pt0, pt1)
        str_fs = common.convert_to_tuple(str_f)

        # instance
        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)
        device = gpu_devices[0]
        qtask = QueueTask()
        fields = Fields(context, device, qtask, nx, ny, nz, '', 'single')
        setf = SetFields(fields, str_f, pt0, pt1, is_array) 
        
        # generate random source
        if is_array:
            shape = common.shape_two_points(pt0, pt1, len(str_fs))
            value = np.random.rand(*shape).astype(fields.dtype)
            split_value = np.split(value, len(str_fs))
            split_value_dict = dict( zip(str_fs, split_value) )
        else:
            value = np.random.ranf()

        # host allocations
        ehs = [np.zeros(fields.ns, dtype=fields.dtype) for i in range(6)]
        eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs) )
        gpu_eh = np.zeros(fields.ns_pitch, dtype=fields.dtype)

        # verify
        for str_f in str_fs:
            if is_array:
                eh_dict[str_f][slidx] = split_value_dict[str_f]
            else:
                eh_dict[str_f][slidx] = value

        setf.set_fields(value)
        setf.mainf.enqueue_barrier()

        for str_f in str_fs:
            cl.enqueue_copy(fields.queue, gpu_eh, fields.get_buf(str_f))
            original = eh_dict[str_f]
            copy = gpu_eh[:,:,fields.slice_z]
            norm = np.linalg.norm(original - copy)
            self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
コード例 #10
0
    def __init__(self, gpuf, core, direction, tmax):
        common.check_type('gpuf', gpuf, Fields)
        common.check_value('direction', direction, ('+', '-', '+-'))

        if '+' in direction:
            self.gf_h = gf_h = GetFields(gpuf, ['hy', 'hz'], (-1, 0, 0),
                                         (-1, -1, -1))
            self.sf_e = SetFields(gpuf, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1),
                                  True)

            self.req_send_h = comm.Send_init(gf_h.host_array, rank + 1, tag=0)
            self.tmp_recv_e_list = [
                np.zeros(gf_h.host_array.shape, gpuf.dtype) for i in range(2)
            ]
            self.req_recv_e_list = [
                comm.Recv_init(tmp_recv_e, rank + 1, tag=1)
                for tmp_recv_e in self.tmp_recv_e_list
            ]
            self.switch_e = 0

        if '-' in direction:
            self.gf_e = gf_e = GetFields(gpuf, ['ey', 'ez'], (0, 0, 0),
                                         (0, -1, -1))
            self.sf_h = SetFields(gpuf, ['hy', 'hz'], (0, 0, 0), (0, -1, -1),
                                  True)

            self.req_send_e = comm.Send_init(gf_e.host_array, rank - 1, tag=1)
            self.tmp_recv_h_list = [
                np.zeros(gf_e.host_array.shape, gpuf.dtype) for i in range(2)
            ]
            self.req_recv_h_list = [
                comm.Recv_init(tmp_recv_h, rank - 1, tag=0)
                for tmp_recv_h in self.tmp_recv_h_list
            ]
            self.switch_h = 0

        # global variables
        self.gpuf = gpuf
        self.core = core
        self.direction = direction

        self.tmax = tmax
        self.tstep = 1
コード例 #11
0
    def __init__(self, fields, str_f, pt0, pt1, tfunc, spatial_value=1., is_overwrite=False):
        """
        """

        common.check_type('fields', fields, Fields)
        common.check_value('str_f', str_f, ('ex', 'ey', 'ez', 'hx', 'hy', 'hz'))
        common.check_type('pt0', pt0, (list, tuple), int)
        common.check_type('pt1', pt1, (list, tuple), int)
        common.check_type('tfunc', tfunc, types.FunctionType)
        common.check_type('spatial_value', spatial_value, \
                (np.ndarray, np.number, types.FloatType, types.IntType) )
        common.check_type('is_overwrite', is_overwrite, bool)

        # local variables
        e_or_h = str_f[0]
        dtype = fields.dtype
        is_array = True if isinstance(spatial_value, np.ndarray) else False

        for axis, n, p0, p1 in zip(['x', 'y', 'z'], fields.ns, pt0, pt1):
            common.check_value('pt0 %s' % axis, p0, range(n))
            common.check_value('pt1 %s' % axis, p1, range(n))

        if is_array:
            shape = common.shape_two_points(pt0, pt1)
            assert shape == spatial_value.shape, \
                    'shape mismatch : %s, %s' % (shape, spatial_value.shape)
            assert dtype == spatial_value.dtype, \
                    'dtype mismatch : %s, %s' % (dtype, spatial_value.dtype)
        else:
            spatial_value = dtype(spatial_value)

        # create the SetFields instance
        setf = SetFields(fields, str_f, pt0, pt1, is_array, is_overwrite)

        # global variables
        self.mainf = fields
        self.dtype = dtype
        self.tfunc = tfunc
        self.setf = setf

        self.spatial_value = spatial_value
        self.tstep = 1

        # global functions
        if e_or_h == 'e':
            self.update_e = self.update
            self.update_h = lambda : None

        elif e_or_h == 'h':
            self.update_e = lambda : None 
            self.update_h = self.update

        # append to the update list
        self.priority_type = 'incident'
        fields.append_instance(self)
コード例 #12
0
class DirectSrc:
	def __init__(s, fields, str_f, pt0, pt1, tfunc, spatial_arr=1):
        """
        """

		self.mainf = fields
		self.tfunc = tfunc
		self.spatial_arr = spatial_arr

        if isinstance(spatial_arr, np.ndarray):
            self.setf = SetFields(self.emf, str_f, pt0, pt1, True)
        else:
            self.setf = SetFields(self.emf, str_f, pt0, pt1)


	def update(s, tstep):
        """
        """

		self.setf.set_fields(self.tfunc(tstep) * self.spatial_arr)
コード例 #13
0
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1, is_array = self.args

        slidx = common.slices_two_points(pt0, pt1)
        str_fs = common.convert_to_tuple(str_f)

        # instance
        fields = Fields(0, nx, ny, nz, '', 'single')
        setf = SetFields(fields, str_f, pt0, pt1, is_array) 
        
        # generate random source
        if is_array:
            shape = common.shape_two_points(pt0, pt1, len(str_fs))
            value = np.random.rand(*shape).astype(fields.dtype)
            split_value = np.split(value, len(str_fs))
            split_value_dict = dict( zip(str_fs, split_value) )
        else:
            value = np.random.ranf()

        # host allocations
        ehs = [np.zeros(fields.ns, dtype=fields.dtype) for i in range(6)]
        eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs) )
        gpu_eh = np.zeros(fields.ns_pitch, dtype=fields.dtype)

        # verify
        for str_f in str_fs:
            if is_array:
                eh_dict[str_f][slidx] = split_value_dict[str_f]
            else:
                eh_dict[str_f][slidx] = value

        setf.set_fields(value)

        for str_f in str_fs:
            cuda.memcpy_dtoh(gpu_eh, fields.get_buf(str_f))
            original = eh_dict[str_f]
            copy = gpu_eh[:,:,fields.slice_z]
            norm = np.linalg.norm(original - copy)
            self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))

        fields.context_pop()
コード例 #14
0
	def verify(s, pt0, pt1):
		print('pt0 = %s, pt1 = %s' % (pt0, pt1))
		slidx = s.get_slidx(pt0, pt1)

		for strf in s.strf_list:
			# non-spatial
			fset = SetFields(s.fdtd, strf, pt0, pt1)
			value = np.random.rand()
			fset.set_fields(value)

			fget = GetFields(s.fdtd, strf, pt0, pt1)
			fget.get_event().wait()
			copy = fget.get_fields(strf)

			assert np.linalg.norm(value - copy) == 0

		if pt0 != pt1:
			for strf in s.strf_list:
				# spatial
				fset = SetFields(s.fdtd, strf, pt0, pt1, np.ndarray)
				values = np.random.rand(*fset.rplist['shape']).astype(s.fdtd.dtype)
				fset.set_fields(values)

				fget = GetFields(s.fdtd, strf, pt0, pt1)
				fget.get_event().wait()
				copy = fget.get_fields(strf)

				assert np.linalg.norm(values - copy) == 0
コード例 #15
0
	def test_boundary(s):
		print('\n-- test boundary (two fields) --')
		shape_dict = {'x':(s.ny*2, s.nz), 'y':(s.nx*2, s.nz), 'z':(s.nx*2, s.ny)}

		print('E fields')
		str_fs_dict = {'x':['ey','ez'], 'y':['ex','ez'], 'z':['ex','ey']}
		pt0_dict = {'x':(s.nx-1, 0, 0), 'y':(0, s.ny-1, 0), 'z':(0, 0, s.nz-1)}
		pt1 = (s.nx-1, s.ny-1, s.nz-1)

		for axis in str_fs_dict.keys():
			print('direction : %s' % axis)
			str_fs = str_fs_dict[axis]
			pt0 = pt0_dict[axis]
			slidx = s.get_slidx(pt0, pt1)
			fset = SetFields(s.fdtd, str_fs, pt0, pt1, np.ndarray)
			values = np.random.rand(*shape_dict[axis]).astype(s.fdtd.dtype)
			fset.set_fields(values)

			fget = GetFields(s.fdtd, str_fs, pt0, pt1)
			fget.get_event().wait()
			copy = fget.get_fields()

			assert np.linalg.norm(values - copy) == 0


		print('H fields')
		str_fs_dict = {'x':['hy','hz'], 'y':['hx','hz'], 'z':['hx','hy']}
		pt0 = (0, 0, 0)
		pt1_dict = {'x':(0, s.ny-1, s.nz-1), 'y':(s.nx-1, 0, s.nz-1), 'z':(s.nx-1, s.ny-1, 0)}

		for axis in str_fs_dict.keys():
			print('direction : %s' % axis)
			str_fs = str_fs_dict[axis]
			pt1 = pt1_dict[axis]
			slidx = s.get_slidx(pt0, pt1)
			fset = SetFields(s.fdtd, str_fs, pt0, pt1, np.ndarray)
			values = np.random.rand(*shape_dict[axis]).astype(s.fdtd.dtype)
			fset.set_fields(values)

			fget = GetFields(s.fdtd, str_fs, pt0, pt1)
			fget.get_event().wait()
			copy = fget.get_fields()

			assert np.linalg.norm(values - copy) == 0
コード例 #16
0
class ExchangeMpiSplit2():
    def __init__(self, gpuf, core, direction):
        common.check_type('gpuf', gpuf, Fields)
        common.check_value('direction', direction, ('+', '-', '+-'))

        if '+' in direction:
            self.gf_h = gf_h = GetFields(gpuf, ['hy', 'hz'], (-1, 0, 0), (-1, -1, -1)) 
            self.sf_e = SetFields(gpuf, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1), True) 

            target = 0 if rank == size-1 else rank+1
            self.req_send_h = comm.Send_init(gf_h.host_array, target, tag=0)
            self.tmp_recv_e = np.zeros(gf_h.host_array.shape, gpuf.dtype)
            self.req_recv_e = comm.Recv_init(self.tmp_recv_e, target, tag=1)

        if '-' in direction:
            self.gf_e = gf_e = GetFields(gpuf, ['ey', 'ez'], (0, 0, 0), (0, -1, -1)) 
            self.sf_h = SetFields(gpuf, ['hy', 'hz'], (0, 0, 0), (0, -1, -1), True)

            target = size-1 if rank == 0 else rank-1
            self.req_send_e = comm.Send_init(gf_e.host_array, target, tag=1)
            self.tmp_recv_h = np.zeros(gf_e.host_array.shape, gpuf.dtype)
            self.req_recv_h = comm.Recv_init(self.tmp_recv_h, target, tag=0)

        # global variables
        self.core = core
        self.direction = direction



    def update_e(self):
        self.core.update_e('pre')

        if '-' in self.direction:
            self.gf_e.get_event().wait()
            self.req_send_e.Start()
        
        if '+' in self.direction:
            self.req_recv_e.Start()

        self.core.update_e('post')

        if '-' in self.direction:
            self.req_send_e.Wait()

        if '+' in self.direction:
            self.req_recv_e.Wait()
            self.sf_e.set_fields(self.tmp_recv_e)



    def update_h(self):
        self.core.update_h('pre')

        if '+' in self.direction:
            self.gf_h.get_event().wait()
            self.req_send_h.Start()
        
        if '-' in self.direction:
            self.req_recv_h.Start()

        self.core.update_h('post')

        if '+' in self.direction:
            self.req_send_h.Wait()

        if '-' in self.direction:
            self.req_recv_h.Wait()
            self.sf_h.set_fields(self.tmp_recv_h)
コード例 #17
0
class ExchangeMpiSplit3():
    def __init__(self, gpuf, core, direction, tmax):
        common.check_type('gpuf', gpuf, Fields)
        common.check_value('direction', direction, ('+', '-', '+-'))

        if '+' in direction:
            self.gf_h = gf_h = GetFields(gpuf, ['hy', 'hz'], (-2, 0, 0),
                                         (-2, -1, -1))
            self.sf_e = SetFields(gpuf, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1),
                                  True)

            self.req_send_h = comm.Send_init(gf_h.host_array, rank + 1, tag=0)
            self.tmp_recv_e_list = [
                np.zeros(gf_h.host_array.shape, gpuf.dtype) for i in range(2)
            ]
            self.req_recv_e_list = [
                comm.Recv_init(tmp_recv_e, rank + 1, tag=1)
                for tmp_recv_e in self.tmp_recv_e_list
            ]
            self.switch_e = 0

        if '-' in direction:
            self.gf_e = gf_e = GetFields(gpuf, ['ey', 'ez'], (1, 0, 0),
                                         (1, -1, -1))
            self.sf_h = SetFields(gpuf, ['hy', 'hz'], (0, 0, 0), (0, -1, -1),
                                  True)

            self.req_send_e = comm.Send_init(gf_e.host_array, rank - 1, tag=1)
            self.tmp_recv_h_list = [
                np.zeros(gf_e.host_array.shape, gpuf.dtype) for i in range(2)
            ]
            self.req_recv_h_list = [
                comm.Recv_init(tmp_recv_h, rank - 1, tag=0)
                for tmp_recv_h in self.tmp_recv_h_list
            ]
            self.switch_h = 0

        # global variables
        self.core = core
        self.direction = direction

        self.tmax = tmax
        self.tstep = 1

    def update_e(self):
        if self.direction == '+':
            self.core.update_e()

        else:
            # update e
            self.core.update_e('pre')

            # mpi send e
            if self.tstep > 1: self.req_send_e.Wait()
            self.gf_e.get_event().wait()
            self.req_send_e.Start()
            if self.tstep == self.tmax: self.req_send_e.Wait()

            # update e
            self.core.update_e('mid')

            # mpi recv h
            if self.tstep > 1:
                self.req_recv_h_list[self.switch_h].Wait()
                self.sf_h.set_fields(self.tmp_recv_h_list[self.switch_h])
                self.switch_h = 1 if self.switch_h == 0 else 0
            if self.tstep < self.tmax:
                self.req_recv_h_list[self.switch_h].Start()

            # update e
            self.core.update_e('post')

    def update_h(self):
        if self.direction == '-':
            self.core.update_h()

        else:
            # update h
            self.core.update_h('pre')

            # mpi send h
            if self.tstep > 1: self.req_send_h.Wait()
            if self.tstep < self.tmax:
                self.gf_h.get_event().wait()
                self.req_send_h.Start()

            # update h
            self.core.update_h('mid')

            # mpi recv e
            if self.tstep == 1: self.req_recv_e_list[self.switch_e].Start()
            self.req_recv_e_list[self.switch_e].Wait()
            self.sf_e.set_fields(self.tmp_recv_e_list[self.switch_e])
            self.switch_e = 1 if self.switch_e == 0 else 0
            if self.tstep < self.tmax:
                self.req_recv_e_list[self.switch_e].Start()

            # update h
            self.core.update_h('post')

        self.tstep += 1
コード例 #18
0
class ExchangeMpiSplit():
    def __init__(self, gpuf, core, direction, tmax):
        common.check_type('gpuf', gpuf, Fields)
        common.check_value('direction', direction, ('+', '-', '+-'))

        if '+' in direction:
            self.gf_h = gf_h = GetFields(gpuf, ['hy', 'hz'], (-1, 0, 0), (-1, -1, -1)) 
            self.sf_e = SetFields(gpuf, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1), True) 

            self.req_send_h = comm.Send_init(gf_h.host_array, rank+1, tag=0)
            self.tmp_recv_e_list = [np.zeros(gf_h.host_array.shape, gpuf.dtype) for i in range(2)]
            self.req_recv_e_list = [comm.Recv_init(tmp_recv_e, rank+1, tag=1) for tmp_recv_e in self.tmp_recv_e_list]
            self.switch_e = 0

        if '-' in direction:
            self.gf_e = gf_e = GetFields(gpuf, ['ey', 'ez'], (0, 0, 0), (0, -1, -1)) 
            self.sf_h = SetFields(gpuf, ['hy', 'hz'], (0, 0, 0), (0, -1, -1), True)

            self.req_send_e = comm.Send_init(gf_e.host_array, rank-1, tag=1)
            self.tmp_recv_h_list = [np.zeros(gf_e.host_array.shape, gpuf.dtype) for i in range(2)]
            self.req_recv_h_list = [comm.Recv_init(tmp_recv_h, rank-1, tag=0) for tmp_recv_h in self.tmp_recv_h_list]
            self.switch_h = 0

        # global variables
        self.gpuf = gpuf
        self.core = core
        self.direction = direction

        self.tmax = tmax
        self.tstep = 1



    def update_e(self):
        # update e
        self.core.update_e('pre')

        if '-' in self.direction:
            # mpi send e
            if self.tstep > 1: self.req_send_e.Wait()
            if self.tstep < self.tmax:
                self.gf_e.get_event().wait()
                self.req_send_e.Start()

        if '+' in self.direction:
            # mpi recv e
            if self.tstep > 1:
                self.req_recv_e_list[self.switch_e].Wait()
                self.sf_e.set_fields(self.tmp_recv_e_list[self.switch_e])
                self.switch_e = 1 if self.switch_e == 0 else 0
            if self.tstep < self.tmax: self.req_recv_e_list[self.switch_e].Start()

        # update h
        self.core.update_h('post')

        # update e
        self.core.update_e('mid')



    def update_h(self):
        # update h
        self.core.update_h('pre')

        if '+' in self.direction:
            # mpi send h
            if self.tstep > 1: self.req_send_h.Wait()
            if self.tstep < self.tmax: 
                self.gf_h.get_event().wait()
                self.req_send_h.Start()

        if '-' in self.direction:
            # mpi recv h
            if self.tstep > 1: 
                self.req_recv_h_list[self.switch_h].Wait()
                self.sf_h.set_fields(self.tmp_recv_h_list[self.switch_h])
                self.switch_h = 1 if self.switch_h == 0 else 0
            if self.tstep < self.tmax: self.req_recv_h_list[self.switch_h].Start()

        # update e
        self.core.update_e('post')

        # update h
        self.core.update_h('mid')

        self.tstep += 1
コード例 #19
0
class ExchangeMpiSplit2():
    def __init__(self, gpuf, core, direction):
        common.check_type('gpuf', gpuf, Fields)
        common.check_value('direction', direction, ('+', '-', '+-'))

        if '+' in direction:
            self.gf_h = gf_h = GetFields(gpuf, ['hy', 'hz'], (-1, 0, 0),
                                         (-1, -1, -1))
            self.sf_e = SetFields(gpuf, ['ey', 'ez'], (-1, 0, 0), (-1, -1, -1),
                                  True)

            target = 0 if rank == size - 1 else rank + 1
            self.req_send_h = comm.Send_init(gf_h.host_array, target, tag=0)
            self.tmp_recv_e = np.zeros(gf_h.host_array.shape, gpuf.dtype)
            self.req_recv_e = comm.Recv_init(self.tmp_recv_e, target, tag=1)

        if '-' in direction:
            self.gf_e = gf_e = GetFields(gpuf, ['ey', 'ez'], (0, 0, 0),
                                         (0, -1, -1))
            self.sf_h = SetFields(gpuf, ['hy', 'hz'], (0, 0, 0), (0, -1, -1),
                                  True)

            target = size - 1 if rank == 0 else rank - 1
            self.req_send_e = comm.Send_init(gf_e.host_array, target, tag=1)
            self.tmp_recv_h = np.zeros(gf_e.host_array.shape, gpuf.dtype)
            self.req_recv_h = comm.Recv_init(self.tmp_recv_h, target, tag=0)

        # global variables
        self.core = core
        self.direction = direction

    def update_e(self):
        self.core.update_e('pre')

        if '-' in self.direction:
            self.gf_e.get_event().wait()
            self.req_send_e.Start()

        if '+' in self.direction:
            self.req_recv_e.Start()

        self.core.update_e('post')

        if '-' in self.direction:
            self.req_send_e.Wait()

        if '+' in self.direction:
            self.req_recv_e.Wait()
            self.sf_e.set_fields(self.tmp_recv_e)

    def update_h(self):
        self.core.update_h('pre')

        if '+' in self.direction:
            self.gf_h.get_event().wait()
            self.req_send_h.Start()

        if '-' in self.direction:
            self.req_recv_h.Start()

        self.core.update_h('post')

        if '+' in self.direction:
            self.req_send_h.Wait()

        if '-' in self.direction:
            self.req_recv_h.Wait()
            self.sf_h.set_fields(self.tmp_recv_h)