example.py 1.6 KB
 Sebastian Ohlmann committed Oct 29, 2018 1 2 ``````#!/usr/bin/env python import numpy as np `````` Sebastian Ohlmann committed Oct 30, 2018 3 ``````from pyelpa import DistributedMatrix `````` Sebastian Ohlmann committed Oct 29, 2018 4 5 6 7 8 9 10 ``````import sys # set some parameters for matrix layout na = 1000 nev = 200 nblk = 16 `````` Sebastian Ohlmann committed Oct 29, 2018 11 12 ``````# create distributed matrix a = DistributedMatrix.from_comm_world(na, nev, nblk) `````` Sebastian Ohlmann committed Oct 29, 2018 13 `````` `````` Sebastian Ohlmann committed Oct 30, 2018 14 ``````# set matrix a by looping over indices `````` Sebastian Ohlmann committed Oct 30, 2018 15 ``````# this is the easiest but also slowest way `````` Sebastian Ohlmann committed Oct 30, 2018 16 17 18 ``````for global_row, global_col in a.global_indices(): a.set_data_for_global_index(global_row, global_col, global_row*global_col) `````` Sebastian Ohlmann committed Oct 30, 2018 19 `````` `````` Sebastian Ohlmann committed Oct 29, 2018 20 21 ``````print("Call ELPA eigenvectors") sys.stdout.flush() `````` Sebastian Ohlmann committed Oct 29, 2018 22 `````` `````` Sebastian Ohlmann committed Oct 29, 2018 23 ``````# now compute nev of na eigenvectors and eigenvalues `````` Sebastian Ohlmann committed Oct 29, 2018 24 25 26 27 ``````data = a.compute_eigenvectors() eigenvalues = data['eigenvalues'] eigenvectors = data['eigenvectors'] `````` Sebastian Ohlmann committed Oct 29, 2018 28 29 30 ``````print("Done") # now eigenvectors.data contains the local part of the eigenvector matrix `````` Sebastian Ohlmann committed Oct 29, 2018 31 32 ``````# which is stored in a block-cyclic distributed layout and eigenvalues contains # all computed eigenvalues on all cores `````` Sebastian Ohlmann committed Oct 29, 2018 33 `````` `````` Sebastian Ohlmann committed Oct 30, 2018 34 ``````# set a again because it has changed after calling elpa `````` Sebastian Ohlmann committed Oct 30, 2018 35 36 37 38 39 40 41 42 ``````# this time set it by looping over blocks, this is more efficient for global_row, global_col, row_block_size, col_block_size in \ a.global_block_indices(): # set block with product of indices x = np.arange(global_row, global_row + row_block_size)[:, None] * \ np.arange(global_col, global_col + col_block_size)[None, :] a.set_block_for_global_index(global_row, global_col, row_block_size, col_block_size, x) `````` Sebastian Ohlmann committed Oct 30, 2018 43 `````` `````` Sebastian Ohlmann committed Oct 29, 2018 44 45 ``````print("Call ELPA eigenvalues") sys.stdout.flush() `````` Sebastian Ohlmann committed Oct 29, 2018 46 `````` `````` Sebastian Ohlmann committed Oct 29, 2018 47 ``````# now compute nev of na eigenvalues `````` Sebastian Ohlmann committed Oct 29, 2018 48 49 ``````eigenvalues = a.compute_eigenvalues() `````` Sebastian Ohlmann committed Oct 29, 2018 50 51 52 ``````print("Done") # now eigenvalues contains all computed eigenvalues on all cores``````