/* Simple example to show how PETSc programs can be run from MATLAB. See ex12.m. */ static char help[] = "Solves the one dimensional heat equation.\n\n"; #include #include int main(int argc,char **argv) { PetscMPIInt rank,size; PetscInt M = 14,time_steps = 20,w=1,s=1,localsize,j,i,mybase,myend,globalsize; PetscErrorCode ierr; DM da; Vec global,local; PetscScalar *globalptr,*localptr; PetscReal h,k; ierr = PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr; CHKERRQ(PetscOptionsGetInt(NULL,NULL,"-M",&M,NULL)); CHKERRQ(PetscOptionsGetInt(NULL,NULL,"-time",&time_steps,NULL)); /* Set up the array */ CHKERRQ(DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,M,w,s,NULL,&da)); CHKERRQ(DMSetFromOptions(da)); CHKERRQ(DMSetUp(da)); CHKERRQ(DMCreateGlobalVector(da,&global)); CHKERRMPI(MPI_Comm_rank(PETSC_COMM_WORLD,&rank)); CHKERRMPI(MPI_Comm_size(PETSC_COMM_WORLD,&size)); /* Make copy of local array for doing updates */ CHKERRQ(DMCreateLocalVector(da,&local)); /* determine starting point of each processor */ CHKERRQ(VecGetOwnershipRange(global,&mybase,&myend)); /* Initialize the Array */ CHKERRQ(VecGetLocalSize (global,&globalsize)); CHKERRQ(VecGetArray (global,&globalptr)); for (i=0; i