How to write a program, which can be run on 1 and multiple processors?
Barry Smith
bsmith at mcs.anl.gov
Mon Apr 27 11:19:42 CDT 2009
On Apr 26, 2009, at 4:30 PM, Yixun Liu wrote:
> Hi,
> I want to make my code run on 1 or multiple processors. The code,
> which
> can run on multiple processors is like the following,
>
> MatCreate(PETSC_COMM_WORLD, &A);
> MatSetSizes(A, 3*numOfVerticesOfOneProcessor,
> 3*numOfVerticesOfOneProcessor, systemSize, systemSize);
> MatSetFromOptions(A);
> MatMPIAIJSetPreallocation(A, 50, PETSC_NULL, 50, PETSC_NULL);
>
> However if I want to run on 1 processor I have to change the last
> code to:
> MatSeqAIJSetPreallocation(A,1000,PETSC_NULL);
>
> How to avoid changing code?
Just leave BOTH lines in the code.
PETSc has the unique feature that it ignores optional function
calls that are not
appropriate for the particular situation. So for runs with one process
the MPI version is
ignored and for runs with multiple processors the Seq version is
ignored.
Barry
>
>
> Thanks.
>
> Yixun
More information about the petsc-users
mailing list