Index: /issm/trunk/externalpackages/scotch/gmap_mex.c
===================================================================
--- /issm/trunk/externalpackages/scotch/gmap_mex.c	(revision 3616)
+++ /issm/trunk/externalpackages/scotch/gmap_mex.c	(revision 3617)
@@ -1,111 +1,55 @@
-/* Copyright 2004,2007,2008 ENSEIRB, INRIA & CNRS
-**
-** This file is part of the Scotch software package for static mapping,
-** graph partitioning and sparse matrix ordering.
-**
-** This software is governed by the CeCILL-C license under French law
-** and abiding by the rules of distribution of free software. You can
-** use, modify and/or redistribute the software under the terms of the
-** CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
-** URL: "http://www.cecill.info".
-** 
-** As a counterpart to the access to the source code and rights to copy,
-** modify and redistribute granted by the license, users are provided
-** only with a limited warranty and the software's author, the holder of
-** the economic rights, and the successive licensors have only limited
-** liability.
-** 
-** In this respect, the user's attention is drawn to the risks associated
-** with loading, using, modifying and/or developing or reproducing the
-** software by the user in light of its specific status of free software,
-** that may mean that it is complicated to manipulate, and that also
-** therefore means that it is reserved for developers and experienced
-** professionals having in-depth computer knowledge. Users are therefore
-** encouraged to load and test the software's suitability as regards
-** their requirements in conditions enabling the security of their
-** systems and/or data to be ensured and, more generally, to use and
-** operate it in the same conditions as regards security.
-** 
-** The fact that you are presently reading this means that you have had
-** knowledge of the CeCILL-C license and that you accept its terms.
-*/
-/************************************************************/
-/**                                                        **/
-/**   NAME       : gmap.c                                  **/
-/**                                                        **/
-/**   AUTHOR     : Francois PELLEGRINI                     **/
-/**                                                        **/
-/**   FUNCTION   : Part of a graph mapping software.       **/
-/**                This module contains the main function. **/
-/**                                                        **/
-/**   DATES      : # Version 0.0  : from : 05 jan 1993     **/
-/**                                 to     12 may 1993     **/
-/**                # Version 1.1  : from : 15 oct 1993     **/
-/**                                 to     15 oct 1993     **/
-/**                # Version 1.3  : from : 06 apr 1994     **/
-/**                                 to     18 may 1994     **/
-/**                # Version 2.0  : from : 06 jun 1994     **/
-/**                                 to     17 nov 1994     **/
-/**                # Version 2.1  : from : 07 apr 1995     **/
-/**                                 to     18 jun 1995     **/
-/**                # Version 3.0  : from : 01 jul 1995     **/
-/**                                 to     02 oct 1995     **/
-/**                # Version 3.1  : from : 07 nov 1995     **/
-/**                                 to     25 apr 1996     **/
-/**                # Version 3.2  : from : 24 sep 1996     **/
-/**                                 to     26 may 1998     **/
-/**                # Version 3.3  : from : 19 oct 1998     **/
-/**                                 to   : 30 mar 1999     **/
-/**                # Version 3.4  : from : 03 feb 2000     **/
-/**                                 to   : 03 feb 2000     **/
-/**                # Version 4.0  : from : 16 jan 2004     **/
-/**                                 to   : 27 dec 2004     **/
-/**                # Version 5.0  : from : 23 dec 2007     **/
-/**                                 to   : 18 jun 2008     **/
-/**                                                        **/
-/************************************************************/
-
-/*
-**  The defines and includes.
-*/
-
-#define GMAP
-
-#include "module.h"
-#include "common.h"
-#include "scotch.h"
-#include "gmap.h"
-
-/*
-**  The static variables.
-*/
-
-static int                  C_partNbr = 2;        /* Default number of parts     */
-static int                  C_paraNum = 0;        /* Number of parameters        */
-static int                  C_paraNbr = 0;        /* No parameters for mapping   */
-static int                  C_fileNum = 0;        /* Number of file in arg list  */
-static int                  C_fileNbr = 4;        /* Number of files for mapping */
-static File                 C_fileTab[C_FILENBR] = { /* File array               */
-                              { "-", NULL, "r" },
-                              { "-", NULL, "r" },
-                              { "-", NULL, "w" },
-                              { "-", NULL, "w" } };
-
-static const char *         C_usageList[] = {     /* Usage */
-  "gmap [<input source file> [<input target file> [<output mapping file> [<output log file>]]]] <options>",
-  "gpart [<nparts>] [<input source file> [<output mapping file> [<output log file>]]] <options>",
-  "  -h         : Display this help",
-  "  -m<strat>  : Set mapping strategy (see user's manual)",
-  "  -s<obj>    : Force unity weights on <obj>:",
-  "                 e  : edges",
-  "                 v  : vertices",
-  "  -V         : Print program version and copyright",
-  "  -v<verb>   : Set verbose mode to <verb>:",
-  "                 m  : mapping information",
-  "                 s  : strategy information",
-  "                 t  : timing information",
-  "",
-  "See default strategy with option '-vs'",
-  NULL };
+
+#define THISFUNCTION "Gmap"
+
+/*  Gmap structures and prototypes  */
+
+#ifdef MATLAB
+		#include "mat.h"
+		#include "mex.h"
+		#include "matrix.h"
+
+		#define printf mexPrintf
+		#define fprintf(file,...) (file == stdout || file == stderr ? mexPrintf(__VA_ARGS__) : fprintf(file,__VA_ARGS__))
+		#define malloc mxMalloc
+		#define calloc mxCalloc
+		#define realloc mxRealloc
+		#define free mxFree
+		#define exit(status) mexErrMsgTxt("exit=" #status)
+#endif
+
+void GmapUsage( void );
+
+
+/* Input Arguments */
+
+#define ADJMAT_IN  prhs[0]
+#define VERTLB_IN  prhs[1]
+#define VERTWT_IN  prhs[2]
+#define EDGEWT_IN  prhs[3]
+#define ARCHTYP_IN prhs[4]
+#define ARCHPAR_IN prhs[5]
+#define REQ_ARGS     6
+
+/* Output Arguments */
+
+#define RETURN_OUT plhs[0]
+#define MAPTAB_OUT plhs[1]
+
+
+int
+gmapx (
+	int                 (**pmaptabi)[2],
+	int                 argcm,
+	char                *argvm[],
+	int                 nvi,
+	int                 ne2i,
+	int                 *ir,
+	int                 *jc,
+	int                 *vli,
+	int                 *vwi,
+	int                 *ewi,
+	char                archtyp[],
+	int                 nai,
+	int                 *api);
 
 /******************************/
