mmg icon indicating copy to clipboard operation
mmg copied to clipboard

Segfault switching from mmg3d 5.3.6/dev 32bit to 5.7.1 64 bit

Open jeandodo opened this issue 3 years ago • 2 comments

Bonjour

Notre code mailage hip marchait ss pb avec 5.3.6, en gros j'appelle

// own routine to copy mesh data to mmg
mmg_put_mesh_3d ( ..

/* Define sizes for a solution/metric field and allocate. */ if ( !MMG3D_Set_solSize( pMMesh, pMMet, MMG5_Vertex, pMMesh->np, MMG5_Scalar ) ) hip_err ( fatal, 0, "failed after MG3D_Set_solSize in adapt_mmg3d" ) ; if ( !MMG3D_Chk_meshData( pMMesh, pMMet ) ) hip_err ( fatal, 0, "failed after MMG3D_Chk_meshData in adapt_mmg3d" ) ;

hip_err ( info, 0, "before call MMG3D_doSol in adapt_mmg3d" ) ; // Initialise metric with average neighbor cell edge length status = MMG3D_doSol ( pMMesh, pMMet ); if ( !status ) { sprintf ( hip_msg, "call to MMG3D_doSol with status %d", status ) ; hip_err ( fatal, 0, hip_msg ) ; }

Basculant sur 5.7.1 master, (ayant modifie les int necessaries pour 64bit), je recois un segfault dans MMG3D_doSol.

Dans mmg/mmg3d/libmmg3d_tools.c dans la routine MMG3D_setfunc mmg declare le pointer MMG3D_doSol ou bien vers MMG3D_doSol_iso, ou bien _ani. Notre cas est _iso.

Si j'appelle directement la variante _iso, dedans mmg appele a la fin de doSol_iso MMG3D_solTruncatureForOptim et s'arrete sur le assert ( mesh->info.optim ), comme il faut. Il semble que la valeur de 0 pour mesh->info.optim est la seule possible.

Si j compile en debug, et j'appelle directement la variante _iso, mon cas simple passe ss pb, et comme avec la 5.3.

Comment pourrai-je deboguer ce cas? Cordialement, Jens

jeandodo avatar Jan 22 '23 13:01 jeandodo

Hi,

I don't work anymore on the Mmg support so I can't promise to solve this issue (or futur ones). I will try to help you to find the bug if my free time allows it.

I am not sure to understand when Mmg-7 fails :

  • it fails only when Mmg is built with int64 integers or when you build it with int32 integers too?
  • the issue is that the assertion on non-null value for mesh->info.optim fails?

If the issue is that mesh->info.optim is 0 inside MMG3D_solTruncatureForOptim I will remove the assert : When called from Mmg, mesh->info.optim has to be non-null in this function but called by the user it is not mandatory.

Another way to avoid this issue for you is to set (resp. unset) the mesh->info.optim value before (resp. after) the call to doSol function using the MMG<X>_Set_iparameter function and the MMG<X>_IPARAM_optim keyword.

Best, A

Algiane avatar Jan 25 '23 08:01 Algiane

Hi Algiane,

nice to hear from you, and thanks for helping.

it fails only when Mmg is built with int64 integers or when you build it with int32 integers too? yes, a int32 build with cmake -DUSE_VTK=NO .. also fails: <<hip[grid_4: 1/1]> mmg isofa -f0.5 INFO: Initialisation of MMG3D MAXIMUM MEMORY AUTHORIZED (MB) 7970 INFO: before call MMG3D_doSol in adapt_mmg3d Segmentation fault (core dumped)

the issue is that the assertion on non-null value for mesh->info.optim fails? When I compile mmg in debug, then I can look inside and see that the assertion is thrown. Tracing info.optim through the source I did not spot where it is made non-zero. But assert() is no-action unless compiled with -g? So this shouldn't make any difference in non-debug mode?

When I compile w/o debug, and manually modify info.optim as

hip_err ( info, 0, "before call MMG3D_doSol in adapt_mmg3d, setting mesh->info.optim=1" ) ; pMMesh->info.optim = 1 ; // Initialise metric with average neighbor cell edge length status = MMG3D_doSol ( pMMesh, pMMet ); if ( !status ) { sprintf ( hip_msg, "call to MMG3D_doSol with status %d", status ) ; hip_err ( fatal, 0, hip_msg ) ; } hip_err ( info, 0, "after call MMG3D_doSol in adapt_mmg3d, setting mesh->info.optim=0" ) ; pMMesh->info.optim = 0 ;

in int32 I still get a segfault, so the segfault is not associated with the assertion:

<<hip[grid_4: 1/1]> mmg isofa -f0.5 INFO: Initialisation of MMG3D MAXIMUM MEMORY AUTHORIZED (MB) 7970 INFO: before call MMG3D_doSol in adapt_mmg3d, setting mesh->info.optim=1 Segmentation fault (core dumped)

What works is compiling mmg either in debug with int64, or compiling with int32 (no debug), and calling doSol_iso instead of doSol:

<<hip[grid_4: 1/1]> mmg isofa -f0.5 INFO: Initialisation of MMG3D MAXIMUM MEMORY AUTHORIZED (MB) 7970 INFO: before call MMG3D_doSol in adapt_mmg3d, setting mesh->info.optim=1 INFO: after call MMG3D_doSol in adapt_mmg3d, setting mesh->info.optim=0 INFO: metric info: max = 1.874758 min = 1.701226 avg = 1.799191

Thanks for your advice, Jens

jeandodo avatar Jan 27 '23 16:01 jeandodo