#include "petsc.h" #define MAX_STR_SIZE 1024 // Main program int main(int argc,char *argv[]) { char auxstr[MAX_STR_SIZE]; Mat G; PetscErrorCode iErr,ierr = 0; PetscBool flag; PetscInt Np = 0; // MATRIX SIZE DECLARATION PetscInt nRows = 300, //5085, nCols = 200; //737352; PetscViewer binv; int rVal = 0; iErr = PetscInitialize(&argc,&argv,PETSC_NULL,0); CHKERRQ(iErr); iErr = PetscOptionsGetString(PETSC_NULL,"--mtx-file",auxstr,MAX_STR_SIZE,&flag); CHKERRQ(iErr); MatCreateMPIDense(PETSC_COMM_WORLD,PETSC_DECIDE,PETSC_DECIDE,nRows,nCols,PETSC_NULL,&G);CHKERRQ(ierr); PetscPrintf(PETSC_COMM_WORLD,"Matrix created successfully!\n"); iErr = MatAssemblyBegin(G,MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); iErr = MatAssemblyEnd(G,MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); PetscPrintf(PETSC_COMM_WORLD,"Matrix assembled successfully!\n"); iErr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,auxstr,FILE_MODE_WRITE,&binv); CHKERRQ(iErr); iErr = PetscViewerPushFormat(binv,PETSC_VIEWER_NATIVE); CHKERRQ(iErr); iErr = MatView(G,binv); CHKERRQ(iErr); iErr = PetscViewerDestroy(&binv); CHKERRQ(iErr); PetscPrintf(PETSC_COMM_WORLD,"Matrix successfully written: now cleaning up and exiting.\n"); iErr = MatDestroy(&G); CHKERRQ(iErr); ierr = MatCreate(PETSC_COMM_WORLD,&G);CHKERRQ(ierr); ierr = MatSetType(G,MATDENSE);CHKERRQ(ierr); iErr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,auxstr,FILE_MODE_READ,&binv); CHKERRQ(iErr); iErr = PetscViewerPushFormat(binv,PETSC_VIEWER_NATIVE); CHKERRQ(iErr); iErr = MatLoad(G,binv); CHKERRQ(iErr); iErr = PetscViewerDestroy(&binv); CHKERRQ(iErr); MatDestroy(&G); PetscFinalize(); return( rVal ); }