Ejemplo n.º 1
0
def test_default_threads():
    if have_openmp:
        try:
            expected_threads = int(os.environ.get('OMP_NUM_THREADS', None))
            if expected_threads < 1:
                raise ValueError("invalid number of threads")
        except (ValueError, TypeError):
            expected_threads = cpu_count()
    else:
        expected_threads = 1
    assert_equal(default_threads, expected_threads)
Ejemplo n.º 2
0
def test_default_threads():
    if have_openmp:
        try:
            expected_threads = int(os.environ.get('OMP_NUM_THREADS', None))
            if expected_threads < 1:
                raise ValueError("invalid number of threads")
        except (ValueError, TypeError):
            expected_threads = cpu_count()
    else:
        expected_threads = 1
    assert_equal(default_threads, expected_threads)
Ejemplo n.º 3
0
def test_nlmeans_4d_3dsigma_and_threads():
    # Input is 4D data and 3D sigma
    data = np.ones((50, 50, 50, 5))
    sigma = np.ones(data.shape[:3])
    mask = np.zeros(data.shape[:3])

    # mask[25-10:25+10] = 1
    mask[:] = 1

    print('cpu count %d' % (cpu_count(),))

    print('1')
    t = time()
    new_data = nlmeans(data, sigma, mask, num_threads=1)
    duration_1core = time() - t
    print(duration_1core)

    print('All')
    t = time()
    new_data2 = nlmeans(data, sigma, mask, num_threads=None)
    duration_all_core = time() - t
    print(duration_all_core)

    print('2')
    t = time()
    new_data3 = nlmeans(data, sigma, mask, num_threads=2)
    duration_2core = time() - t
    print(duration_all_core)

    assert_array_almost_equal(new_data, new_data2)
    assert_array_almost_equal(new_data2, new_data3)

    if cpu_count() > 2:

        assert_equal(duration_all_core < duration_2core, True)
        assert_equal(duration_2core < duration_1core, True)

    if cpu_count() == 2:

        assert_equal(duration_2core < duration_1core, True)
Ejemplo n.º 4
0
def test_nlmeans_4d_3dsigma_and_threads():
    # Input is 4D data and 3D sigma
    data = np.ones((50, 50, 50, 5))
    sigma = np.ones(data.shape[:3])
    mask = np.zeros(data.shape[:3])

    # mask[25-10:25+10] = 1
    mask[:] = 1

    print('cpu count %d' % (cpu_count(), ))

    print('1')
    t = time()
    new_data = nlmeans(data, sigma, mask, num_threads=1)
    duration_1core = time() - t
    print(duration_1core)

    print('All')
    t = time()
    new_data2 = nlmeans(data, sigma, mask, num_threads=None)
    duration_all_core = time() - t
    print(duration_all_core)

    print('2')
    t = time()
    new_data3 = nlmeans(data, sigma, mask, num_threads=2)
    duration_2core = time() - t
    print(duration_2core)

    assert_array_almost_equal(new_data, new_data2)
    assert_array_almost_equal(new_data2, new_data3)

    if cpu_count() > 2:

        assert_equal(duration_all_core < duration_2core, True)
        assert_equal(duration_2core < duration_1core, True)

    if cpu_count() == 2:

        assert_equal(duration_2core < duration_1core, True)
Ejemplo n.º 5
0
def test_set_omp_threads():
    if have_openmp:
        # set threads to default
        _restore_omp_threads()
        assert_equal(thread_count(), default_threads)

        # change number of threads
        nthreads_new = default_threads + 1
        _set_omp_threads(nthreads_new)
        assert_equal(thread_count(), nthreads_new)

        # restore back to default
        _restore_omp_threads()
        assert_equal(thread_count(), default_threads)
    else:
        assert_equal(thread_count(), 1)
        assert_equal(cpu_count(), 1)
Ejemplo n.º 6
0
def test_set_omp_threads():
    if have_openmp:
        # set threads to default
        _restore_omp_threads()
        assert_equal(thread_count(), default_threads)

        # change number of threads
        nthreads_new = default_threads + 1
        _set_omp_threads(nthreads_new)
        assert_equal(thread_count(), nthreads_new)

        # restore back to default
        _restore_omp_threads()
        assert_equal(thread_count(), default_threads)
    else:
        assert_equal(thread_count(), 1)
        assert_equal(cpu_count(), 1)