@@ -116,352 +60,208 @@
 
 void mexFunction( int nlhs,
-                  mxArray *plhs[],
-                  int nrhs,
-                  const mxArray *prhs[] )
+				  mxArray *plhs[],
+				  int nrhs,
+				  const mxArray *prhs[] )
 {
-  int                         argcm;
-  char                        argvm[21][257];
-  SCOTCH_Graph        grafdat;                    /* Source graph            */
-  SCOTCH_Num          grafflag;                   /* Source graph properties */
-  SCOTCH_Arch         archdat;                    /* Target architecture     */
-  SCOTCH_Strat        stradat;                    /* Mapping strategy        */
-  SCOTCH_Mapping      mapdat;                     /* Mapping data            */
-  Clock               runtime[2];                 /* Timing variables        */
-  SCOTCH_Num          nvert =0;
-  SCOTCH_Num          nedge2=0;
-  SCOTCH_Num*         adjir  =NULL;
-  SCOTCH_Num*         adjjc  =NULL;
-  mwIndex             *ir=NULL,*jc=NULL;
-  double              *vld=NULL,*vwd=NULL,*ewd=NULL,*apd=NULL;
-  SCOTCH_Num*         vertlab=NULL;
-  SCOTCH_Num*         vertwgt=NULL;
-  SCOTCH_Num*         edgewgt=NULL;
-  char                archtyp[256];
-  SCOTCH_Num          napar =0;
-  SCOTCH_Num*         archpar=NULL;
-  SCOTCH_Num          (*maptab)[2]=NULL;
-  double*             maptabm;
-  int                 flagval;
-  int                 i,j,k;
-
-/*  check static variables from previous runs  */
-
-  if (C_paraNum > 0 || C_fileNum > 0)
-    mexErrMsgTxt("gmap_mex still in memory -- clear gmap_mex and try again.\n");
-
-/*  load matlab argument list  */
-
-  if (!mxIsNumeric(prhs[0]) || (!mxIsEmpty(prhs[0]) && !mxIsSparse(prhs[0]))) {
-    mexPrintf("%s -- Adjacency matrix must be numeric and sparse.\n","gmap_mex");
-    mexErrMsgTxt(" ");
-  }
-  else {
-    nvert =mxGetM(prhs[0]);
-    nedge2=mxGetNzmax(prhs[0]);
-    ir    =mxGetIr(prhs[0]);
-    adjir = (SCOTCH_Num *) malloc(mxGetNzmax(prhs[0])*sizeof(SCOTCH_Num));
-    for (i=0; i<mxGetNzmax(prhs[0]); i++)
-      adjir[i]=(SCOTCH_Num)ir[i];
-    jc    =mxGetJc(prhs[0]);
-    adjjc = (SCOTCH_Num *) malloc((mxGetN(prhs[0])+1)*sizeof(SCOTCH_Num));
-    for (i=0; i<(mxGetN(prhs[0])+1); i++)
-      adjjc[i]=(SCOTCH_Num)jc[i];
-    mexPrintf("%s -- Adjacency matrix is of size %d by %d with %d non-zeroes.\n",
-              "gmap_mex",mxGetM(prhs[0]),mxGetN(prhs[0]),mxGetNzmax(prhs[0]));
-  }
-
-  if (!mxIsNumeric(prhs[1])) {
-    mexPrintf("%s -- Vertex label vector must be numeric.\n","gmap_mex");
-    mexErrMsgTxt(" ");
-  }
-  else {
-    vld=mxGetPr(prhs[1]);
-    vertlab = (SCOTCH_Num *) malloc(mxGetM(prhs[1])*mxGetN(prhs[1])*sizeof(SCOTCH_Num));
-    for (i=0; i<mxGetM(prhs[1])*mxGetN(prhs[1]); i++)
-      vertlab[i]=(SCOTCH_Num)vld[i];
-    mexPrintf("%s -- Vertex label vector is of size %d by %d.\n",
-              "gmap_mex",mxGetM(prhs[1]),mxGetN(prhs[1]));
-  }
-
-  if (!mxIsNumeric(prhs[2])) {
-    mexPrintf("%s -- Vertex weight vector must be numeric.\n","gmap_mex");
-    mexErrMsgTxt(" ");
-  }
-  else {
-    vwd=mxGetPr(prhs[2]);
-    vertwgt = (SCOTCH_Num *) malloc(mxGetM(prhs[2])*mxGetN(prhs[2])*sizeof(SCOTCH_Num));
-    for (i=0; i<mxGetM(prhs[2])*mxGetN(prhs[2]); i++)
-      vertwgt[i]=(SCOTCH_Num)vwd[i];
-    mexPrintf("%s -- Vertex weight vector is of size %d by %d.\n",
-              "gmap_mex",mxGetM(prhs[2]),mxGetN(prhs[2]));
-  }
-
-  if (!mxIsNumeric(prhs[3]) || (!mxIsEmpty(prhs[3]) && !mxIsSparse(prhs[3]))) {
-    mexPrintf("%s -- Edge weight matrix must be numeric and sparse.\n","gmap_mex");
-    mexErrMsgTxt(" ");
-  }
-  else {
-    ewd=mxGetPr(prhs[3]);
-    edgewgt = (SCOTCH_Num *) malloc(mxGetM(prhs[3])*sizeof(SCOTCH_Num));
-    for (i=0; i<mxGetNzmax(prhs[3]); i++)
-      edgewgt[i]=(SCOTCH_Num)ewd[i];
-    mexPrintf("%s -- Edge weight matrix is of size %d by %d with %d non-zeroes.\n",
-              "gmap_mex",mxGetM(prhs[3]),mxGetN(prhs[3]),mxGetNzmax(prhs[3]));
-  }
-
-  if (!mxIsChar(prhs[4])) {
-    mexPrintf("%s -- Architecture type must be character.\n","gmap_mex");
-    mexErrMsgTxt(" ");
-  }
-  else {
-    mxGetString(prhs[4],archtyp,255);
-    mexPrintf("%s -- Architecture type is \"%s\".\n",
-              "gmap_mex",archtyp);
-    archtyp[255] = '\0';
-  }
-
-  if (!mxIsNumeric(prhs[5])) {
-    mexPrintf("%s -- Architecture parameter vector must be numeric.\n","gmap_mex");
-    mexErrMsgTxt(" ");
-  }
-  else {
-    napar =mxGetM(prhs[5])*mxGetN(prhs[5]);
-    apd=mxGetPr(prhs[5]);
-    archpar = (SCOTCH_Num *) malloc(mxGetM(prhs[5])*mxGetN(prhs[5])*sizeof(SCOTCH_Num));
-    for (i=0; i<mxGetM(prhs[5])*mxGetN(prhs[5]); i++)
-      archpar[i]=(SCOTCH_Num)apd[i];
-    mexPrintf("%s -- Architecture parameter vector is of size %d by %d.\n",
-              "gmap_mex",mxGetM(prhs[5]),mxGetN(prhs[5]));
-  }
-
-  argcm=nrhs+1-6;
-  mexPrintf("argcm=%d\n",argcm);
-  strcpy(argvm[0],"gmap");
-  for (i=6; i<nrhs; i++)
-    if (!mxIsChar(prhs[i])) {
-      mexPrintf("%s -- prhs[%d] must be character.\n","gmap_mex",i);
-      mexErrMsgTxt(" ");
-    }
-    else
-      mxGetString(prhs[i],argvm[i-5],256);
-  for (i=0; i<argcm; i++)
-    mexPrintf("argvm[%d]=\"%s\"\n",i,argvm[i]);
-
-  flagval = C_FLAGNONE;                           /* Default behavior */
-  i = strlen (argvm[0]);
-  if ((i >= 5) && (strncmp (argvm[0] + i - 5, "gpart", 5) == 0)) {
-    flagval |= C_FLAGPART;
-    C_paraNbr = 1;                                /* One more parameter       */
-    C_fileNbr = 3;                                /* One less file to provide */
-    errorProg ("gpart");
-  }
-  else
-    errorProg ("gmap");
-
-  intRandInit ();
-
-  if ((argcm >= 2) && (argvm[1][0] == '?')) {       /* If need for help */
-    usagePrint (stdout, C_usageList);
-/*    return     (0); */
-    plhs[0]=mxCreateDoubleMatrix(1, 1, mxREAL);
-    *mxGetPr(plhs[0])=0.;
+	int     argcm;
+	char    **argvm=NULL;
+	int     nvert =0,nedge2=0,napar =0;
+	mwIndex *ir=NULL,*jc=NULL;
+	int     *adjir=NULL,*adjjc=NULL;
+	double  *vld=NULL,*vwd=NULL,*ewd=NULL,*apd=NULL;
+	int     *vli=NULL,*vwi=NULL,*ewi=NULL,*api=NULL;
+	char    *archtyp=NULL;
+	int     (*maptabi)[2]=NULL;
+	double* maptabd=NULL;
+	int     i,j,k,ierr;
+
+	/* Check for proper number of arguments */
+   
+	if      (nrhs == 0 && nlhs == 0) {
+		GmapUsage();
+		return;
+	}
+	else if (nrhs <  6 || nlhs >  2) {
+		GmapUsage();
+		mexErrMsgTxt(" ");
+	}
+
+/*  load matlab argument list and convert to integer (note that converting here
+	and in the x-layer is inefficient, but it makes the x-layer more general)  */
+
+	if (!mxIsNumeric(ADJMAT_IN) || (!mxIsEmpty(ADJMAT_IN) && !mxIsSparse(ADJMAT_IN))) {
+		mexPrintf("%s -- Adjacency matrix must be numeric and sparse.\n",THISFUNCTION);
+		mexErrMsgTxt(" ");
+	}
+	else {
+		nvert =mxGetM(ADJMAT_IN);
+		nedge2=mxGetNzmax(ADJMAT_IN);
+		if (mxGetNzmax(ADJMAT_IN)) {
+			ir    =mxGetIr(ADJMAT_IN);
+			adjir = (int *) malloc(mxGetNzmax(ADJMAT_IN)*sizeof(int));
+			for (i=0; i<mxGetNzmax(ADJMAT_IN); i++)
+				adjir[i]=(int)ir[i];
+		}
+		if (mxGetN(ADJMAT_IN)) {
+			jc    =mxGetJc(ADJMAT_IN);
+			adjjc = (int *) malloc((mxGetN(ADJMAT_IN)+1)*sizeof(int));
+			for (i=0; i<(mxGetN(ADJMAT_IN)+1); i++)
+				adjjc[i]=(int)jc[i];
+		}
+		mexPrintf("%s -- Adjacency matrix is of size %d by %d with %d non-zeroes.\n",
+				  THISFUNCTION,mxGetM(ADJMAT_IN),mxGetN(ADJMAT_IN),mxGetNzmax(ADJMAT_IN));
+	}
+
+	if (!mxIsNumeric(VERTLB_IN)) {
+		mexPrintf("%s -- Vertex label vector must be numeric.\n",THISFUNCTION);
+		mexErrMsgTxt(" ");
+	}
+	else {
+		if (mxGetM(VERTLB_IN)*mxGetN(VERTLB_IN)) {
+			vld=mxGetPr(VERTLB_IN);
+			vli = (int *) malloc(mxGetM(VERTLB_IN)*mxGetN(VERTLB_IN)*sizeof(int));
+			for (i=0; i<mxGetM(VERTLB_IN)*mxGetN(VERTLB_IN); i++)
+				vli[i]=(int)vld[i];
+		}
+		mexPrintf("%s -- Vertex label vector is of size %d by %d.\n",
+				  THISFUNCTION,mxGetM(VERTLB_IN),mxGetN(VERTLB_IN));
+	}
+
+	if (!mxIsNumeric(VERTWT_IN)) {
+		mexPrintf("%s -- Vertex weight vector must be numeric.\n",THISFUNCTION);
+		mexErrMsgTxt(" ");
+	}
+	else {
+		if (mxGetM(VERTWT_IN)*mxGetN(VERTWT_IN)) {
+			vwd=mxGetPr(VERTWT_IN);
+			vwi = (int *) malloc(mxGetM(VERTWT_IN)*mxGetN(VERTWT_IN)*sizeof(int));
+			for (i=0; i<mxGetM(VERTWT_IN)*mxGetN(VERTWT_IN); i++)
+				vwi[i]=(int)vwd[i];
+		}
+		mexPrintf("%s -- Vertex weight vector is of size %d by %d.\n",
+				  THISFUNCTION,mxGetM(VERTWT_IN),mxGetN(VERTWT_IN));
+	}
+
+	if (!mxIsNumeric(EDGEWT_IN) || (!mxIsEmpty(EDGEWT_IN) && !mxIsSparse(EDGEWT_IN))) {
+		mexPrintf("%s -- Edge weight matrix must be numeric and sparse.\n",THISFUNCTION);
+		mexErrMsgTxt(" ");
+	}
+	else {
+		if (mxGetM(EDGEWT_IN)) {
+			ewd=mxGetPr(EDGEWT_IN);
+			ewi = (int *) malloc(mxGetM(EDGEWT_IN)*sizeof(int));
+			for (i=0; i<mxGetNzmax(EDGEWT_IN); i++)
+				ewi[i]=(int)ewd[i];
+		}
+		mexPrintf("%s -- Edge weight matrix is of size %d by %d with %d non-zeroes.\n",
+				  THISFUNCTION,mxGetM(EDGEWT_IN),mxGetN(EDGEWT_IN),mxGetNzmax(EDGEWT_IN));
+	}
+
+	if (!mxIsChar(ARCHTYP_IN)) {
+		mexPrintf("%s -- Architecture type must be character.\n",THISFUNCTION);
+		mexErrMsgTxt(" ");
+	}
+	else {
+		if (mxGetM(ARCHTYP_IN)*mxGetN(ARCHTYP_IN)) {
+			archtyp = (char *) calloc(mxGetM(ARCHTYP_IN)*mxGetN(ARCHTYP_IN)+1,sizeof(char));
+			mxGetString(ARCHTYP_IN,archtyp,mxGetM(ARCHTYP_IN)*mxGetN(ARCHTYP_IN)+1);
+		}
+		mexPrintf("%s -- Architecture type is \"%s\".\n",
+				  THISFUNCTION,archtyp);
+	}
+
+	if (!mxIsNumeric(ARCHPAR_IN)) {
+		mexPrintf("%s -- Architecture parameter vector must be numeric.\n",THISFUNCTION);
+		mexErrMsgTxt(" ");
+	}
+	else {
+		napar =mxGetM(ARCHPAR_IN)*mxGetN(ARCHPAR_IN);
+		if (mxGetM(ARCHPAR_IN)*mxGetN(ARCHPAR_IN)) {
+			apd=mxGetPr(ARCHPAR_IN);
+			api = (int *) malloc(mxGetM(ARCHPAR_IN)*mxGetN(ARCHPAR_IN)*sizeof(int));
+			for (i=0; i<mxGetM(ARCHPAR_IN)*mxGetN(ARCHPAR_IN); i++)
+				api[i]=(int)apd[i];
+		}
+		mexPrintf("%s -- Architecture parameter vector is of size %d by %d.\n",
+				  THISFUNCTION,mxGetM(ARCHPAR_IN),mxGetN(ARCHPAR_IN));
+	}
+
+	argcm=nrhs+1-REQ_ARGS;
+	mexPrintf("argcm=%d\n",argcm);
+	argvm = (char **) malloc(argcm*sizeof(char *));
+	argvm[0] = (char *) calloc(4+1,sizeof(char));
+	strcpy(argvm[0],"gmap");
+	for (i=REQ_ARGS; i<nrhs; i++)
+		if (!mxIsChar(prhs[i])) {
+			mexPrintf("%s -- prhs[%d] must be character.\n",THISFUNCTION,i);
+			mexErrMsgTxt(" ");
+		}
+		else {
+			argvm[i+1-REQ_ARGS] = (char *) calloc(mxGetM(prhs[i])*mxGetN(prhs[i])+1,sizeof(char));
+			mxGetString(prhs[i],argvm[i+1-REQ_ARGS],mxGetM(prhs[i])*mxGetN(prhs[i])+1);
+		}
+	for (i=0; i<argcm; i++)
+		mexPrintf("argvm[%d]=\"%s\"\n",i,argvm[i]);
+
+	/* Do the actual computations in a subroutine */
+
+	mexPrintf("Gmapx:\n");
+	ierr=gmapx(&maptabi,
+			   argcm,
+			   argvm,
+			   nvert,
+			   nedge2,
+			   adjir,
+			   adjjc,
+			   vli,
+			   vwi,
+			   ewi,
+			   archtyp,
+			   napar,
+			   api);
+	mexPrintf("%s -- Error %d from Gmapx.\n",THISFUNCTION,ierr);
+
+/*  for (i=0; i<nvert; i++)
+		mexPrintf("maptabi[%d][0]=%d, maptabi[%d][1]=%d\n",
+			 	  i,maptabi[i][0],i,maptabi[i][1]); */
+
+	/* Create matrices for the return arguments */
+
+	if (maptabi) {
+		MAPTAB_OUT=mxCreateDoubleMatrix(nvert, 2, mxREAL);
+		maptabd = mxGetPr(MAPTAB_OUT);
+		k=0;
+		for (j=0; j<2; j++)
+			for (i=0; i<nvert; i++)
+				maptabd[k++]=(double)maptabi[i][j];
+		free(maptabi);
+	}
+
+	if (argvm)
+		for (i=argcm-1; i>=0; i--)
+			free(argvm[i]);
+	if (api)     free(api);
+	if (archtyp) free(archtyp);
+	if (ewi)     free(ewi);
+	if (vwi)     free(vwi);
+	if (vli)     free(vli);
+	if (adjjc)   free(adjjc);
+	if (adjir)   free(adjir);
+
+	RETURN_OUT=mxCreateDoubleMatrix(1, 1, mxREAL);
+	*mxGetPr(RETURN_OUT)=ierr;
+
+	return;
+}
+
+void GmapUsage( void )
+{
+
+    mexPrintf("\n");
+    mexPrintf("Usage: [return,maptab]=Gmap_mex(adjmat,vertlb,vertwt,edgewt,archtyp,archpar,\n");
+    mexPrintf("                                Scotch-specific parameters);\n");
+    mexPrintf("\n");
+
     return;
-  }
-
-  grafflag = 0;                                   /* Use vertex and edge weights  */
-  SCOTCH_stratInit (&stradat);                    /* Set default mapping strategy */
-
-  printf("point 0: C_FILENBR=%d, C_fileNbr=%d, C_paraNbr=%d\n",
-         C_FILENBR,C_fileNbr,C_paraNbr);
-  for (i = 0; i < C_FILENBR; i ++)                /* Set default stream pointers */
-    C_fileTab[i].pntr = (C_fileTab[i].mode[0] == 'r') ? stdin : stdout;
-  for (i = 1; i < argcm; i ++) {                   /* Loop for all option codes                        */
-  printf("point 1: i=%d; C_fileNbr=%d, C_fileNum=%d, C_paraNbr=%d, C_paraNum=%d\n",
-         i,C_fileNbr,C_fileNum,C_paraNbr,C_paraNum);
-    if ((argvm[i][0] != '-') || (argvm[i][1] == '\0') || (argvm[i][1] == '.')) { /* If found a file name */
-  printf("point 2: i=%d; C_fileNbr=%d, C_fileNum=%d, C_paraNbr=%d, C_paraNum=%d\n",
-         i,C_fileNbr,C_fileNum,C_paraNbr,C_paraNum);
-      if (C_paraNum < C_paraNbr) {                /* If number of parameters not reached              */
-        if ((C_partNbr = atoi (argvm[i])) < 1)     /* Get the number of parts                          */
-          errorPrint ("main: invalid number of parts (\"%s\")", argvm[i]);
-        C_paraNum ++;
-        continue;                                 /* Process the other parameters */
-      }
-  printf("point 3: i=%d; C_fileNbr=%d, C_fileNum=%d, C_paraNbr=%d, C_paraNum=%d\n",
-         i,C_fileNbr,C_fileNum,C_paraNbr,C_paraNum);
-      if (C_fileNum < C_fileNbr)                  /* A file name has been given */
-        C_fileTab[C_fileNum ++].name = argvm[i];
-      else
-        errorPrint ("main: too many file names given");
-  printf("point 4: i=%d; C_fileNbr=%d, C_fileNum=%d, C_paraNbr=%d, C_paraNum=%d\n",
-         i,C_fileNbr,C_fileNum,C_paraNbr,C_paraNum);
-    }
-    else {                                        /* If found an option name */
-      switch (argvm[i][1]) {
-        case 'H' :                                /* Give the usage message */
-        case 'h' :
-          usagePrint (stdout, C_usageList);
-/*          return     (0); */
-          plhs[0]=mxCreateDoubleMatrix(1, 1, mxREAL);
-          *mxGetPr(plhs[0])=0.;
-          return;
-        case 'M' :
-        case 'm' :
-          SCOTCH_stratExit (&stradat);
-          SCOTCH_stratInit (&stradat);
-          SCOTCH_stratGraphMap (&stradat, &argvm[i][2]);
-          break;
-        case 'S' :
-        case 's' :                                /* Source graph parameters */
-          for (j = 2; argvm[i][j] != '\0'; j ++) {
-            switch (argvm[i][j]) {
-              case 'E' :
-              case 'e' :
-                grafflag |= 2;                    /* Do not load edge weights */
-                break;
-              case 'V' :
-              case 'v' :
-                grafflag |= 1;                    /* Do not load vertex weights */
-                break;
-              default :
-                errorPrint ("main: invalid source graph option (\"%c\")", argvm[i][j]);
-            }
-          }
-          break;
-        case 'V' :
-          fprintf (stderr, "gmap/gpart, version %s - F. Pellegrini\n", SCOTCH_VERSION);
-          fprintf (stderr, "Copyright 2004,2007,2008 ENSEIRB, INRIA & CNRS, France\n");
-          fprintf (stderr, "This software is libre/free software under CeCILL-C -- see the user's manual for more information\n");
-/*          return  (0); */
-          plhs[0]=mxCreateDoubleMatrix(1, 1, mxREAL);
-          *mxGetPr(plhs[0])=0.;
-          return;
-        case 'v' :                                /* Output control info */
-          for (j = 2; argvm[i][j] != '\0'; j ++) {
-            switch (argvm[i][j]) {
-              case 'M' :
-              case 'm' :
-                flagval |= C_FLAGVERBMAP;
-                break;
-              case 'S' :
-              case 's' :
-                flagval |= C_FLAGVERBSTR;
-                break;
-              case 'T' :
-              case 't' :
-                flagval |= C_FLAGVERBTIM;
-                break;
-              default :
-                errorPrint ("main: unprocessed parameter \"%c\" in \"%s\"", argvm[i][j], argvm[i]);
-            }
-          }
-          break;
-        default :
-          errorPrint ("main: unprocessed option (\"%s\")", argvm[i]);
-      }
-    }
-  }
-  printf("point 5\n");
-  if ((flagval & C_FLAGPART) != 0) {              /* If program run as the partitioner            */
-    C_fileTab[3].name = C_fileTab[2].name;        /* Put provided file names at their right place */
-    C_fileTab[2].name = C_fileTab[1].name;
-    C_fileTab[1].name = "-";
-  }
-  printf("point 6\n");
-
-  fileBlockOpen (C_fileTab, C_FILENBR);           /* Open all files */
-  for (i=0; i<C_FILENBR; i++)
-    mexPrintf("C_fileTab[%d]: name=\"%s\",pntr=%p,mode=\"%s\"\n",
-              i,C_fileTab[i].name,C_fileTab[i].pntr,C_fileTab[i].mode);
-  printf("point 7\n");
-
-  clockInit  (&runtime[0]);
-  clockStart (&runtime[0]);
-  printf("point 8\n");
-
-  SCOTCH_graphInit (&grafdat);                    /* Create graph structure         */
-  SCOTCH_graphLoad (&grafdat, C_filepntrsrcinp, -1, grafflag, nvert, nedge2, adjir, adjjc, vertlab, vertwgt, edgewgt); /* Read source graph */
-
-  printf("point 9\n");
-  SCOTCH_archInit (&archdat);                     /* Create architecture structure          */
-  if ((flagval & C_FLAGPART) != 0)                /* If program run as the partitioner      */
-    SCOTCH_archCmplt (&archdat, C_partNbr);       /* Create a complete graph of proper size */
-  else
-    SCOTCH_archLoad (&archdat, C_filepntrtgtinp, archtyp, napar, archpar); /* Read target architecture */
-  printf("point 10\n");
-
-  clockStop  (&runtime[0]);                       /* Get input time */
-  clockInit  (&runtime[1]);
-  clockStart (&runtime[1]);
-
-  SCOTCH_graphMapInit    (&grafdat, &mapdat, &archdat, NULL);
-  SCOTCH_graphMapCompute (&grafdat, &mapdat, &stradat); /* Perform mapping */
-  printf("point 11\n");
-
-  clockStop  (&runtime[1]);                       /* Get computation time */
-  clockStart (&runtime[0]);
-
-  SCOTCH_graphMapSave (&nvert, &maptab, &grafdat, &mapdat, C_filepntrmapout); /* Write mapping */
-
-/*  for (i=0; i<nvert; i++)
-    printf("maptab[%d][0]=%d, maptab[%d][1]=%d\n",
-           i,maptab[i][0],i,maptab[i][1]); */
-  if (maptab) {
-    plhs[1]=mxCreateDoubleMatrix(nvert, 2, mxREAL);
-    maptabm = mxGetPr(plhs[1]);
-    k=0;
-    for (j=0; j<2; j++)
-      for (i=0; i<nvert; i++)
-          maptabm[k++]=(double)maptab[i][j];
-    free(maptab);
-  }
-  printf("point 12\n");
-
-  clockStop (&runtime[0]);                        /* Get output time */
-
-  if (flagval & C_FLAGVERBSTR) {
-    fprintf (C_filepntrlogout, "S\tStrat=");
-    SCOTCH_stratSave (&stradat, C_filepntrlogout);
-    putc ('\n', C_filepntrlogout);
-  }
-  printf("point 13\n");
-  if (flagval & C_FLAGVERBTIM) {
-    fprintf (C_filepntrlogout, "T\tMapping\t\t%g\nT\tI/O\t\t%g\nT\tTotal\t\t%g\n",
-             (double) clockVal (&runtime[1]),
-             (double) clockVal (&runtime[0]),
-             (double) clockVal (&runtime[0]) +
-             (double) clockVal (&runtime[1]));
-  }
-  printf("point 14\n");
-  if (flagval & C_FLAGVERBMAP)
-    SCOTCH_graphMapView (&grafdat, &mapdat, C_filepntrlogout);
-  printf("point 15\n");
-
-  fileBlockClose (C_fileTab, C_FILENBR);          /* Always close explicitely to end eventual (un)compression tasks */
-
-  printf("point 16\n");
-  SCOTCH_graphMapExit (&grafdat, &mapdat);
-  printf("point 16a\n");
-  SCOTCH_graphExit    (&grafdat);
-  printf("point 16b\n");
-  SCOTCH_stratExit    (&stradat);
-  printf("point 16c\n");
-  SCOTCH_archExit     (&archdat);
-  printf("point 17\n");
-
-  if (archpar) free(archpar);
-  if (edgewgt) free(edgewgt);
-  if (vertwgt) free(vertwgt);
-  if (vertlab) free(vertlab);
-  if (adjjc) free(adjjc);
-  if (adjir) free(adjir);
-
-#ifdef COMMON_PTHREAD
-  pthread_exit ((void *) 0);                      /* Allow potential (un)compression tasks to complete */
-#endif /* COMMON_PTHREAD */
-  printf("point 18\n");
-/*  return (0); */
-  plhs[0]=mxCreateDoubleMatrix(1, 1, mxREAL);
-  *mxGetPr(plhs[0])=0.;
-  return;
 }
+
Index: /issm/trunk/externalpackages/scotch/gmapx.c
===================================================================
--- /issm/trunk/externalpackages/scotch/gmapx.c	(revision 3617)
+++ /issm/trunk/externalpackages/scotch/gmapx.c	(revision 3617)
@@ -0,0 +1,408 @@
+/* Copyright 2004,2007,2008 ENSEIRB, INRIA & CNRS
+**
+** This file is part of the Scotch software package for static mapping,
+** graph partitioning and sparse matrix ordering.
+**
+** This software is governed by the CeCILL-C license under French law
+** and abiding by the rules of distribution of free software. You can
+** use, modify and/or redistribute the software under the terms of the
+** CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
+** URL: "http://www.cecill.info".
+** 
+** As a counterpart to the access to the source code and rights to copy,
+** modify and redistribute granted by the license, users are provided
+** only with a limited warranty and the software's author, the holder of
+** the economic rights, and the successive licensors have only limited
+** liability.
+** 
+** In this respect, the user's attention is drawn to the risks associated
+** with loading, using, modifying and/or developing or reproducing the
+** software by the user in light of its specific status of free software,
+** that may mean that it is complicated to manipulate, and that also
+** therefore means that it is reserved for developers and experienced
+** professionals having in-depth computer knowledge. Users are therefore
+** encouraged to load and test the software's suitability as regards
+** their requirements in conditions enabling the security of their
+** systems and/or data to be ensured and, more generally, to use and
+** operate it in the same conditions as regards security.
+** 
+** The fact that you are presently reading this means that you have had
+** knowledge of the CeCILL-C license and that you accept its terms.
+*/
+/************************************************************/
+/**                                                        **/
+/**   NAME       : gmap.c                                  **/
+/**                                                        **/
+/**   AUTHOR     : Francois PELLEGRINI                     **/
+/**                                                        **/
+/**   FUNCTION   : Part of a graph mapping software.       **/
+/**                This module contains the main function. **/
+/**                                                        **/
+/**   DATES      : # Version 0.0  : from : 05 jan 1993     **/
+/**                                 to     12 may 1993     **/
+/**                # Version 1.1  : from : 15 oct 1993     **/
+/**                                 to     15 oct 1993     **/
+/**                # Version 1.3  : from : 06 apr 1994     **/
+/**                                 to     18 may 1994     **/
+/**                # Version 2.0  : from : 06 jun 1994     **/
+/**                                 to     17 nov 1994     **/
+/**                # Version 2.1  : from : 07 apr 1995     **/
+/**                                 to     18 jun 1995     **/
+/**                # Version 3.0  : from : 01 jul 1995     **/
+/**                                 to     02 oct 1995     **/
+/**                # Version 3.1  : from : 07 nov 1995     **/
+/**                                 to     25 apr 1996     **/
+/**                # Version 3.2  : from : 24 sep 1996     **/
+/**                                 to     26 may 1998     **/
+/**                # Version 3.3  : from : 19 oct 1998     **/
+/**                                 to   : 30 mar 1999     **/
+/**                # Version 3.4  : from : 03 feb 2000     **/
+/**                                 to   : 03 feb 2000     **/
+/**                # Version 4.0  : from : 16 jan 2004     **/
+/**                                 to   : 27 dec 2004     **/
+/**                # Version 5.0  : from : 23 dec 2007     **/
+/**                                 to   : 18 jun 2008     **/
+/**                                                        **/
+/************************************************************/
+
+/*
+**  The defines and includes.
+*/
+
+#define GMAP
+
+#include "module.h"
+#include "common.h"
+#include "scotch.h"
+#include "gmap.h"
+
+/*
+**  The static variables.
+*/
+
+static int                  C_partNbr = 2;        /* Default number of parts     */
+static int                  C_paraNum = 0;        /* Number of parameters        */
+static int                  C_paraNbr = 0;        /* No parameters for mapping   */
+static int                  C_fileNum = 0;        /* Number of file in arg list  */
+static int                  C_fileNbr = 4;        /* Number of files for mapping */
+static File                 C_fileTab[C_FILENBR] = { /* File array               */
+                              { "-", NULL, "r" },
+                              { "-", NULL, "r" },
+                              { "-", NULL, "w" },
+                              { "-", NULL, "w" } };
+
+static const char *         C_usageList[] = {     /* Usage */
+  "gmap [<input source file> [<input target file> [<output mapping file> [<output log file>]]]] <options>",
+  "gpart [<nparts>] [<input source file> [<output mapping file> [<output log file>]]] <options>",
+  "  -h         : Display this help",
+  "  -m<strat>  : Set mapping strategy (see user's manual)",
+  "  -s<obj>    : Force unity weights on <obj>:",
+  "                 e  : edges",
+  "                 v  : vertices",
+  "  -V         : Print program version and copyright",
+  "  -v<verb>   : Set verbose mode to <verb>:",
+  "                 m  : mapping information",
+  "                 s  : strategy information",
+  "                 t  : timing information",
+  "",
+  "See default strategy with option '-vs'",
+  NULL };
+
+/******************************/
+/*                            */
+/* This is the main function. */
+/*                            */
+/******************************/
+
+int
+gmapx (
+  int                 (**pmaptabi)[2],
+  int                 argcm,
+  char                *argvm[],
+  int                 nvi,
+  int                 ne2i,
+  int                 *ir,
+  int                 *jc,
+  int                 *vli,
+  int                 *vwi,
+  int                 *ewi,
+  char                archtyp[],
+  int                 nai,
+  int                 *api)
+{
+  SCOTCH_Graph        grafdat;                    /* Source graph            */
+  SCOTCH_Num          grafflag;                   /* Source graph properties */
+  SCOTCH_Arch         archdat;                    /* Target architecture     */
+  SCOTCH_Strat        stradat;                    /* Mapping strategy        */
+  SCOTCH_Mapping      mapdat;                     /* Mapping data            */
+  Clock               runtime[2];                 /* Timing variables        */
+  SCOTCH_Num          nvert =0;
+  SCOTCH_Num          nedge2=0;
+  SCOTCH_Num*         adjir  =NULL;
+  SCOTCH_Num*         adjjc  =NULL;
+  SCOTCH_Num*         vertlab=NULL;
+  SCOTCH_Num*         vertwgt=NULL;
+  SCOTCH_Num*         edgewgt=NULL;
+  SCOTCH_Num          napar =0;
+  SCOTCH_Num*         archpar=NULL;
+  SCOTCH_Num          (*maptab)[2]=NULL;
+  int                 (*maptabi)[2]=NULL;
+  int                 flagval;
+  int                 i,j,k;
+
+/*  check static variables from previous runs  */
+
+  if (C_paraNum > 0 || C_fileNum > 0) {
+    printf("gmap_mex still in memory -- clear gmap_mex and try again.\n");
+    return(1);
+  }
+
+/*  convert input arguments to scotch data types  */
+
+  nvert =(SCOTCH_Num)nvi;
+  nedge2=(SCOTCH_Num)ne2i;
+
+  if (ir && jc) {
+    adjir = (SCOTCH_Num *) malloc(nedge2*sizeof(SCOTCH_Num));
+    for (i=0; i<nedge2; i++)
+      adjir[i]=(SCOTCH_Num)ir[i];
+    adjjc = (SCOTCH_Num *) malloc((nvert+1)*sizeof(SCOTCH_Num));
+    for (i=0; i<(nvert+1); i++)
+      adjjc[i]=(SCOTCH_Num)jc[i];
+  }
+
+  if (vli) {
+    vertlab = (SCOTCH_Num *) malloc(nvert*sizeof(SCOTCH_Num));
+    for (i=0; i<nvert; i++)
+      vertlab[i]=(SCOTCH_Num)vli[i];
+  }
+
+  if (vwi) {
+    vertwgt = (SCOTCH_Num *) malloc(nvert*sizeof(SCOTCH_Num));
+    for (i=0; i<nvert; i++)
+      vertwgt[i]=(SCOTCH_Num)vwi[i];
+  }
+
+  if (ewi) {
+    edgewgt = (SCOTCH_Num *) malloc(nedge2*sizeof(SCOTCH_Num));
+    for (i=0; i<nedge2; i++)
+      edgewgt[i]=(SCOTCH_Num)ewi[i];
+  }
+
+  napar =(SCOTCH_Num)nai;
+
+  if (api) {
+    archpar = (SCOTCH_Num *) malloc(nai*sizeof(SCOTCH_Num));
+    for (i=0; i<nai; i++)
+      archpar[i]=(SCOTCH_Num)api[i];
+  }
+
+/*  start scotch processing  */
+
+  flagval = C_FLAGNONE;                           /* Default behavior */
+  i = strlen (argvm[0]);
+  if ((i >= 5) && (strncmp (argvm[0] + i - 5, "gpart", 5) == 0)) {
+    flagval |= C_FLAGPART;
+    C_paraNbr = 1;                                /* One more parameter       */
+    C_fileNbr = 3;                                /* One less file to provide */
+    errorProg ("gpart");
+  }
+  else
+    errorProg ("gmap");
+
+  intRandInit ();
+
+  if ((argcm >= 2) && (argvm[1][0] == '?')) {       /* If need for help */
+    usagePrint (stdout, C_usageList);
+    return     (0);
+  }
+
+  grafflag = 0;                                   /* Use vertex and edge weights  */
+  SCOTCH_stratInit (&stradat);                    /* Set default mapping strategy */
+
+  printf("point 0: C_FILENBR=%d, C_fileNbr=%d, C_paraNbr=%d\n",
+         C_FILENBR,C_fileNbr,C_paraNbr);
+  for (i = 0; i < C_FILENBR; i ++)                /* Set default stream pointers */
+    C_fileTab[i].pntr = (C_fileTab[i].mode[0] == 'r') ? stdin : stdout;
+  for (i = 1; i < argcm; i ++) {                   /* Loop for all option codes                        */
+  printf("point 1: i=%d; C_fileNbr=%d, C_fileNum=%d, C_paraNbr=%d, C_paraNum=%d\n",
+         i,C_fileNbr,C_fileNum,C_paraNbr,C_paraNum);
+    if ((argvm[i][0] != '-') || (argvm[i][1] == '\0') || (argvm[i][1] == '.')) { /* If found a file name */
+  printf("point 2: i=%d; C_fileNbr=%d, C_fileNum=%d, C_paraNbr=%d, C_paraNum=%d\n",
+         i,C_fileNbr,C_fileNum,C_paraNbr,C_paraNum);
+      if (C_paraNum < C_paraNbr) {                /* If number of parameters not reached              */
+        if ((C_partNbr = atoi (argvm[i])) < 1)     /* Get the number of parts                          */
+          errorPrint ("main: invalid number of parts (\"%s\")", argvm[i]);
+        C_paraNum ++;
+        continue;                                 /* Process the other parameters */
+      }
+  printf("point 3: i=%d; C_fileNbr=%d, C_fileNum=%d, C_paraNbr=%d, C_paraNum=%d\n",
+         i,C_fileNbr,C_fileNum,C_paraNbr,C_paraNum);
+      if (C_fileNum < C_fileNbr)                  /* A file name has been given */
+        C_fileTab[C_fileNum ++].name = argvm[i];
+      else
+        errorPrint ("main: too many file names given");
+  printf("point 4: i=%d; C_fileNbr=%d, C_fileNum=%d, C_paraNbr=%d, C_paraNum=%d\n",
+         i,C_fileNbr,C_fileNum,C_paraNbr,C_paraNum);
+    }
+    else {                                        /* If found an option name */
+      switch (argvm[i][1]) {
+        case 'H' :                                /* Give the usage message */
+        case 'h' :
+          usagePrint (stdout, C_usageList);
+          return     (0);
+        case 'M' :
+        case 'm' :
+          SCOTCH_stratExit (&stradat);
+          SCOTCH_stratInit (&stradat);
+          SCOTCH_stratGraphMap (&stradat, &argvm[i][2]);
+          break;
+        case 'S' :
+        case 's' :                                /* Source graph parameters */
+          for (j = 2; argvm[i][j] != '\0'; j ++) {
+            switch (argvm[i][j]) {
+              case 'E' :
+              case 'e' :
+                grafflag |= 2;                    /* Do not load edge weights */
+                break;
+              case 'V' :
+              case 'v' :
+                grafflag |= 1;                    /* Do not load vertex weights */
+                break;
+              default :
+                errorPrint ("main: invalid source graph option (\"%c\")", argvm[i][j]);
+            }
+          }
+          break;
+        case 'V' :
+          fprintf (stderr, "gmap/gpart, version %s - F. Pellegrini\n", SCOTCH_VERSION);
+          fprintf (stderr, "Copyright 2004,2007,2008 ENSEIRB, INRIA & CNRS, France\n");
+          fprintf (stderr, "This software is libre/free software under CeCILL-C -- see the user's manual for more information\n");
+          return  (0);
+        case 'v' :                                /* Output control info */
+          for (j = 2; argvm[i][j] != '\0'; j ++) {
+            switch (argvm[i][j]) {
+              case 'M' :
+              case 'm' :
+                flagval |= C_FLAGVERBMAP;
+                break;
+              case 'S' :
+              case 's' :
+                flagval |= C_FLAGVERBSTR;
+                break;
+              case 'T' :
+              case 't' :
+                flagval |= C_FLAGVERBTIM;
+                break;
+              default :
+                errorPrint ("main: unprocessed parameter \"%c\" in \"%s\"", argvm[i][j], argvm[i]);
+            }
+          }
+          break;
+        default :
+          errorPrint ("main: unprocessed option (\"%s\")", argvm[i]);
+      }
+    }
+  }
+  printf("point 5\n");
+  if ((flagval & C_FLAGPART) != 0) {              /* If program run as the partitioner            */
+    C_fileTab[3].name = C_fileTab[2].name;        /* Put provided file names at their right place */
+    C_fileTab[2].name = C_fileTab[1].name;
+    C_fileTab[1].name = "-";
+  }
+  printf("point 6\n");
+
+  fileBlockOpen (C_fileTab, C_FILENBR);           /* Open all files */
+  for (i=0; i<C_FILENBR; i++)
+    printf("C_fileTab[%d]: name=\"%s\",pntr=%p,mode=\"%s\"\n",
+           i,C_fileTab[i].name,C_fileTab[i].pntr,C_fileTab[i].mode);
+  printf("point 7\n");
+
+  clockInit  (&runtime[0]);
+  clockStart (&runtime[0]);
+  printf("point 8\n");
+
+  SCOTCH_graphInit (&grafdat);                    /* Create graph structure         */
+  SCOTCH_graphLoad (&grafdat, C_filepntrsrcinp, -1, grafflag, nvert, nedge2, adjir, adjjc, vertlab, vertwgt, edgewgt); /* Read source graph */
+
+  printf("point 9\n");
+  SCOTCH_archInit (&archdat);                     /* Create architecture structure          */
+  if ((flagval & C_FLAGPART) != 0)                /* If program run as the partitioner      */
+    SCOTCH_archCmplt (&archdat, C_partNbr);       /* Create a complete graph of proper size */
+  else
+    SCOTCH_archLoad (&archdat, C_filepntrtgtinp, archtyp, napar, archpar); /* Read target architecture */
+  printf("point 10\n");
+
+  clockStop  (&runtime[0]);                       /* Get input time */
+  clockInit  (&runtime[1]);
+  clockStart (&runtime[1]);
+
+  SCOTCH_graphMapInit    (&grafdat, &mapdat, &archdat, NULL);
+  SCOTCH_graphMapCompute (&grafdat, &mapdat, &stradat); /* Perform mapping */
+  printf("point 11\n");
+
+  clockStop  (&runtime[1]);                       /* Get computation time */
+  clockStart (&runtime[0]);
+
+  SCOTCH_graphMapSave (&nvert, &maptab, &grafdat, &mapdat, C_filepntrmapout); /* Write mapping */
+
+/*  convert output arguments from scotch data types  */
+
+/*  for (i=0; i<nvert; i++)
+    printf("maptab[%d][0]=%d, maptab[%d][1]=%d\n",
+           i,maptab[i][0],i,maptab[i][1]); */
+  if (maptab) {
+    *pmaptabi = (int (*)[2]) malloc(nvert*2*sizeof(int));
+    maptabi  = *pmaptabi;
+    for (j=0; j<2; j++)
+      for (i=0; i<nvert; i++)
+          maptabi[i][j]=(int)maptab[i][j];
+    free(maptab);
+  }
+  printf("point 12\n");
+
+  clockStop (&runtime[0]);                        /* Get output time */
+
+  if (flagval & C_FLAGVERBSTR) {
+    fprintf (C_filepntrlogout, "S\tStrat=");
+    SCOTCH_stratSave (&stradat, C_filepntrlogout);
+    putc ('\n', C_filepntrlogout);
+  }
+  printf("point 13\n");
+  if (flagval & C_FLAGVERBTIM) {
+    fprintf (C_filepntrlogout, "T\tMapping\t\t%g\nT\tI/O\t\t%g\nT\tTotal\t\t%g\n",
+             (double) clockVal (&runtime[1]),
+             (double) clockVal (&runtime[0]),
+             (double) clockVal (&runtime[0]) +
+             (double) clockVal (&runtime[1]));
+  }
+  printf("point 14\n");
+  if (flagval & C_FLAGVERBMAP)
+    SCOTCH_graphMapView (&grafdat, &mapdat, C_filepntrlogout);
+  printf("point 15\n");
+
+  fileBlockClose (C_fileTab, C_FILENBR);          /* Always close explicitely to end eventual (un)compression tasks */
+
+  printf("point 16\n");
+  SCOTCH_graphMapExit (&grafdat, &mapdat);
+  printf("point 16a\n");
+  SCOTCH_graphExit    (&grafdat);
+  printf("point 16b\n");
+  SCOTCH_stratExit    (&stradat);
+  printf("point 16c\n");
+  SCOTCH_archExit     (&archdat);
+  printf("point 17\n");
+
+  if (archpar) free(archpar);
+  if (edgewgt) free(edgewgt);
+  if (vertwgt) free(vertwgt);
+  if (vertlab) free(vertlab);
+  if (adjjc) free(adjjc);
+  if (adjir) free(adjir);
+
+#ifdef COMMON_PTHREAD
+  pthread_exit ((void *) 0);                      /* Allow potential (un)compression tasks to complete */
+#endif /* COMMON_PTHREAD */
+  printf("point 18\n");
+  return (0);
+}
Index: /issm/trunk/externalpackages/scotch/install.sh
===================================================================
--- /issm/trunk/externalpackages/scotch/install.sh	(revision 3616)
+++ /issm/trunk/externalpackages/scotch/install.sh	(revision 3617)
@@ -23,4 +23,5 @@
 cp -p Makefile.inc src/src
 cp -p gmap_mex.c src/src/scotch
+cp -p gmapx.c src/src/scotch
 cd src/src
 # For stand-alone scotch modules:
Index: /issm/trunk/externalpackages/scotch/scotch.patch
===================================================================
--- /issm/trunk/externalpackages/scotch/scotch.patch	(revision 3616)
+++ /issm/trunk/externalpackages/scotch/scotch.patch	(revision 3617)
@@ -4,5 +4,5 @@
 diff -rc src/src/libscotch/arch.c new/src/libscotch/arch.c
 *** src/src/libscotch/arch.c	2008-09-27 07:48:01.000000000 -0700
---- new/src/libscotch/arch.c	2010-03-03 14:06:15.166926170 -0800
+--- new/src/libscotch/arch.c	2010-04-06 15:51:57.485253299 -0700
 ***************
 *** 173,187 ****
@@ -70,5 +70,5 @@
 diff -rc src/src/libscotch/arch_cmplt.c new/src/libscotch/arch_cmplt.c
 *** src/src/libscotch/arch_cmplt.c	2008-05-22 06:44:41.000000000 -0700
---- new/src/libscotch/arch_cmplt.c	2010-03-03 14:06:15.171926172 -0800
+--- new/src/libscotch/arch_cmplt.c	2010-04-06 15:51:57.492253308 -0700
 ***************
 *** 90,99 ****
@@ -122,5 +122,5 @@
 diff -rc src/src/libscotch/arch_cmplt.h new/src/libscotch/arch_cmplt.h
 *** src/src/libscotch/arch_cmplt.h	2008-05-22 06:44:41.000000000 -0700
---- new/src/libscotch/arch_cmplt.h	2010-03-03 14:06:15.178926175 -0800
+--- new/src/libscotch/arch_cmplt.h	2010-04-06 15:51:57.499253316 -0700
 ***************
 *** 87,93 ****
@@ -139,5 +139,5 @@
 diff -rc src/src/libscotch/arch_cmpltw.c new/src/libscotch/arch_cmpltw.c
 *** src/src/libscotch/arch_cmpltw.c	2008-08-27 14:22:22.000000000 -0700
---- new/src/libscotch/arch_cmpltw.c	2010-03-03 14:06:15.184926177 -0800
+--- new/src/libscotch/arch_cmpltw.c	2010-04-06 15:51:57.505253324 -0700
 ***************
 *** 200,211 ****
@@ -211,5 +211,5 @@
 diff -rc src/src/libscotch/arch_cmpltw.h new/src/libscotch/arch_cmpltw.h
 *** src/src/libscotch/arch_cmpltw.h	2008-05-22 06:44:41.000000000 -0700
---- new/src/libscotch/arch_cmpltw.h	2010-03-03 14:06:15.189926179 -0800
+--- new/src/libscotch/arch_cmpltw.h	2010-04-06 15:51:57.512253332 -0700
 ***************
 *** 86,92 ****
@@ -228,5 +228,5 @@
 diff -rc src/src/libscotch/arch_deco.c new/src/libscotch/arch_deco.c
 *** src/src/libscotch/arch_deco.c	2008-09-28 06:35:27.000000000 -0700
---- new/src/libscotch/arch_deco.c	2010-03-03 14:06:15.195926181 -0800
+--- new/src/libscotch/arch_deco.c	2010-04-06 15:51:57.519253341 -0700
 ***************
 *** 211,217 ****
@@ -269,5 +269,5 @@
 diff -rc src/src/libscotch/arch_deco.h new/src/libscotch/arch_deco.h
 *** src/src/libscotch/arch_deco.h	2008-09-27 07:49:46.000000000 -0700
---- new/src/libscotch/arch_deco.h	2010-03-03 14:06:15.201926184 -0800
+--- new/src/libscotch/arch_deco.h	2010-04-06 15:51:57.527253350 -0700
 ***************
 *** 113,119 ****
@@ -286,5 +286,5 @@
 diff -rc src/src/libscotch/arch.h new/src/libscotch/arch.h
 *** src/src/libscotch/arch.h	2009-04-28 08:11:27.000000000 -0700
---- new/src/libscotch/arch.h	2010-03-03 14:06:15.207926186 -0800
+--- new/src/libscotch/arch.h	2010-04-06 15:51:57.533253358 -0700
 ***************
 *** 175,181 ****
@@ -303,5 +303,5 @@
 diff -rc src/src/libscotch/arch_hcub.c new/src/libscotch/arch_hcub.c
 *** src/src/libscotch/arch_hcub.c	2008-05-22 06:44:41.000000000 -0700
---- new/src/libscotch/arch_hcub.c	2010-03-03 14:06:15.213926188 -0800
+--- new/src/libscotch/arch_hcub.c	2010-04-06 15:51:57.540253366 -0700
 ***************
 *** 88,95 ****
@@ -351,5 +351,5 @@
 diff -rc src/src/libscotch/arch_hcub.h new/src/libscotch/arch_hcub.h
 *** src/src/libscotch/arch_hcub.h	2008-05-22 06:44:41.000000000 -0700
---- new/src/libscotch/arch_hcub.h	2010-03-03 14:06:15.219926191 -0800
+--- new/src/libscotch/arch_hcub.h	2010-04-06 15:51:57.547253375 -0700
 ***************
 *** 85,91 ****
@@ -368,5 +368,5 @@
 diff -rc src/src/libscotch/arch_mesh.c new/src/libscotch/arch_mesh.c
 *** src/src/libscotch/arch_mesh.c	2008-05-22 06:44:41.000000000 -0700
---- new/src/libscotch/arch_mesh.c	2010-03-03 14:06:15.225926193 -0800
+--- new/src/libscotch/arch_mesh.c	2010-04-06 15:51:57.555253385 -0700
 ***************
 *** 96,103 ****
@@ -467,5 +467,5 @@
 diff -rc src/src/libscotch/arch_mesh.h new/src/libscotch/arch_mesh.h
 *** src/src/libscotch/arch_mesh.h	2008-05-22 06:44:41.000000000 -0700
---- new/src/libscotch/arch_mesh.h	2010-03-03 14:06:15.232926196 -0800
+--- new/src/libscotch/arch_mesh.h	2010-04-06 15:51:57.561253392 -0700
 ***************
 *** 96,102 ****
@@ -498,5 +498,5 @@
 diff -rc src/src/libscotch/arch_tleaf.c new/src/libscotch/arch_tleaf.c
 *** src/src/libscotch/arch_tleaf.c	2008-05-22 06:44:41.000000000 -0700
---- new/src/libscotch/arch_tleaf.c	2010-03-03 14:06:15.238926198 -0800
+--- new/src/libscotch/arch_tleaf.c	2010-04-06 15:51:57.569253402 -0700
 ***************
 *** 92,99 ****
@@ -556,5 +556,5 @@
 diff -rc src/src/libscotch/arch_tleaf.h new/src/libscotch/arch_tleaf.h
 *** src/src/libscotch/arch_tleaf.h	2008-05-22 06:44:41.000000000 -0700
---- new/src/libscotch/arch_tleaf.h	2010-03-03 14:06:15.244926201 -0800
+--- new/src/libscotch/arch_tleaf.h	2010-04-06 15:51:57.576253410 -0700
 ***************
 *** 89,95 ****
@@ -573,5 +573,5 @@
 diff -rc src/src/libscotch/arch_torus.c new/src/libscotch/arch_torus.c
 *** src/src/libscotch/arch_torus.c	2008-05-22 06:44:41.000000000 -0700
---- new/src/libscotch/arch_torus.c	2010-03-03 14:06:15.251926203 -0800
+--- new/src/libscotch/arch_torus.c	2010-04-06 15:51:57.583253419 -0700
 ***************
 *** 90,97 ****
@@ -672,5 +672,5 @@
 diff -rc src/src/libscotch/arch_torus.h new/src/libscotch/arch_torus.h
 *** src/src/libscotch/arch_torus.h	2008-05-22 06:44:41.000000000 -0700
---- new/src/libscotch/arch_torus.h	2010-03-03 14:06:15.257926206 -0800
+--- new/src/libscotch/arch_torus.h	2010-04-06 15:51:57.590253427 -0700
 ***************
 *** 96,102 ****
@@ -703,5 +703,5 @@
 diff -rc src/src/libscotch/common.c new/src/libscotch/common.c
 *** src/src/libscotch/common.c	2008-05-22 06:44:41.000000000 -0700
---- new/src/libscotch/common.c	2010-03-03 14:06:15.263926208 -0800
+--- new/src/libscotch/common.c	2010-04-06 15:51:57.597253436 -0700
 ***************
 *** 100,106 ****
@@ -722,5 +722,5 @@
 diff -rc src/src/libscotch/common.h new/src/libscotch/common.h
 *** src/src/libscotch/common.h	2009-02-06 14:20:55.000000000 -0800
---- new/src/libscotch/common.h	2010-03-03 14:06:15.270926211 -0800
+--- new/src/libscotch/common.h	2010-04-06 15:51:57.604253444 -0700
 ***************
 *** 66,71 ****
@@ -758,5 +758,5 @@
 diff -rc src/src/libscotch/dummysizes.c new/src/libscotch/dummysizes.c
 *** src/src/libscotch/dummysizes.c	2009-05-09 16:08:02.000000000 -0700
---- new/src/libscotch/dummysizes.c	2010-03-03 14:06:15.276926213 -0800
+--- new/src/libscotch/dummysizes.c	2010-04-06 15:51:57.611253453 -0700
 ***************
 *** 267,271 ****
@@ -771,5 +771,5 @@
 diff -rc src/src/libscotch/graph.c new/src/libscotch/graph.c
 *** src/src/libscotch/graph.c	2008-05-22 06:44:42.000000000 -0700
---- new/src/libscotch/graph.c	2010-03-03 14:06:15.283926216 -0800
+--- new/src/libscotch/graph.c	2010-04-06 15:51:57.618253461 -0700
 ***************
 *** 135,141 ****
@@ -794,5 +794,5 @@
 diff -rc src/src/libscotch/graph.h new/src/libscotch/graph.h
 *** src/src/libscotch/graph.h	2008-06-01 02:49:11.000000000 -0700
---- new/src/libscotch/graph.h	2010-03-03 14:06:15.289926218 -0800
+--- new/src/libscotch/graph.h	2010-04-06 15:51:57.624253469 -0700
 ***************
 *** 159,165 ****
@@ -811,5 +811,5 @@
 diff -rc src/src/libscotch/graph_io.c new/src/libscotch/graph_io.c
 *** src/src/libscotch/graph_io.c	2008-05-22 06:44:42.000000000 -0700
---- new/src/libscotch/graph_io.c	2010-03-03 14:06:15.297926222 -0800
+--- new/src/libscotch/graph_io.c	2010-04-06 15:51:57.632253478 -0700
 ***************
 *** 86,92 ****
@@ -1049,5 +1049,5 @@
 diff -rc src/src/libscotch/graph_io_scot.c new/src/libscotch/graph_io_scot.c
 *** src/src/libscotch/graph_io_scot.c	2008-05-22 06:44:42.000000000 -0700
---- new/src/libscotch/graph_io_scot.c	2010-03-03 14:06:15.304926224 -0800
+--- new/src/libscotch/graph_io_scot.c	2010-04-06 15:51:57.638253486 -0700
 ***************
 *** 89,95 ****
@@ -1066,5 +1066,5 @@
 diff -rc src/src/libscotch/library_arch.c new/src/libscotch/library_arch.c
 *** src/src/libscotch/library_arch.c	2008-05-22 06:44:42.000000000 -0700
---- new/src/libscotch/library_arch.c	2010-03-03 14:06:15.310926227 -0800
+--- new/src/libscotch/library_arch.c	2010-04-06 15:51:57.644253493 -0700
 ***************
 *** 120,128 ****
@@ -1101,5 +1101,5 @@
 diff -rc src/src/libscotch/library_arch_f.c new/src/libscotch/library_arch_f.c
 *** src/src/libscotch/library_arch_f.c	2008-05-22 06:44:42.000000000 -0700
---- new/src/libscotch/library_arch_f.c	2010-03-03 14:06:15.317926230 -0800
+--- new/src/libscotch/library_arch_f.c	2010-04-06 15:51:57.651253502 -0700
 ***************
 *** 121,127 ****
@@ -1118,5 +1118,5 @@
 diff -rc src/src/libscotch/library_error_exit.c new/src/libscotch/library_error_exit.c
 *** src/src/libscotch/library_error_exit.c	2009-01-20 00:36:33.000000000 -0800
---- new/src/libscotch/library_error_exit.c	2010-03-03 14:06:15.323926232 -0800
+--- new/src/libscotch/library_error_exit.c	2010-04-06 15:51:57.657253509 -0700
 ***************
 *** 114,119 ****
@@ -1193,5 +1193,5 @@
 diff -rc src/src/libscotch/library_graph.c new/src/libscotch/library_graph.c
 *** src/src/libscotch/library_graph.c	2008-05-22 07:28:12.000000000 -0700
---- new/src/libscotch/library_graph.c	2010-03-03 14:06:15.329926234 -0800
+--- new/src/libscotch/library_graph.c	2010-04-06 15:51:57.664253518 -0700
 ***************
 *** 137,143 ****
@@ -1238,5 +1238,5 @@
 diff -rc src/src/libscotch/library_graph_f.c new/src/libscotch/library_graph_f.c
 *** src/src/libscotch/library_graph_f.c	2008-05-22 06:44:43.000000000 -0700
---- new/src/libscotch/library_graph_f.c	2010-03-03 14:06:15.336926237 -0800
+--- new/src/libscotch/library_graph_f.c	2010-04-06 15:51:57.671253526 -0700
 ***************
 *** 136,142 ****
@@ -1255,5 +1255,5 @@
 diff -rc src/src/libscotch/library_graph_map.c new/src/libscotch/library_graph_map.c
 *** src/src/libscotch/library_graph_map.c	2008-09-28 04:04:05.000000000 -0700
---- new/src/libscotch/library_graph_map.c	2010-03-03 14:06:15.343926240 -0800
+--- new/src/libscotch/library_graph_map.c	2010-04-06 15:51:57.678253535 -0700
 ***************
 *** 182,192 ****
@@ -1280,5 +1280,5 @@
 diff -rc src/src/libscotch/library_graph_map_f.c new/src/libscotch/library_graph_map_f.c
 *** src/src/libscotch/library_graph_map_f.c	2008-06-28 03:44:26.000000000 -0700
---- new/src/libscotch/library_graph_map_f.c	2010-03-03 14:06:15.349926242 -0800
+--- new/src/libscotch/library_graph_map_f.c	2010-04-06 15:51:57.684253542 -0700
 ***************
 *** 183,189 ****
@@ -1297,5 +1297,5 @@
 diff -rc src/src/libscotch/library.h new/src/libscotch/library.h
 *** src/src/libscotch/library.h	2009-05-09 16:08:03.000000000 -0700
---- new/src/libscotch/library.h	2010-03-03 14:06:15.356926245 -0800
+--- new/src/libscotch/library.h	2010-04-06 15:51:57.691253550 -0700
 ***************
 *** 134,140 ****
@@ -1342,5 +1342,5 @@
 diff -rc src/src/libscotch/Makefile new/src/libscotch/Makefile
 *** src/src/libscotch/Makefile	2009-05-09 16:08:04.000000000 -0700
---- new/src/libscotch/Makefile	2010-03-03 14:41:00.434722658 -0800
+--- new/src/libscotch/Makefile	2010-04-06 15:51:57.700253561 -0700
 ***************
 *** 49,55 ****
@@ -1381,5 +1381,5 @@
 diff -rc src/src/libscotch/mapping.h new/src/libscotch/mapping.h
 *** src/src/libscotch/mapping.h	2008-10-27 08:27:47.000000000 -0700
---- new/src/libscotch/mapping.h	2010-03-03 14:06:15.371926251 -0800
+--- new/src/libscotch/mapping.h	2010-04-06 15:51:57.708253571 -0700
 ***************
 *** 106,112 ****
@@ -1398,5 +1398,5 @@
 diff -rc src/src/libscotch/mapping_io.c new/src/libscotch/mapping_io.c
 *** src/src/libscotch/mapping_io.c	2008-05-22 06:44:43.000000000 -0700
---- new/src/libscotch/mapping_io.c	2010-03-03 14:06:15.377926253 -0800
+--- new/src/libscotch/mapping_io.c	2010-04-06 15:51:57.714253579 -0700
 ***************
 *** 199,204 ****
@@ -1487,5 +1487,5 @@
 diff -rc src/src/libscotch/mesh_io_scot.c new/src/libscotch/mesh_io_scot.c
 *** src/src/libscotch/mesh_io_scot.c	2008-05-22 06:44:43.000000000 -0700
---- new/src/libscotch/mesh_io_scot.c	2010-03-03 14:06:15.384926256 -0800
+--- new/src/libscotch/mesh_io_scot.c	2010-04-06 15:51:57.721253587 -0700
 ***************
 *** 85,91 ****
@@ -1504,5 +1504,5 @@
 diff -rc src/src/Makefile new/src/Makefile
 *** src/src/Makefile	2008-09-15 05:50:51.000000000 -0700
---- new/src/Makefile	2010-03-03 14:06:15.389926258 -0800
+--- new/src/Makefile	2010-04-06 15:51:57.728253596 -0700
 ***************
 *** 97,102 ****
@@ -1520,7 +1520,9 @@
 Only in new/src: Makefile.inc
 Only in new/src/scotch: gmap_mex.c
+Only in new/src/scotch: gmap_mex_save.c
+Only in new/src/scotch: gmapx.c
 diff -rc src/src/scotch/Makefile new/src/scotch/Makefile
 *** src/src/scotch/Makefile	2009-04-27 02:19:43.000000000 -0700
---- new/src/scotch/Makefile	2010-03-03 14:06:15.395926260 -0800
+--- new/src/scotch/Makefile	2010-04-22 15:56:37.518839458 -0700
 ***************
 *** 49,59 ****
@@ -1553,10 +1555,12 @@
 ***************
 *** 94,99 ****
---- 97,106 ----
+--- 97,108 ----
   					dgscat$(EXE)				\
   					dgtst$(EXE)
   
 + mexscotch			:	clean
-+ 					$(MAKE) CFLAGS="$(CFLAGS) -DMATLAB -I${MATLAB_DIR}/extern/include" CC="$(CCS)" LDFLAGS="$(LDFLAGS) -Wl,-rpath-link,${MATLAB_DIR}/bin/glnxa64 -L${MATLAB_DIR}/bin/glnxa64 -lmex -lmat" SCOTCHLIB=scotch	\
++ 					$(MAKE) CFLAGS="$(CFLAGS) -DMATLAB -I${MATLAB_DIR}/extern/include" CC="$(CCS)" CCD="$(CCS)" LDFLAGS="$(LDFLAGS) -Wl,-rpath-link,${MATLAB_DIR}/bin/glnxa64 -L${MATLAB_DIR}/bin/glnxa64 -lmex -lmat" SCOTCHLIB=scotch \
++                     gmapx$(OBJ)
++ 					$(MAKE) CFLAGS="$(CFLAGS) -DMATLAB -I${MATLAB_DIR}/extern/include" CC="$(CCS)" LDFLAGS="$(LDFLAGS) -Wl,-rpath-link,${MATLAB_DIR}/bin/glnxa64 -L${MATLAB_DIR}/bin/glnxa64 -lmex -lmat gmapx$(OBJ)" SCOTCHLIB=scotch	\
 + 					gmap_mex$(MEX)
 + 
@@ -1566,5 +1570,5 @@
 ***************
 *** 104,111 ****
---- 111,122 ----
+--- 113,124 ----
   					-$(RM) $(bindir)/dgpart$(EXE)
   					-$(LN) $(bindir)/dgmap$(EXE) $(bindir)/dgpart$(EXE)
@@ -1581,8 +1585,16 @@
 ***************
 *** 365,367 ****
---- 376,386 ----
+--- 378,396 ----
   					$(libdir)/libscotch$(LIB)		\
   					$(libdir)/libscotcherrexit$(LIB)	\
   					mtst.h
++ 
++ gmapx$(OBJ)			:	gmapx.c					\
++ 					../libscotch/module.h			\
++ 					../libscotch/common.h			\
++ 					$(includedir)/scotch.h			\
++ 					$(libdir)/libscotch$(LIB)		\
++ 					$(libdir)/libscotcherrexit$(LIB)	\
++ 					gmap.h
 + 
 + gmap_mex$(MEX)		:	gmap_mex.c					\
@@ -1593,2 +1605,3 @@
 + 					$(libdir)/libscotcherrexit$(LIB)	\
 + 					gmap.h
+Only in new/src/scotch: Makefile_save
Index: /issm/trunk/externalpackages/scotch/scotch_jes_notes.txt
===================================================================
--- /issm/trunk/externalpackages/scotch/scotch_jes_notes.txt	(revision 3616)
+++ /issm/trunk/externalpackages/scotch/scotch_jes_notes.txt	(revision 3617)
@@ -289,2 +289,6 @@
 - separated dummysizes within mexscotch target in libscotch/Makefile so that it is built without the matlab flag, includes, and libraries (matlab 7.8 would fail even though matlab 7.6 was okay).
 
+4/26/10:
+
+- separated gmap_mex.c driver into gmap_mex.c matlab-layer (independent of scotch) and gmapx.c x-layer (independent of matlab).
+
