On Mon, 9 Mar 2009, Roy Stogner wrote:

On Mon, 9 Mar 2009, Tim Kroeger wrote:

But wouldn't we be catching that with a libmesh_assert()?  The
preconditions on operator= in petsc_vector.C seem pretty thorough.

But only in debug mode, right?

Right.

Talking about asserts, what do you think about the attached patch?

(I'm now using METHOD=devel and try to catch my crash using asserts, and I suspect now that it's in the ghosted part of PetscVector somewhere.)

libMesh makes it easy enough to keep simultaneous
debug and optimized builds around; IMHO every software package should
do the same.

Well, our software package tries to make that easy as well. It's just so huge a package that it's still difficult to work with several versions.

Anyway, METHOD=devel works well with the non-debug version of our software. Actuall, it causes my application to crash at a completely different point, even before any NumericVectors are used. Would you please have a look at the attached test.cpp; it creates a grid, partially refines 5 times and then completely coarsens it again. To actually delete the elements that are not required, it calls Mesh::contract(), which crashes for me with METHOD=devel. (It runs well with METHOD=opt, though.)

Best Regards,

Tim

--
Dr. Tim Kroeger
tim.kroe...@mevis.fraunhofer.de            Phone +49-421-218-7710
tim.kroe...@cevis.uni-bremen.de            Fax   +49-421-218-4236

Fraunhofer MEVIS, Institute for Medical Image Computing
Universitaetsallee 29, 28359 Bremen, Germany
Index: include/numerics/petsc_vector.h
===================================================================
--- include/numerics/petsc_vector.h     (Revision 3305)
+++ include/numerics/petsc_vector.h     (Arbeitskopie)
@@ -988,6 +988,14 @@
       CHKERRABORT(libMesh::COMM_WORLD,ierr);
       ierr = VecGetArray(loc_vec, &values);
       CHKERRABORT(libMesh::COMM_WORLD,ierr);
+
+#ifndef NDEBUG
+      int local_size = 0;
+      ierr = VecGetLocalSize(loc_vec, &local_size);
+      CHKERRABORT(libMesh::COMM_WORLD,ierr);
+      libmesh_assert(local_index<static_cast<unsigned int>(local_size));
+#endif
+
       value = values[local_index];
       ierr = VecRestoreArray (loc_vec, &values);
       CHKERRABORT(libMesh::COMM_WORLD,ierr);
#include <iostream>
#include <math.h>

#include "libmesh.h"
#include "mesh.h"
#include "mesh_generation.h"
#include "mesh_refinement.h"
#include "elem.h"

int main (int argc, char** argv)
{
  LibMeshInit init (argc, argv);

  Mesh mesh (3);
  
  MeshTools::Generation::build_cube (mesh, 
                                     10, 10, 10,
                                       -1., 1.,
                                       -1., 1.,
                                       -1., 1.,
                                     HEX8);
  MeshRefinement meshRefinement(mesh);
  meshRefinement.edge_level_mismatch_limit() = 1;

  std::cout << "Mesh has " << mesh.n_elem() << " elements and " << 
mesh.n_nodes() << " nodes." << std::endl;

  for(unsigned int ii=0; ii<5; ii++)
    {
      MeshBase::element_iterator       elem_it  = mesh.active_elements_begin();
      const MeshBase::element_iterator elem_end = mesh.active_elements_end(); 
      unsigned int q = 0;
      for (;elem_it!=elem_end; ++elem_it)
        {
          q++;
          if(q%29==0)
            {
              (*elem_it)->set_refinement_flag(Elem::REFINE);
            }
        }
      meshRefinement.refine_and_coarsen_elements();
      std::cout << "Mesh has " << mesh.n_elem() << " elements and " << 
mesh.n_nodes() << " nodes." << std::endl;
    }
  
  for(unsigned int ii=0; ii<5; ii++)
    {
      MeshBase::element_iterator       elem_it  = mesh.active_elements_begin();
      const MeshBase::element_iterator elem_end = mesh.active_elements_end(); 
      for (;elem_it!=elem_end; ++elem_it)
        {
          (*elem_it)->set_refinement_flag(Elem::COARSEN);
        }
      meshRefinement.refine_and_coarsen_elements();
      std::cout << "Mesh has " << mesh.n_elem() << " elements and " << 
mesh.n_nodes() << " nodes." << std::endl;
    }    

  std::cout << "I'm how here." << std::endl;
  mesh.contract(); // crashes
  std::cout << "Mesh has " << mesh.n_elem() << " elements and " << 
mesh.n_nodes() << " nodes." << std::endl;

  return 0;
}

------------------------------------------------------------------------------
_______________________________________________
Libmesh-devel mailing list
Libmesh-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libmesh-devel

Reply via email to