ParMETIS_V3_PartMeshKway still someproblem with fortran

Hello,

I am patitioning a mesh using ParMETIS_V3_PartMeshKway inside a c++ and inside a fortran90 program. To have exactly same initialization in c++ and fortran90, I am using C convention even with fortran (my tables start at 0). With c++ everything works nicely. But this is not the case with fortran 90 and to trace the problem I add some pintf commands in procedure ParMETIS_V3_PartMeshKway localized in file mmetis.c.

More precisely, in fortran, it fails at line :

SetUpCtrl(&ctrl, *nparts, (options[0] == 1 ? options[PMV3_OPTION_DBGLVL] : 0), *comm);

*comm was initialized in fortran program as

integer :: comm(0)

and the error message I have is :

[santafe.onera:31060] *** An error occurred in MPI_Comm_dup
[santafe.onera:31060] *** on communicator MPI_COMM_WORLD
[santafe.onera:31060] *** MPI_ERR_COMM: invalid communicator
[santafe.onera:31060] *** MPI_ERRORS_ARE_FATAL (goodbye)
[santafe.onera:31061] *** An error occurred in MPI_Comm_dup
[santafe.onera:31061] *** on communicator MPI_COMM_WORLD
[santafe.onera:31061] *** MPI_ERR_COMM: invalid communicator
[santafe.onera:31061] *** MPI_ERRORS_ARE_FATAL (goodbye)

if I declare

integer :: comm

I do not pass a pointer anymore but the value and then the error message is different this time even if the error occurs at same line

[santafe:31141] *** Process received signal ***
[santafe:31141] Signal: Segmentation fault (11)
[santafe:31141] Signal code: Address not mapped (1)
[santafe:31141] Failing at address: 0x3000000b3
[santafe:31141] *** End of error message ***
mpirun noticed that job rank 0 with PID 31140 on node santafe.onera exited on signal 11 (Segmentation fault).
1 additional process aborted (not shown)

I wonder if there is a solution and if people have already use parmetis in fortran90 program ?

RE: Sample F90 code

May I get a sample F90 code to call ParMETIS_V3_PartMeshKway function with compile option using gfortran?

RE: The error I face seem to be

The error I face seem to be mentioned here :

http://glaros.dtc.umn.edu/flyspray/task/16

RE: ParMETIS_V3_PartMeshKway still someproblem with fortran

I think you are doing something illegal in Fortran90.
Try do declare
integer :: comm(0:0)
instead of
integer :: comm(0)

Massimo

RE: I agree, comm(0:0) is better

I agree, comm(0:0) is better but it doesn't change anything, the compiler seems to do same.

There is a difference between

interger :: comm or integer :: com(0:0)

and

MPI_Comm comm;

RE: it works, but you need to convert MPI_Fint to MPI_Comm before

it works, but I had to modify the routine ParMETIS_V3_PartMeshKway as mentionned by Dana Hammond.
Without this, parmetis can't be linked under openmpi or modern distribution of MPI with fortran because of communicators.

void ParMETIS_V3_PartMeshKway(
idxtype *elmdist,
idxtype *eptr,
idxtype *eind,
idxtype *elmwgt,
int *wgtflag,
int *numflag,
int *ncon,
int *ncommonnodes,
int *nparts,
float *tpwgts,
float *ubvec,
int *options,
int *edgecut,
idxtype *part,
MPI_Fint *commF
)
{

MPI_Comm comm_world;
MPI_Comm *comm;

comm_world = MPI_Comm_f2c((MPI_Fint)*commF);
comm = &comm_world;

}

Update :

better than chaniging parmetis sources, it is possible to bind parmetis and fortran source by a specific c source file where you are going to realise the comunicator translation.

christophe

RE: ParMETIS_V3_PartMeshKway_Fortran may be added in mmetis.c file

May I add the following routine in mmetis.c file to give the support for both C and Fortran interfaces? Or Fortran programmer should write down a wrapper function in c for above mentioned conversion.

void ParMETIS_V3_PartMeshKway_Fortran (idxtype *elmdist, idxtype *eptr, idxtype *eind, idxtype *elmwgt,
int *wgtflag, int *numflag, int *ncon, int *ncommonnodes, int *nparts,
float *tpwgts, float *ubvec, int *options, int *edgecut, idxtype *part,
MPI_Comm *commF)
{

MPI_Comm comm_world;
MPI_Comm *comm;

comm_world = MPI_Comm_f2c((MPI_Fint)*commF);
comm = &comm_world;

ParMETIS_V3_PartMeshKway (elmdist, eptr, eind, elmwgt, wgtflag, numflag, ncon, ncommonnodes, nparts, tpwgts, ubvec, options, edgecut, part, comm);

}