Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "petscmat.h"
- #include "mpi.h"
- using namespace std;
- // Compile with: mpicxx -g3 -Wall -I ~/software/petsc/include -I ~/software/petsc/arch-linux2-c-debug/include -L ~/software/petsc/arch-linux2-c-debug/lib -lpetsc test.cpp
- int main(int argc, char **args)
- {
- PetscInitialize(&argc, &args, "", NULL);
- int MPIrank = 0, MPIsize = 0;
- MPI_Comm_rank(MPI_COMM_WORLD, &MPIrank);
- MPI_Comm_size(MPI_COMM_WORLD, &MPIsize);
- cout << "MPI Size = " << MPIsize << endl;
- PetscErrorCode ierr = 0;
- int sizes[] = {4, 3, 3};
- Mat matrix;
- ierr = MatCreate(PETSC_COMM_SELF, &matrix);
- ierr = MatSetType(matrix, MATDENSE); CHKERRQ(ierr);
- // ierr = MatSetSizes(matrix, sizes[MPIrank], sizes[MPIrank], PETSC_DECIDE, PETSC_DECIDE); CHKERRQ(ierr);
- ierr = MatSetSizes(matrix, 10, 10, PETSC_DECIDE, PETSC_DECIDE); CHKERRQ(ierr);
- MatSetUp(matrix);
- PetscInt ownerBegin, ownerEnd;
- MatGetOwnershipRange(matrix, &ownerBegin, &ownerEnd);
- cout << "Rank = " << MPIrank << " Begin = " << ownerBegin << " End = " << ownerEnd << endl;
- MatDestroy(&matrix);
- PetscFinalize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement