***LOOPING MAIL*** PetscInitialize problem?

Satish Balay balay at mcs.anl.gov
Mon Mar 13 14:38:00 CST 2006


You should be able to use either MPI_COMM_WORLD or PETSC_COMM_WORLD or
any other communicator. There must be something else wrong in your
code. Can't comment without looking at the code.

Satish

On Mon, 13 Mar 2006, ziemer at lncc.br wrote:

> Hi,
> 
> The Petsc installation examples run ok.
> 
> The strange thing is if I change the parameter MPI_COMM_WORLD of the function
> MPI_Comm_size() to PTESC_COMM_WORLD this function works, but at same time this
> same strategy does not work with the MPI_Bcast() function.
> 
> Thank you very much for your nice help.
> 
> Paulo Ziemer.
> 
> 
> Quoting Satish Balay <balay at mcs.anl.gov>:
> 
> > According to the error message - the communicator is invalid.  You
> > might want to check that..
> >
> > You should be able to call MPI_Comm_size() after PetscInitialize()
> > Check src/sys/examples/tutorials/ex1.c for an example of this usage.
> >
> > BTW: Do PETSc examples run fine with your install?
> >
> > Satish
> >
> >
> > On Mon, 13 Mar 2006, ziemer at lncc.br wrote:
> >
> > > Hello,
> > >
> > > I would be very glad if someone could give me some direction:
> > >
> > > After the MPI_Comm_size function is called, I got this error:
> > >
> > > aborting job:
> > > Fatal error in MPI_Comm_size: Invalid communicator, error stack:
> > > MPI_Comm_size(110): MPI_Comm_size(comm=0x1, size=0xbfffdf78) failed
> > > MPI_Comm_size(69): Invalid communicator
> > >
> > > It seems that the MPI environment is not being correctly created by the
> > function
> > > PetscInitialize.
> > >
> > >
> > > Does anyone have any idea?
> > >
> > >
> > > Best Regards.
> > >
> > > ----------------------------------------------------------------
> > > This message was sent using IMP, the Internet Messaging Program.
> > >
> > >
> >
> 
> 
> 
> 
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
> 
> 
-------------- next part --------------

/* Program usage:  mpirun ex1 [-help] [all PETSc options] */

static char help[] = "Introductory example that illustrates printing.\n\n";

/*T
   Concepts: introduction to PETSc;
   Concepts: printing^in parallel
   Processors: n
T*/
 
#include "petsc.h"
int main(int argc,char **argv)
{
  PetscErrorCode ierr;
  PetscMPIInt    rank,size;

  /*
    Every PETSc routine should begin with the PetscInitialize() routine.
    argc, argv - These command line arguments are taken to extract the options
                 supplied to PETSc and options supplied to MPI.
    help       - When PETSc executable is invoked with the option -help, 
                 it prints the various options that can be applied at 
                 runtime.  The user can use the "help" variable place
                 additional help messages in this printout.
  */
  ierr = PetscInitialize(&argc,&argv,(char *)0,help);CHKERRQ(ierr);

  /* 
     The following MPI calls return the number of processes
     being used and the rank of this process in the group.
   */
  ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
  ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);

  /* 
     Here we would like to print only one message that represents
     all the processes in the group.  We use PetscPrintf() with the 
     communicator PETSC_COMM_WORLD.  Thus, only one message is
     printed representng PETSC_COMM_WORLD, i.e., all the processors.
  */
  ierr = PetscPrintf(PETSC_COMM_WORLD,"Number of processors = %d, rank = %d\n",size,rank);CHKERRQ(ierr);

  /*
    Here a barrier is used to separate the two program states.
  */
  ierr = MPI_Barrier(PETSC_COMM_WORLD);CHKERRQ(ierr);

  /*
    Here we simply use PetscPrintf() with the communicator PETSC_COMM_SELF,
    where each process is considered separately and prints independently
    to the screen.  Thus, the output from different processes does not
    appear in any particular order.
  */

  ierr = PetscPrintf(PETSC_COMM_SELF,"[%d] Jumbled Hello World\n",rank);CHKERRQ(ierr);

  /*
     Always call PetscFinalize() before exiting a program.  This routine
       - finalizes the PETSc libraries as well as MPI
       - provides summary and diagnostic information if certain runtime
         options are chosen (e.g., -log_summary).  See PetscFinalize()
     manpage for more information.
  */
  ierr = PetscFinalize();CHKERRQ(ierr);
  return 0;
}


More information about the petsc-users mailing list