Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include "petscmat.h"  
  3. #include "mpi.h"
  4.  
  5. using namespace std;
  6.  
  7. // 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
  8.  
  9.  
  10. int main(int argc, char **args)
  11. {
  12.   PetscInitialize(&argc, &args, "", NULL);
  13.  
  14.   int MPIrank = 0, MPIsize = 0;
  15.   MPI_Comm_rank(MPI_COMM_WORLD, &MPIrank);
  16.   MPI_Comm_size(MPI_COMM_WORLD, &MPIsize);
  17.   cout << "MPI Size = " << MPIsize << endl;
  18.  
  19.   PetscErrorCode ierr = 0;
  20.  
  21.   int sizes[] = {4, 3, 3};
  22.   Mat matrix;
  23.  
  24.   ierr = MatCreate(PETSC_COMM_SELF, &matrix);
  25.   ierr = MatSetType(matrix, MATDENSE); CHKERRQ(ierr);
  26.   // ierr = MatSetSizes(matrix, sizes[MPIrank], sizes[MPIrank], PETSC_DECIDE, PETSC_DECIDE); CHKERRQ(ierr);
  27.   ierr = MatSetSizes(matrix, 10, 10, PETSC_DECIDE, PETSC_DECIDE); CHKERRQ(ierr);
  28.   MatSetUp(matrix);
  29.  
  30.   PetscInt ownerBegin, ownerEnd;
  31.   MatGetOwnershipRange(matrix, &ownerBegin, &ownerEnd);
  32.   cout << "Rank = " << MPIrank << " Begin = " << ownerBegin << " End = " << ownerEnd << endl;
  33.  
  34.   MatDestroy(&matrix);
  35.   PetscFinalize();  
  36.   return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement