File: ConvertMtxToPetsc.py

package info (click to toggle)
combblas 2.0.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 190,488 kB
  • sloc: cpp: 55,918; ansic: 25,134; sh: 3,691; makefile: 548; csh: 66; python: 49; perl: 21
file content (26 lines) | stat: -rw-r--r-- 781 bytes parent folder | download | duplicates (2)
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
import os, sys, argparse, logging
from scipy.io import mmread

# change if you use a different dir
sys.path.append('/opt/cray/pe/petsc/3.11.2.0/real/GNU64/8.2/haswell/lib/petsc/bin')
import PetscBinaryIO

parser = argparse.ArgumentParser()
parser.add_argument('matrix')
parser.add_argument('-o', '--outfile')

args = parser.parse_args()

# logging setup
logging.basicConfig(stream=sys.stdout,
                    format='%(asctime)s ::: %(levelname)s ::: %(filename)s ::: '
                    '%(funcName)s ::: line %(lineno)d ::: %(message)s',
                    level=logging.INFO)

A = mmread(args.matrix)
outfile = args.matrix.replace('.mtx', '.petsc')

if (args.outfile != None):
    outfile = args.outfile

PetscBinaryIO.PetscBinaryIO().writeMatSciPy(open(outfile,'w'), A)