forked from frovedis/frovedis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scalapack_demo.py
executable file
·81 lines (65 loc) · 2.81 KB
/
scalapack_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
import sys
import numpy as np
from frovedis.exrpc.server import FrovedisServer
from frovedis.matrix.dense import FrovedisBlockcyclicMatrix
from frovedis.matrix.wrapper import SCALAPACK
# initializing the Frovedis server
argvs = sys.argv
argc = len(argvs)
if (argc < 2):
print ('Please give frovedis_server calling command as the first argument \n(e.g. "mpirun -np 2 -x /opt/nec/nosupport/frovedis/ve/bin/frovedis_server")')
quit()
FrovedisServer.initialize(argvs[1])
# Loading Frovedis server side blockcyclic matrix from text file
bcm1 = FrovedisBlockcyclicMatrix(dtype=np.float64)
print("loading blockcyclic matrix from text file: ./input/mat_3x3")
bcm1.load("./input/mat_3x3")
bcm1.get_rowmajor_view()
# --- getrf (LU factorization) demo ---
rf = SCALAPACK.getrf(bcm1)
print("getrf info: " + str(rf.stat()))
# --- getri (matrix inversion using LU factor) demo ---
stat = SCALAPACK.getri(bcm1,rf.ipiv())
print("getri info: " + str(stat))
# Saving inverse matrix in text format
print("saving result to text file: ./out/inv_mat_3x3")
bcm1.save("./out/inv_mat_3x3") #result can be saved in text file
# Releasing IPIV vector and LU factored matrix from Frovedis server
rf.release()
bcm1.release()
# Loading new text file containing 4x4 input data for computing SVD
print("loading blockcyclic matrix from text file: ./input/svd_input_4x4")
bcm1.load("./input/svd_input_4x4")
bcm1.get_rowmajor_view()
# --- gesvd (computing SVD) demo ---
svd = SCALAPACK.gesvd(bcm1)
print("gesvd info: " + str(svd.stat()))
# Saving SVD results (singular values and singular vectors) in text format
print("saving svd results: ")
# sfile name is mandatory... ufile/vfile can be None (default), if not required to be saved
svd.save("./out/svd_output_sfile","./out/svd_output_ufile","./out/svd_output_vfile")
# getting the result back at pythob side
print("printing the results (umat, svec, vmat) at python client:")
(umat,svec,vmat) = svd.to_numpy_results()
print (umat)
print (svec)
print (vmat)
# Releasing input matrix and resultant matrices
print("releasing frovedis side svd input and result data")
bcm1.release()
svd.release()
# Loading the same results from saved text files
print("loading the same svd results from saved files as blockcyclic matrix (umat/vmat):")
svd.load("./out/svd_output_sfile","./out/svd_output_ufile","./out/svd_output_vfile")
print("printing the loaded svd results (at Frovedis server): ")
svd.debug_print()
svd.release()
# sfile name is mandatory... ufile/vfile can be None (default), if not required to be loaded
print("loading only svec and umat (as colmajor matrix) from saved files:")
svd.load("./out/svd_output_sfile", "./out/svd_output_ufile", mtype='C')
print("printing partially loaded svd results (at Frovedis server): ")
svd.debug_print()
svd.release()
# Shutting down the Frovedis server
FrovedisServer.shut_down()