[petsc-users] Why is PETSC_COMM_WORLD changed?
Barry Smith
bsmith at mcs.anl.gov
Fri Dec 19 11:43:43 CST 2014
> You can set PETSC_COMM_WORLD before PetscInitialize, but its value is
> not valid/useful before PetscInitialize.
I have added text to the manual page for PETSC_COMM_WORLD to make this clear.
> On Dec 19, 2014, at 11:30 AM, Jed Brown <jed at jedbrown.org> wrote:
>
> 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
More information about the petsc-users
mailing list