All pastes #2457643 Raw Edit

test.c

public unlisted c v1 · immutable
#2457643 ·published 2013-09-24 05:28 UTC
rendered paste body
#include <petscsys.h>#include <petscvec.h>#include <petscmat.h>#undef __FUNCT__#define __FUNCT__ "main"intmain (int argc, char **argv){  PetscInitialize (&argc, &argv, (char *) 0, PETSC_NULL);  Mat AVG_BDIBJ;  Vec BDB_AA;  PetscInt dim = 5;  PetscInt matsize = dim * dim;  PetscInt Istart, Iend, sitestride1, sitestride2;  VecCreateSeq (PETSC_COMM_SELF, dim, &BDB_AA);  MatCreate (PETSC_COMM_WORLD, &AVG_BDIBJ);  MatSetSizes (AVG_BDIBJ, PETSC_DECIDE, PETSC_DECIDE, matsize, matsize);  MatSetFromOptions (AVG_BDIBJ);  MatSetUp (AVG_BDIBJ);  MatGetOwnershipRange (AVG_BDIBJ, &Istart, &Iend);  PetscScalar element, vecval;  PetscInt alpha, mu, lambda;  PetscInt count;  PetscInt *idx;  idx = malloc (matsize * sizeof (PetscInt));  for (count = 0; count < matsize; count++)    idx[count] = count;  PetscScalar *colvalues = malloc (matsize * sizeof (PetscScalar));  for (sitestride1 = Istart; sitestride1 < Iend; sitestride1++)    {      for (sitestride2 = 0; sitestride2 < matsize; sitestride2++)	{	  for (alpha = 0; alpha < dim; alpha++)	    {	      for (mu = 0; mu < dim; mu++)		for (lambda = 0; lambda < dim; lambda++)		  {		    vecval = rand () / rand ();		  }	      VecSetValue (BDB_AA, alpha, vecval, INSERT_VALUES);	    }	  VecAssemblyBegin (BDB_AA);	  VecAssemblyEnd (BDB_AA);	  VecSum (BDB_AA, &element);	  colvalues[sitestride2] = element;	}      //Insert the array of colvalues to the sitestride1^th row of H         MatSetValues (AVG_BDIBJ, 1, &sitestride1, matsize, idx, colvalues,		    INSERT_VALUES);    }  MatAssemblyBegin (AVG_BDIBJ, MAT_FINAL_ASSEMBLY);  MatAssemblyEnd (AVG_BDIBJ, MAT_FINAL_ASSEMBLY);  PetscViewer dekhbo;  PetscViewerDrawOpen (PETSC_COMM_WORLD, 0, "Hopping Matrix Diag Avg",		       PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE,		       PETSC_DECIDE, &dekhbo);  MatView (AVG_BDIBJ, dekhbo);  MatDestroy (&AVG_BDIBJ);  VecDestroy (&BDB_AA);  free (idx);  free (colvalues);  PetscFinalize ();  return 0;}