Skip to content

Commit

Permalink
Fix errors in the computation of edge length histo
Browse files Browse the repository at this point in the history
  - Calls the suitable function in PMMG_computePrilen when an aniso metric
 is provided with a specific metric storage at ridges (metRidTyp==1)
  - Check if metric is allocated before computing the edge lengths (to avoid memory errors)
 but inside the `MMG3D|PMMG_computePrilen` functions to be able to differentiate the cases where:
    - computePrilen fails due to memory error
    - We have a metric on at least one MPI proc so we can compute the edge lengths
    - We don't have any metric (and we cannot compute the edge length histo). In this case and
      with a centralized mesh on 1 proc and -v 10 verbosity, we were previously printing infinit edge lengths.

It makes the PMMG_prilen function callable everywhere in the software.
  • Loading branch information
Algiane committed Dec 5, 2023
1 parent 250dce2 commit e6a398b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ IF ( DOWNLOAD_MMG )

EXTERNALPROJECT_ADD ( Mmg
GIT_REPOSITORY https://github.com/MmgTools/mmg.git
GIT_TAG bdbf11ada1a9c44d179636f7f2ebe00ce76f0558
GIT_TAG 90916feecc62932701e4f8ae367a20f1c77215a9
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install
CMAKE_ARGS ${MMG_ARGS} -DUSE_ELAS=OFF ${COMPILER_CFG} ${FLAGS_CFG}
${SCOTCH_CFG} ${VTK_CFG} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
Expand Down
70 changes: 50 additions & 20 deletions src/quality_pmmg.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "parmmg.h"
#include <stddef.h>
#include "inlined_functions_3d_private.h"
#include "mmgexterns_private.h"

typedef struct {
double min;
Expand Down Expand Up @@ -371,7 +372,7 @@ int PMMG_qualhisto( PMMG_pParMesh parmesh, int opt, int isCentral, MPI_Comm comm
* read_comm communicator (i.e. the communicator used to provide the inputs).
* For all ather calls, comm has to be the communicator to use for computations.
*
* \return 0 if fail, 1 otherwise.
* \return 2 without metric, 0 if fail, 1 otherwise.
*
* Compute the required information to print the length histogram
*
Expand Down Expand Up @@ -405,6 +406,12 @@ int PMMG_computePrilen( PMMG_pParMesh parmesh,MMG5_pMesh mesh, MMG5_pSol met, do
*amin = *amax = *bmin = *bmax = 0;
*nullEdge = 0;

if ( (!met) || (!met->m) ) {
/* the functions that computes the edge length cannot be called without an
* allocated metric */
return 2;
}

/* Hash parallel edges in the mesh */
if ( PMMG_hashPar(mesh,&hpar) != PMMG_SUCCESS ) return 0;

Expand Down Expand Up @@ -469,11 +476,18 @@ int PMMG_computePrilen( PMMG_pParMesh parmesh,MMG5_pMesh mesh, MMG5_pSol met, do
/* Remove edge from hash ; ier = 1 if edge has been found */
ier = MMG5_hashPop(&hash,np,nq);
if( ier ) {
if ( (!metRidTyp) && met->size==6 && met->m ) {
assert ( met->m );
if ( (!metRidTyp) && met->size==6 ) {
assert ( met->m );
/* We pass here if metric is aniso without metRidTyp */
len = MMG5_lenSurfEdg33_ani(mesh,met,np,nq,(tag & MG_GEO));
}
else
len = MMG5_lenSurfEdg_iso(mesh,met,np,nq,0);
else {
/* We pass here if metric is aniso with metRidTyp or iso with
* allocated metric. Note that the lenSurfEdg function segfault if called
* with met==NULL or met->m==NULL */
len = MMG5_lenSurfEdg(mesh,met,np,nq,0);
}


if ( !len ) {
Expand Down Expand Up @@ -534,6 +548,7 @@ int PMMG_computePrilen( PMMG_pParMesh parmesh,MMG5_pMesh mesh, MMG5_pSol met, do
/* Remove edge from hash ; ier = 1 if edge has been found */
ier = MMG5_hashPop(&hash,np,nq);
if( ier ) {
assert ( met->m );
if ( (!metRidTyp) && met->size==6 && met->m ) {
len = MMG5_lenedg33_ani(mesh,met,ia,pt);
}
Expand Down Expand Up @@ -656,21 +671,35 @@ int PMMG_prilen( PMMG_pParMesh parmesh, int8_t metRidTyp, int isCentral, MPI_Com
if ( parmesh->ngrp==1 ) {
mesh = parmesh->listgrp[0].mesh;
met = parmesh->listgrp[0].met;
if ( met && met->m ) {
if( isCentral )
ier = MMG3D_computePrilen( mesh, met,
&lenStats.avlen, &lenStats.lmin,
&lenStats.lmax, &lenStats.ned, &lenStats.amin,
&lenStats.bmin, &lenStats.amax, &lenStats.bmax,
&lenStats.nullEdge, metRidTyp, &bd,
lenStats.hl );
else
ier = PMMG_computePrilen( parmesh, mesh, met,
&lenStats.avlen, &lenStats.lmin,
&lenStats.lmax, &lenStats.ned, &lenStats.amin,
&lenStats.bmin, &lenStats.amax, &lenStats.bmax,
&lenStats.nullEdge, metRidTyp, &bd,
lenStats.hl,comm );
if( isCentral ) {
/* If metric is not allocated or if hash table alloc fails, the next
* function returns 0, which allows to detect that we cannot print the
* edge length histo. */
ier = MMG3D_computePrilen( mesh, met,
&lenStats.avlen, &lenStats.lmin,
&lenStats.lmax, &lenStats.ned, &lenStats.amin,
&lenStats.bmin, &lenStats.amax, &lenStats.bmax,
&lenStats.nullEdge, metRidTyp, &bd,
lenStats.hl );
}
else {
/* The next function returns 0 if the hash table alloc fails and 2 if
* called without metric (in this case we are not able to compute the edge
* lengths). It allows to detect:
* - if we can't print the histo due to an alloc error (ier = 0 on 1 MPI
* process at least)
* - if we can't print the histo because the metric is not allocated
* (ier=2 on all the MPI process)
* - if we can print the histo (metric is allocated on at least 1 MPI
* process and no MPI process fail, thus ier is at least 1 on all the
* MPI proc but may be 2 on some of them)
*/
ier = PMMG_computePrilen( parmesh, mesh, met,
&lenStats.avlen, &lenStats.lmin,
&lenStats.lmax, &lenStats.ned, &lenStats.amin,
&lenStats.bmin, &lenStats.amax, &lenStats.bmax,
&lenStats.nullEdge, metRidTyp, &bd,
lenStats.hl,comm );
}
}

Expand All @@ -679,7 +708,8 @@ int PMMG_prilen( PMMG_pParMesh parmesh, int8_t metRidTyp, int isCentral, MPI_Com
else
MPI_Reduce( &ier, &ieresult,1, MPI_INT, MPI_MIN, parmesh->info.root, comm );

if ( !ieresult ) {
if ( (ieresult==0) || ieresult==2 ) {
/* We are not able to print the histogram */
MPI_Type_free( &mpi_lenStats_t );
MPI_Op_free( &mpi_lenStats_op );
return 0;
Expand Down

0 comments on commit e6a398b

Please sign in to comment.