Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
from frovedis.exrpc.server import FrovedisServer
from frovedis.matrix.dense import FrovedisBlockcyclicMatrix
from frovedis.matrix.wrapper import PBLAS

FrovedisServer.initialize("mpirun -np 2 {}".format(os.environ['FROVEDIS_SERVER']))

# numpy matrices creation
x = np.matrix([[1],[2],[3],[4]], dtype=np.float64) # 4x1
y = np.matrix([[5],[6],[7],[8]], dtype=np.float64) # 4x1
m = np.matrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],
               dtype=np.float64) # 4x4: eye(I)
n = np.matrix([[1,2,3,4],[5,6,7,8],[8,7,6,5],[4,3,2,1]],
               dtype=np.float64) # 4x4

# Creating Frovedis server side blockcyclic matrics from numpy matrices
bcx = FrovedisBlockcyclicMatrix(x) # blockcyclic vector (x)
bcy = FrovedisBlockcyclicMatrix(y) # blockcyclic vector (y)
bcm = FrovedisBlockcyclicMatrix(m) # blockcyclic matrix (m)
bcn = FrovedisBlockcyclicMatrix(n) # blockcyclic matrix (n)

# --- print original data
print ("x:")
print (x)
print ("y:")
print (y)
print ("m:")
print (m)
print ("m:")
print (n)

# --- swap ---
Ejemplo n.º 3
0
from frovedis.exrpc.server import FrovedisServer
from frovedis.matrix.dense import FrovedisBlockcyclicMatrix
import sys

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

mat = np.asmatrix([[2, 1, 1], [3, 2, 1], [2, 1, 2]], dtype=np.float64)
bmat = FrovedisBlockcyclicMatrix(mat)

print("input matrix:")
print(mat)

print("--- demo of frovedis wrapper with input as numpy matrix ---")
from frovedis.linalg import *
frov_rf = dgetrf(mat)
print("lu factor: ")
print(frov_rf[0])
frov_ri = dgetri(frov_rf[0], frov_rf[1])
print("inverse: ")
print(frov_ri[0])

print(
    "--- demo of frovedis wrapper with input as FrovedisBlockcyclicMatrix ---")
Ejemplo n.º 4
0
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])

# sample numpy matrices creation
m1 = np.matrix([[1],[2],[3],[4]], dtype=np.float64) # 4x1
m2 = np.matrix([[5],[6],[7],[8]], dtype=np.float64) # 4x1
m3 = np.matrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],
               dtype=np.float64) # 4x4: eye(I)
m4 = np.matrix([[1,2,3,4],[5,6,7,8],[8,7,6,5],[4,3,2,1]],
               dtype=np.float64) # 4x4

# Creating Frovedis server side blockcyclic matrics from numpy matrices
bcm1 = FrovedisBlockcyclicMatrix(m1) # blockcyclic vector (x)
bcm2 = FrovedisBlockcyclicMatrix(m2) # blockcyclic vector (y)
bcm3 = FrovedisBlockcyclicMatrix(m3) # blockcyclic matrix (m)
bcm4 = FrovedisBlockcyclicMatrix(m4) # blockcyclic matrix (n)

# --- swap demo ---
PBLAS.swap(bcm1,bcm2)
print ("after swap (x <=> y):")
bcm1.get_rowmajor_view()
bcm2.get_rowmajor_view()

# --- scal demo ---
PBLAS.scal(bcm1,2)
print ("after scal (x = 2x):")
bcm1.get_rowmajor_view()
Ejemplo n.º 5
0
import os
import numpy as np
from frovedis.exrpc.server import FrovedisServer
from frovedis.matrix.dense import FrovedisBlockcyclicMatrix
from frovedis.matrix.wrapper import SCALAPACK

FrovedisServer.initialize("mpirun -np 2 {}".format(
    os.environ['FROVEDIS_SERVER']))

# Loading Frovedis server side blockcyclic matrix from text file
bcm = FrovedisBlockcyclicMatrix(dtype=np.float64)
print("loading blockcyclic matrix from text file: ./input")
bcm.load("./input")
m = bcm.to_numpy_matrix()
print(m)

# --- getrf (LU factorization) ---
rf = SCALAPACK.getrf(bcm)

# --- getri (matrix inversion using LU factor) ---
SCALAPACK.getri(bcm, rf.ipiv())
print("inverse of the matrix")
print(bcm.to_numpy_matrix())

# Releasing IPIV vector and LU factored matrix from Frovedis server
rf.release()
bcm.release()

# use the same matrix
bcm = FrovedisBlockcyclicMatrix(m)
x = np.matrix([[1], [2], [3]], dtype=np.float64)