[petsc-users] Why is PETSC_COMM_WORLD changed?

Jed Brown jed at jedbrown.org
Fri Dec 19 11:30:49 CST 2014


Florian Lindner <mailinglists at xgm.de> writes:

> Hello,
>
> I have a piece of code that looks like that:
>
>   // PETSC_COMM_WORLD = MPI_COMM_WORLD;
>   PetscBool petscIsInitialized;
>   PetscInitialized(&petscIsInitialized);
>     
>   if (not petscIsInitialized) {
>     PetscErrorCode ierr;
>
>     std::cout << "PETSC == WORLD: " << (PETSC_COMM_WORLD == MPI_COMM_WORLD) << std::endl;
>     std::cout << "PETSC_COMM_WORLD: " << PETSC_COMM_WORLD << std::endl;
>     std::cout << "Petsc before PetscInitializeNoArguments()"  << std::endl;
>     ierr = PetscInitializeNoArguments(); CHKERRV(ierr);
>     std::cout << "Petsc after PetscInitializeNoArguments()"  << std::endl;
>   }
>
> PETSC_COMM_WORLD is touched nowhere else in our source, I promise, having grepped through right now.
>
> The code runs fine like that, but when I uncomment the first line it does not anymore.
>
> As far as I know PETSC_COMM_WORLD equals to MPI_COMM_WORLD unless
> changed, 

src/sys/objects/pinit.c:

  /* user may set this BEFORE calling PetscInitialize() */
  MPI_Comm PETSC_COMM_WORLD = MPI_COMM_NULL;

(and later)

  if (PETSC_COMM_WORLD == MPI_COMM_NULL) PETSC_COMM_WORLD = MPI_COMM_WORLD;

You can set PETSC_COMM_WORLD before PetscInitialize, but its value is
not valid/useful before PetscInitialize.

> but when I run it prints
>
> PETSC == WORLD: 0
> PETSC_COMM_WORLD: 67108864
>
> The first line uncommented gives:
>
> PETSC == WORLD: 1
> PETSC_COMM_WORLD: 1140850688
>
> (and an error in my program: Attempting to use an MPI routine before initializing MPICH)
>
> Just trying to understand what's going on...
>
> Thanks and have a nice weekend!
>
> Florian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20141219/b90322ab/attachment.pgp>


More information about the petsc-users mailing list