Most of the code developed within my group is written in Matlab and there are specific tasks such as solving a dense linear system very computationally intensive. My idea was to write the Matlab Mex file in C to wrap around the needed functions in ScaLAPACK, and present the Matlab interface to other group members.
Currently, I was able to write a mex file that contains calls to MPI_Init()/MPI_Finalize(). A TestHarness.m was created to call this mex file, and the TestHarness was invoked on the command line like
- Code: Select all
mpiexec -np 10 matlab -nodesktop -nosplash -nojvm -r TestHarness
However, the Segmentation Violation was detected when I embedded the Cblacs_gridinit() in the mex function. A portion of the mex file contains the following lines
- Code: Select all
MPI_Init(0, 0);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank_mpi);
MPI_Comm_size(MPI_COMM_WORLD, &nprocs_mpi);
printf("number of processes %d and my rank %d\n", nprocs_mpi, myrank_mpi);
npcol = 2; nprow = 2;
if (nprow*npcol > nprocs_mpi) {
MPI_Finalize(); exit(1);
}
/* Initilize the processor grid */
Cblacs_pinfo(&iam, &nprocs); /* executed OK */
Cblacs_get(-1, 0, &ictxt); /* executed OK */
Cblacs_gridinit(&ictxt, "Col-major", nprow, npcol); /* throw segmentation violation error in Matlab */
Cblacs_gridinfo(ictxt, &nprow, &npcol, &myrow, &mycol); /* not executed */
I have not identified anyone on the internet with a report of mex wrapper of Matlab. My question is: is this idea valid/possible or is there any more appropriate solution? My second question is: what could possibly be the cause of the segmentation violation?
Any comment is welcome. Thank you for reading this post.
Kevin

