def runTest(self):
        nx, ny, nz, str_f, pt0, pt1, is_array = self.args
        slice_xyz = common.slices_two_points(pt0, pt1)

        # generate random source
        if is_array:
            shape = common.shape_two_points(pt0, pt1)
            value = np.random.rand(*shape).astype(np.float32)
        else:
            value = np.random.ranf()

        # 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')

        tfunc = lambda tstep: np.sin(0.03*tstep)
        incident = IncidentDirect(fields, str_f, pt0, pt1, tfunc, value) 

        # host allocations
        eh = np.zeros(fields.ns_pitch, dtype=fields.dtype)

        # verify
        eh[slice_xyz] = fields.dtype(value) * fields.dtype(tfunc(1))
        fields.update_e()
        fields.update_h()
        fields.enqueue_barrier()

        copy_eh_buf = fields.get_buf(str_f)
        copy_eh = np.zeros_like(eh)
        cl.enqueue_copy(fields.queue, copy_eh, copy_eh_buf)

        original = eh[slice_xyz]
        copy = copy_eh[slice_xyz]
        norm = np.linalg.norm(original - copy)
        self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
Esempio n. 2
0
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1, is_array = self.args
        slice_xyz = common.slices_two_points(pt0, pt1)

        # generate random source
        if is_array:
            shape = common.shape_two_points(pt0, pt1)
            value = np.random.rand(*shape).astype(np.float32)
        else:
            value = np.random.ranf()

        # 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')

        tfunc = lambda tstep: np.sin(0.03 * tstep)
        incident = IncidentDirect(fields, str_f, pt0, pt1, tfunc, value)

        # host allocations
        eh = np.zeros(fields.ns_pitch, dtype=fields.dtype)

        # verify
        eh[slice_xyz] = fields.dtype(value) * fields.dtype(tfunc(1))
        fields.update_e()
        fields.update_h()
        fields.enqueue_barrier()

        copy_eh_buf = fields.get_buf(str_f)
        copy_eh = np.zeros_like(eh)
        cl.enqueue_copy(fields.queue, copy_eh, copy_eh_buf)

        original = eh[slice_xyz]
        copy = copy_eh[slice_xyz]
        norm = np.linalg.norm(original - copy)
        self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
Esempio n. 3
0
    if tstep % 10 == 0 and is_plot:
        getf.get_event().wait()
        np.save('rank%d_%d' % (rank, tstep), getf.get_fields())

        if is_master:
            print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)),
            sys.stdout.flush()

            for i in range(size):
                load_fail = True
                while load_fail:
                    try:
                        arr[i*nx:(i+1)*nx,:] = np.load('rank%d_%d.npy' % (i, tstep))
                        load_fail = False
                    except:
                        sleep(0.1)

            imag.set_array(arr.T)
            #plt.savefig('./png/%.6d.png' % tstep)
            plt.draw()

if is_plot:
    if is_master: sleep(1)
else:
    fields.enqueue_barrier()

if is_master:
    dt = time() - t00
    print dt
    print('[%s] %d/%d (%d %%) %f Mpoint/s' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100, nx*ny*nz*tmax/dt/1e6) )
Esempio n. 4
0
            print(
                '[%s] %d/%d (%d %%)\r' %
                (datetime.now() - t0, tstep, tmax, float(tstep) / tmax * 100)),
            sys.stdout.flush()

            for i in range(size):
                load_fail = True
                while load_fail:
                    try:
                        arr[i * nx:(i + 1) * nx, :] = np.load('rank%d_%d.npy' %
                                                              (i, tstep))
                        load_fail = False
                    except:
                        sleep(0.1)

            imag.set_array(arr.T)
            #plt.savefig('./png/%.6d.png' % tstep)
            plt.draw()

if is_plot:
    if is_master: sleep(1)
else:
    fields.enqueue_barrier()

if is_master:
    dt = time() - t00
    print dt
    print('[%s] %d/%d (%d %%) %f Mpoint/s' %
          (datetime.now() - t0, tstep, tmax, float(tstep) / tmax * 100,
           nx * ny * nz * tmax / dt / 1e6))