From: Roy S. <roy...@ic...> - 2008-03-19 14:34:28
|
On Wed, 19 Mar 2008, David Knezevic wrote: > I've just updated to the SVN head, and saw that libMesh::init is now > deprecated. So I changed to use LibMeshInit, but I get a problem when I > make MPI calls. For example, this runs fine: > > int main (int argc, char** argv) > { > libMesh::init(argc,argv); > { > > PetscErrorCode ierr; > PetscMPIInt num_procs; > ierr = MPI_Comm_size(PETSC_COMM_WORLD,&num_procs);CHKERRQ(ierr); > > } > return libMesh::close(); > } > > But changing to: > > int main (int argc, char** argv) > { > LibMeshInit(argc,argv); > > PetscErrorCode ierr; > PetscMPIInt num_procs; > ierr = MPI_Comm_size(PETSC_COMM_WORLD,&num_procs);CHKERRQ(ierr); > > } > > I get the error: > "Attempting to use an MPI routine after finalizing MPICH". > > I haven't spotted what's causing the problem, help would be appreciated. Instead of LibMeshInit(argc, argv), try LibMeshInit init (argc, argv); Your way, a temporary LibMeshInit object is being created (which initializes MPI) but immediately destroyed (which finalizes MPI). The LibMeshInit object needs to last as long as your use of MPI/PETSc/ libMesh does. Don't feel bad; I originally made the same mistake when converting the examples. I really like the C++ "constructors acquire resources, destructors delete them" idiom, but it would really help if there was a way to catch this sort of typo at compile time instead of run time. --- Roy |