Commit 954eb7f2 authored by Sebastian Ohlmann's avatar Sebastian Ohlmann
Browse files

update python tests and example

parent c92d3037
#!/usr/bin/env python #!/usr/bin/env python
import numpy as np import numpy as np
from pyelpa import ProcessorLayout, DistributedMatrix from pyelpa import DistributedMatrix
import sys import sys
# set some parameters for matrix layout # set some parameters for matrix layout
...@@ -11,15 +11,19 @@ nblk = 16 ...@@ -11,15 +11,19 @@ nblk = 16
# create distributed matrix # create distributed matrix
a = DistributedMatrix.from_comm_world(na, nev, nblk) a = DistributedMatrix.from_comm_world(na, nev, nblk)
# function for setting the matrix
# this is the easiest but also slowest way
def set_matrix(a): def set_matrix(a):
for global_row, global_col in a.global_indices(): for global_row, global_col in a.global_indices():
a.set_data_for_global_index(global_row, global_col, a.set_data_for_global_index(global_row, global_col,
global_row*global_col) global_row*global_col)
# set a
set_matrix(a)
print("Call ELPA eigenvectors") print("Call ELPA eigenvectors")
sys.stdout.flush() sys.stdout.flush()
set_matrix(a)
# now compute nev of na eigenvectors and eigenvalues # now compute nev of na eigenvectors and eigenvalues
data = a.compute_eigenvectors() data = a.compute_eigenvectors()
eigenvalues = data['eigenvalues'] eigenvalues = data['eigenvalues']
...@@ -31,12 +35,13 @@ print("Done") ...@@ -31,12 +35,13 @@ print("Done")
# which is stored in a block-cyclic distributed layout and eigenvalues contains # which is stored in a block-cyclic distributed layout and eigenvalues contains
# all computed eigenvalues on all cores # all computed eigenvalues on all cores
# set a again because it has changed after calling elpa
set_matrix(a)
print("Call ELPA eigenvalues") print("Call ELPA eigenvalues")
sys.stdout.flush() sys.stdout.flush()
set_matrix(a)
# now compute nev of na eigenvalues # now compute nev of na eigenvalues
set_matrix(a)
eigenvalues = a.compute_eigenvalues() eigenvalues = a.compute_eigenvalues()
print("Done") print("Done")
......
...@@ -54,7 +54,7 @@ def test_distributed_matrix_from_processor_layout(na, nev, nblk): ...@@ -54,7 +54,7 @@ def test_distributed_matrix_from_processor_layout(na, nev, nblk):
@pytest.mark.parametrize("na,nev,nblk", parameter_list) @pytest.mark.parametrize("na,nev,nblk", parameter_list)
def test_distributed_matrix_from_communicator(na, nev, nblk): def test_distributed_matrix_from_communicator(na, nev, nblk):
import numpy as np import numpy as np
from pyelpa import ProcessorLayout, DistributedMatrix from pyelpa import DistributedMatrix
from mpi4py import MPI from mpi4py import MPI
comm = MPI.COMM_WORLD comm = MPI.COMM_WORLD
...@@ -68,7 +68,7 @@ def test_distributed_matrix_from_communicator(na, nev, nblk): ...@@ -68,7 +68,7 @@ def test_distributed_matrix_from_communicator(na, nev, nblk):
@pytest.mark.parametrize("na,nev,nblk", parameter_list) @pytest.mark.parametrize("na,nev,nblk", parameter_list)
def test_distributed_matrix_from_world(na, nev, nblk): def test_distributed_matrix_from_world(na, nev, nblk):
import numpy as np import numpy as np
from pyelpa import ProcessorLayout, DistributedMatrix from pyelpa import DistributedMatrix
for dtype in [np.float64, np.float32, np.complex64, np.complex128]: for dtype in [np.float64, np.float32, np.complex64, np.complex128]:
a = DistributedMatrix.from_comm_world(na, nev, nblk, dtype=dtype) a = DistributedMatrix.from_comm_world(na, nev, nblk, dtype=dtype)
...@@ -164,7 +164,7 @@ def test_compare_eigenvalues_to_those_from_eigenvectors(na, nev, nblk): ...@@ -164,7 +164,7 @@ def test_compare_eigenvalues_to_those_from_eigenvectors(na, nev, nblk):
def test_compare_eigenvalues_to_those_from_eigenvectors_self_functions( def test_compare_eigenvalues_to_those_from_eigenvectors_self_functions(
na, nev, nblk): na, nev, nblk):
import numpy as np import numpy as np
from pyelpa import ProcessorLayout, DistributedMatrix from pyelpa import DistributedMatrix
for dtype in [np.float64, np.complex128]: for dtype in [np.float64, np.complex128]:
# create arrays # create arrays
...@@ -295,7 +295,7 @@ def test_dot_product(na, nev, nblk): ...@@ -295,7 +295,7 @@ def test_dot_product(na, nev, nblk):
@pytest.mark.parametrize("na,nev,nblk", parameter_list) @pytest.mark.parametrize("na,nev,nblk", parameter_list)
def test_dot_product_incompatible_size(na, nev, nblk): def test_dot_product_incompatible_size(na, nev, nblk):
import numpy as np import numpy as np
from pyelpa import ProcessorLayout, DistributedMatrix from pyelpa import DistributedMatrix
for dtype in [np.float64, np.complex128]: for dtype in [np.float64, np.complex128]:
a = DistributedMatrix.from_comm_world(na, nev, nblk, dtype=dtype) a = DistributedMatrix.from_comm_world(na, nev, nblk, dtype=dtype)
...@@ -312,7 +312,7 @@ def test_dot_product_incompatible_size(na, nev, nblk): ...@@ -312,7 +312,7 @@ def test_dot_product_incompatible_size(na, nev, nblk):
@pytest.mark.parametrize("na,nev,nblk", parameter_list) @pytest.mark.parametrize("na,nev,nblk", parameter_list)
def test_validate_eigenvectors(na, nev, nblk): def test_validate_eigenvectors(na, nev, nblk):
import numpy as np import numpy as np
from pyelpa import ProcessorLayout, DistributedMatrix from pyelpa import DistributedMatrix
for dtype in [np.float64, np.complex128]: for dtype in [np.float64, np.complex128]:
a = DistributedMatrix.from_comm_world(na, nev, nblk, dtype=dtype) a = DistributedMatrix.from_comm_world(na, nev, nblk, dtype=dtype)
...@@ -338,7 +338,7 @@ def test_validate_eigenvectors(na, nev, nblk): ...@@ -338,7 +338,7 @@ def test_validate_eigenvectors(na, nev, nblk):
def test_validate_eigenvectors_to_numpy(na, nev, nblk): def test_validate_eigenvectors_to_numpy(na, nev, nblk):
import numpy as np import numpy as np
from numpy import linalg from numpy import linalg
from pyelpa import ProcessorLayout, DistributedMatrix from pyelpa import DistributedMatrix
for dtype in [np.float64, np.complex128]: for dtype in [np.float64, np.complex128]:
a = DistributedMatrix.from_comm_world(na, nev, nblk, dtype=dtype) a = DistributedMatrix.from_comm_world(na, nev, nblk, dtype=dtype)
...@@ -364,7 +364,7 @@ def test_validate_eigenvectors_to_numpy(na, nev, nblk): ...@@ -364,7 +364,7 @@ def test_validate_eigenvectors_to_numpy(na, nev, nblk):
@pytest.mark.parametrize("na,nev,nblk", parameter_list) @pytest.mark.parametrize("na,nev,nblk", parameter_list)
def test_accessing_matrix(na, nev, nblk): def test_accessing_matrix(na, nev, nblk):
import numpy as np import numpy as np
from pyelpa import ProcessorLayout, DistributedMatrix from pyelpa import DistributedMatrix
for dtype in [np.float64, np.complex128]: for dtype in [np.float64, np.complex128]:
a = DistributedMatrix.from_comm_world(na, nev, nblk, dtype=dtype) a = DistributedMatrix.from_comm_world(na, nev, nblk, dtype=dtype)
...@@ -381,7 +381,7 @@ def test_accessing_matrix(na, nev, nblk): ...@@ -381,7 +381,7 @@ def test_accessing_matrix(na, nev, nblk):
@pytest.mark.parametrize("na,nev,nblk", parameter_list) @pytest.mark.parametrize("na,nev,nblk", parameter_list)
def test_global_index_iterator(na, nev, nblk): def test_global_index_iterator(na, nev, nblk):
import numpy as np import numpy as np
from pyelpa import ProcessorLayout, DistributedMatrix from pyelpa import DistributedMatrix
for dtype in [np.float64, np.complex128]: for dtype in [np.float64, np.complex128]:
a = DistributedMatrix.from_comm_world(na, nev, nblk, dtype=dtype) a = DistributedMatrix.from_comm_world(na, nev, nblk, dtype=dtype)
...@@ -392,7 +392,7 @@ def test_global_index_iterator(na, nev, nblk): ...@@ -392,7 +392,7 @@ def test_global_index_iterator(na, nev, nblk):
@pytest.mark.parametrize("na,nev,nblk", parameter_list) @pytest.mark.parametrize("na,nev,nblk", parameter_list)
def test_global_index_access(na, nev, nblk): def test_global_index_access(na, nev, nblk):
import numpy as np import numpy as np
from pyelpa import ProcessorLayout, DistributedMatrix from pyelpa import DistributedMatrix
for dtype in [np.float64, np.complex128]: for dtype in [np.float64, np.complex128]:
a = DistributedMatrix.from_comm_world(na, nev, nblk, dtype=dtype) a = DistributedMatrix.from_comm_world(na, nev, nblk, dtype=dtype)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment