Changeset 3617 for issm/trunk/externalpackages/scotch/gmap_mex.c
- Timestamp:
- 04/26/10 10:41:29 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/externalpackages/scotch/gmap_mex.c
r3003 r3617 1 /* Copyright 2004,2007,2008 ENSEIRB, INRIA & CNRS 2 ** 3 ** This file is part of the Scotch software package for static mapping, 4 ** graph partitioning and sparse matrix ordering. 5 ** 6 ** This software is governed by the CeCILL-C license under French law 7 ** and abiding by the rules of distribution of free software. You can 8 ** use, modify and/or redistribute the software under the terms of the 9 ** CeCILL-C license as circulated by CEA, CNRS and INRIA at the following 10 ** URL: "http://www.cecill.info". 11 ** 12 ** As a counterpart to the access to the source code and rights to copy, 13 ** modify and redistribute granted by the license, users are provided 14 ** only with a limited warranty and the software's author, the holder of 15 ** the economic rights, and the successive licensors have only limited 16 ** liability. 17 ** 18 ** In this respect, the user's attention is drawn to the risks associated 19 ** with loading, using, modifying and/or developing or reproducing the 20 ** software by the user in light of its specific status of free software, 21 ** that may mean that it is complicated to manipulate, and that also 22 ** therefore means that it is reserved for developers and experienced 23 ** professionals having in-depth computer knowledge. Users are therefore 24 ** encouraged to load and test the software's suitability as regards 25 ** their requirements in conditions enabling the security of their 26 ** systems and/or data to be ensured and, more generally, to use and 27 ** operate it in the same conditions as regards security. 28 ** 29 ** The fact that you are presently reading this means that you have had 30 ** knowledge of the CeCILL-C license and that you accept its terms. 31 */ 32 /************************************************************/ 33 /** **/ 34 /** NAME : gmap.c **/ 35 /** **/ 36 /** AUTHOR : Francois PELLEGRINI **/ 37 /** **/ 38 /** FUNCTION : Part of a graph mapping software. **/ 39 /** This module contains the main function. **/ 40 /** **/ 41 /** DATES : # Version 0.0 : from : 05 jan 1993 **/ 42 /** to 12 may 1993 **/ 43 /** # Version 1.1 : from : 15 oct 1993 **/ 44 /** to 15 oct 1993 **/ 45 /** # Version 1.3 : from : 06 apr 1994 **/ 46 /** to 18 may 1994 **/ 47 /** # Version 2.0 : from : 06 jun 1994 **/ 48 /** to 17 nov 1994 **/ 49 /** # Version 2.1 : from : 07 apr 1995 **/ 50 /** to 18 jun 1995 **/ 51 /** # Version 3.0 : from : 01 jul 1995 **/ 52 /** to 02 oct 1995 **/ 53 /** # Version 3.1 : from : 07 nov 1995 **/ 54 /** to 25 apr 1996 **/ 55 /** # Version 3.2 : from : 24 sep 1996 **/ 56 /** to 26 may 1998 **/ 57 /** # Version 3.3 : from : 19 oct 1998 **/ 58 /** to : 30 mar 1999 **/ 59 /** # Version 3.4 : from : 03 feb 2000 **/ 60 /** to : 03 feb 2000 **/ 61 /** # Version 4.0 : from : 16 jan 2004 **/ 62 /** to : 27 dec 2004 **/ 63 /** # Version 5.0 : from : 23 dec 2007 **/ 64 /** to : 18 jun 2008 **/ 65 /** **/ 66 /************************************************************/ 67 68 /* 69 ** The defines and includes. 70 */ 71 72 #define GMAP 73 74 #include "module.h" 75 #include "common.h" 76 #include "scotch.h" 77 #include "gmap.h" 78 79 /* 80 ** The static variables. 81 */ 82 83 static int C_partNbr = 2; /* Default number of parts */ 84 static int C_paraNum = 0; /* Number of parameters */ 85 static int C_paraNbr = 0; /* No parameters for mapping */ 86 static int C_fileNum = 0; /* Number of file in arg list */ 87 static int C_fileNbr = 4; /* Number of files for mapping */ 88 static File C_fileTab[C_FILENBR] = { /* File array */ 89 { "-", NULL, "r" }, 90 { "-", NULL, "r" }, 91 { "-", NULL, "w" }, 92 { "-", NULL, "w" } }; 93 94 static const char * C_usageList[] = { /* Usage */ 95 "gmap [<input source file> [<input target file> [<output mapping file> [<output log file>]]]] <options>", 96 "gpart [<nparts>] [<input source file> [<output mapping file> [<output log file>]]] <options>", 97 " -h : Display this help", 98 " -m<strat> : Set mapping strategy (see user's manual)", 99 " -s<obj> : Force unity weights on <obj>:", 100 " e : edges", 101 " v : vertices", 102 " -V : Print program version and copyright", 103 " -v<verb> : Set verbose mode to <verb>:", 104 " m : mapping information", 105 " s : strategy information", 106 " t : timing information", 107 "", 108 "See default strategy with option '-vs'", 109 NULL }; 1 2 #define THISFUNCTION "Gmap" 3 4 /* Gmap structures and prototypes */ 5 6 #ifdef MATLAB 7 #include "mat.h" 8 #include "mex.h" 9 #include "matrix.h" 10 11 #define printf mexPrintf 12 #define fprintf(file,...) (file == stdout || file == stderr ? mexPrintf(__VA_ARGS__) : fprintf(file,__VA_ARGS__)) 13 #define malloc mxMalloc 14 #define calloc mxCalloc 15 #define realloc mxRealloc 16 #define free mxFree 17 #define exit(status) mexErrMsgTxt("exit=" #status) 18 #endif 19 20 void GmapUsage( void ); 21 22 23 /* Input Arguments */ 24 25 #define ADJMAT_IN prhs[0] 26 #define VERTLB_IN prhs[1] 27 #define VERTWT_IN prhs[2] 28 #define EDGEWT_IN prhs[3] 29 #define ARCHTYP_IN prhs[4] 30 #define ARCHPAR_IN prhs[5] 31 #define REQ_ARGS 6 32 33 /* Output Arguments */ 34 35 #define RETURN_OUT plhs[0] 36 #define MAPTAB_OUT plhs[1] 37 38 39 int 40 gmapx ( 41 int (**pmaptabi)[2], 42 int argcm, 43 char *argvm[], 44 int nvi, 45 int ne2i, 46 int *ir, 47 int *jc, 48 int *vli, 49 int *vwi, 50 int *ewi, 51 char archtyp[], 52 int nai, 53 int *api); 110 54 111 55 /******************************/ … … 116 60 117 61 void mexFunction( int nlhs, 118 119 120 62 mxArray *plhs[], 63 int nrhs, 64 const mxArray *prhs[] ) 121 65 { 122 int argcm; 123 char argvm[21][257]; 124 SCOTCH_Graph grafdat; /* Source graph */ 125 SCOTCH_Num grafflag; /* Source graph properties */ 126 SCOTCH_Arch archdat; /* Target architecture */ 127 SCOTCH_Strat stradat; /* Mapping strategy */ 128 SCOTCH_Mapping mapdat; /* Mapping data */ 129 Clock runtime[2]; /* Timing variables */ 130 SCOTCH_Num nvert =0; 131 SCOTCH_Num nedge2=0; 132 SCOTCH_Num* adjir =NULL; 133 SCOTCH_Num* adjjc =NULL; 134 mwIndex *ir=NULL,*jc=NULL; 135 double *vld=NULL,*vwd=NULL,*ewd=NULL,*apd=NULL; 136 SCOTCH_Num* vertlab=NULL; 137 SCOTCH_Num* vertwgt=NULL; 138 SCOTCH_Num* edgewgt=NULL; 139 char archtyp[256]; 140 SCOTCH_Num napar =0; 141 SCOTCH_Num* archpar=NULL; 142 SCOTCH_Num (*maptab)[2]=NULL; 143 double* maptabm; 144 int flagval; 145 int i,j,k; 146 147 /* check static variables from previous runs */ 148 149 if (C_paraNum > 0 || C_fileNum > 0) 150 mexErrMsgTxt("gmap_mex still in memory -- clear gmap_mex and try again.\n"); 151 152 /* load matlab argument list */ 153 154 if (!mxIsNumeric(prhs[0]) || (!mxIsEmpty(prhs[0]) && !mxIsSparse(prhs[0]))) { 155 mexPrintf("%s -- Adjacency matrix must be numeric and sparse.\n","gmap_mex"); 156 mexErrMsgTxt(" "); 157 } 158 else { 159 nvert =mxGetM(prhs[0]); 160 nedge2=mxGetNzmax(prhs[0]); 161 ir =mxGetIr(prhs[0]); 162 adjir = (SCOTCH_Num *) malloc(mxGetNzmax(prhs[0])*sizeof(SCOTCH_Num)); 163 for (i=0; i<mxGetNzmax(prhs[0]); i++) 164 adjir[i]=(SCOTCH_Num)ir[i]; 165 jc =mxGetJc(prhs[0]); 166 adjjc = (SCOTCH_Num *) malloc((mxGetN(prhs[0])+1)*sizeof(SCOTCH_Num)); 167 for (i=0; i<(mxGetN(prhs[0])+1); i++) 168 adjjc[i]=(SCOTCH_Num)jc[i]; 169 mexPrintf("%s -- Adjacency matrix is of size %d by %d with %d non-zeroes.\n", 170 "gmap_mex",mxGetM(prhs[0]),mxGetN(prhs[0]),mxGetNzmax(prhs[0])); 171 } 172 173 if (!mxIsNumeric(prhs[1])) { 174 mexPrintf("%s -- Vertex label vector must be numeric.\n","gmap_mex"); 175 mexErrMsgTxt(" "); 176 } 177 else { 178 vld=mxGetPr(prhs[1]); 179 vertlab = (SCOTCH_Num *) malloc(mxGetM(prhs[1])*mxGetN(prhs[1])*sizeof(SCOTCH_Num)); 180 for (i=0; i<mxGetM(prhs[1])*mxGetN(prhs[1]); i++) 181 vertlab[i]=(SCOTCH_Num)vld[i]; 182 mexPrintf("%s -- Vertex label vector is of size %d by %d.\n", 183 "gmap_mex",mxGetM(prhs[1]),mxGetN(prhs[1])); 184 } 185 186 if (!mxIsNumeric(prhs[2])) { 187 mexPrintf("%s -- Vertex weight vector must be numeric.\n","gmap_mex"); 188 mexErrMsgTxt(" "); 189 } 190 else { 191 vwd=mxGetPr(prhs[2]); 192 vertwgt = (SCOTCH_Num *) malloc(mxGetM(prhs[2])*mxGetN(prhs[2])*sizeof(SCOTCH_Num)); 193 for (i=0; i<mxGetM(prhs[2])*mxGetN(prhs[2]); i++) 194 vertwgt[i]=(SCOTCH_Num)vwd[i]; 195 mexPrintf("%s -- Vertex weight vector is of size %d by %d.\n", 196 "gmap_mex",mxGetM(prhs[2]),mxGetN(prhs[2])); 197 } 198 199 if (!mxIsNumeric(prhs[3]) || (!mxIsEmpty(prhs[3]) && !mxIsSparse(prhs[3]))) { 200 mexPrintf("%s -- Edge weight matrix must be numeric and sparse.\n","gmap_mex"); 201 mexErrMsgTxt(" "); 202 } 203 else { 204 ewd=mxGetPr(prhs[3]); 205 edgewgt = (SCOTCH_Num *) malloc(mxGetM(prhs[3])*sizeof(SCOTCH_Num)); 206 for (i=0; i<mxGetNzmax(prhs[3]); i++) 207 edgewgt[i]=(SCOTCH_Num)ewd[i]; 208 mexPrintf("%s -- Edge weight matrix is of size %d by %d with %d non-zeroes.\n", 209 "gmap_mex",mxGetM(prhs[3]),mxGetN(prhs[3]),mxGetNzmax(prhs[3])); 210 } 211 212 if (!mxIsChar(prhs[4])) { 213 mexPrintf("%s -- Architecture type must be character.\n","gmap_mex"); 214 mexErrMsgTxt(" "); 215 } 216 else { 217 mxGetString(prhs[4],archtyp,255); 218 mexPrintf("%s -- Architecture type is \"%s\".\n", 219 "gmap_mex",archtyp); 220 archtyp[255] = '\0'; 221 } 222 223 if (!mxIsNumeric(prhs[5])) { 224 mexPrintf("%s -- Architecture parameter vector must be numeric.\n","gmap_mex"); 225 mexErrMsgTxt(" "); 226 } 227 else { 228 napar =mxGetM(prhs[5])*mxGetN(prhs[5]); 229 apd=mxGetPr(prhs[5]); 230 archpar = (SCOTCH_Num *) malloc(mxGetM(prhs[5])*mxGetN(prhs[5])*sizeof(SCOTCH_Num)); 231 for (i=0; i<mxGetM(prhs[5])*mxGetN(prhs[5]); i++) 232 archpar[i]=(SCOTCH_Num)apd[i]; 233 mexPrintf("%s -- Architecture parameter vector is of size %d by %d.\n", 234 "gmap_mex",mxGetM(prhs[5]),mxGetN(prhs[5])); 235 } 236 237 argcm=nrhs+1-6; 238 mexPrintf("argcm=%d\n",argcm); 239 strcpy(argvm[0],"gmap"); 240 for (i=6; i<nrhs; i++) 241 if (!mxIsChar(prhs[i])) { 242 mexPrintf("%s -- prhs[%d] must be character.\n","gmap_mex",i); 243 mexErrMsgTxt(" "); 244 } 245 else 246 mxGetString(prhs[i],argvm[i-5],256); 247 for (i=0; i<argcm; i++) 248 mexPrintf("argvm[%d]=\"%s\"\n",i,argvm[i]); 249 250 flagval = C_FLAGNONE; /* Default behavior */ 251 i = strlen (argvm[0]); 252 if ((i >= 5) && (strncmp (argvm[0] + i - 5, "gpart", 5) == 0)) { 253 flagval |= C_FLAGPART; 254 C_paraNbr = 1; /* One more parameter */ 255 C_fileNbr = 3; /* One less file to provide */ 256 errorProg ("gpart"); 257 } 258 else 259 errorProg ("gmap"); 260 261 intRandInit (); 262 263 if ((argcm >= 2) && (argvm[1][0] == '?')) { /* If need for help */ 264 usagePrint (stdout, C_usageList); 265 /* return (0); */ 266 plhs[0]=mxCreateDoubleMatrix(1, 1, mxREAL); 267 *mxGetPr(plhs[0])=0.; 66 int argcm; 67 char **argvm=NULL; 68 int nvert =0,nedge2=0,napar =0; 69 mwIndex *ir=NULL,*jc=NULL; 70 int *adjir=NULL,*adjjc=NULL; 71 double *vld=NULL,*vwd=NULL,*ewd=NULL,*apd=NULL; 72 int *vli=NULL,*vwi=NULL,*ewi=NULL,*api=NULL; 73 char *archtyp=NULL; 74 int (*maptabi)[2]=NULL; 75 double* maptabd=NULL; 76 int i,j,k,ierr; 77 78 /* Check for proper number of arguments */ 79 80 if (nrhs == 0 && nlhs == 0) { 81 GmapUsage(); 82 return; 83 } 84 else if (nrhs < 6 || nlhs > 2) { 85 GmapUsage(); 86 mexErrMsgTxt(" "); 87 } 88 89 /* load matlab argument list and convert to integer (note that converting here 90 and in the x-layer is inefficient, but it makes the x-layer more general) */ 91 92 if (!mxIsNumeric(ADJMAT_IN) || (!mxIsEmpty(ADJMAT_IN) && !mxIsSparse(ADJMAT_IN))) { 93 mexPrintf("%s -- Adjacency matrix must be numeric and sparse.\n",THISFUNCTION); 94 mexErrMsgTxt(" "); 95 } 96 else { 97 nvert =mxGetM(ADJMAT_IN); 98 nedge2=mxGetNzmax(ADJMAT_IN); 99 if (mxGetNzmax(ADJMAT_IN)) { 100 ir =mxGetIr(ADJMAT_IN); 101 adjir = (int *) malloc(mxGetNzmax(ADJMAT_IN)*sizeof(int)); 102 for (i=0; i<mxGetNzmax(ADJMAT_IN); i++) 103 adjir[i]=(int)ir[i]; 104 } 105 if (mxGetN(ADJMAT_IN)) { 106 jc =mxGetJc(ADJMAT_IN); 107 adjjc = (int *) malloc((mxGetN(ADJMAT_IN)+1)*sizeof(int)); 108 for (i=0; i<(mxGetN(ADJMAT_IN)+1); i++) 109 adjjc[i]=(int)jc[i]; 110 } 111 mexPrintf("%s -- Adjacency matrix is of size %d by %d with %d non-zeroes.\n", 112 THISFUNCTION,mxGetM(ADJMAT_IN),mxGetN(ADJMAT_IN),mxGetNzmax(ADJMAT_IN)); 113 } 114 115 if (!mxIsNumeric(VERTLB_IN)) { 116 mexPrintf("%s -- Vertex label vector must be numeric.\n",THISFUNCTION); 117 mexErrMsgTxt(" "); 118 } 119 else { 120 if (mxGetM(VERTLB_IN)*mxGetN(VERTLB_IN)) { 121 vld=mxGetPr(VERTLB_IN); 122 vli = (int *) malloc(mxGetM(VERTLB_IN)*mxGetN(VERTLB_IN)*sizeof(int)); 123 for (i=0; i<mxGetM(VERTLB_IN)*mxGetN(VERTLB_IN); i++) 124 vli[i]=(int)vld[i]; 125 } 126 mexPrintf("%s -- Vertex label vector is of size %d by %d.\n", 127 THISFUNCTION,mxGetM(VERTLB_IN),mxGetN(VERTLB_IN)); 128 } 129 130 if (!mxIsNumeric(VERTWT_IN)) { 131 mexPrintf("%s -- Vertex weight vector must be numeric.\n",THISFUNCTION); 132 mexErrMsgTxt(" "); 133 } 134 else { 135 if (mxGetM(VERTWT_IN)*mxGetN(VERTWT_IN)) { 136 vwd=mxGetPr(VERTWT_IN); 137 vwi = (int *) malloc(mxGetM(VERTWT_IN)*mxGetN(VERTWT_IN)*sizeof(int)); 138 for (i=0; i<mxGetM(VERTWT_IN)*mxGetN(VERTWT_IN); i++) 139 vwi[i]=(int)vwd[i]; 140 } 141 mexPrintf("%s -- Vertex weight vector is of size %d by %d.\n", 142 THISFUNCTION,mxGetM(VERTWT_IN),mxGetN(VERTWT_IN)); 143 } 144 145 if (!mxIsNumeric(EDGEWT_IN) || (!mxIsEmpty(EDGEWT_IN) && !mxIsSparse(EDGEWT_IN))) { 146 mexPrintf("%s -- Edge weight matrix must be numeric and sparse.\n",THISFUNCTION); 147 mexErrMsgTxt(" "); 148 } 149 else { 150 if (mxGetM(EDGEWT_IN)) { 151 ewd=mxGetPr(EDGEWT_IN); 152 ewi = (int *) malloc(mxGetM(EDGEWT_IN)*sizeof(int)); 153 for (i=0; i<mxGetNzmax(EDGEWT_IN); i++) 154 ewi[i]=(int)ewd[i]; 155 } 156 mexPrintf("%s -- Edge weight matrix is of size %d by %d with %d non-zeroes.\n", 157 THISFUNCTION,mxGetM(EDGEWT_IN),mxGetN(EDGEWT_IN),mxGetNzmax(EDGEWT_IN)); 158 } 159 160 if (!mxIsChar(ARCHTYP_IN)) { 161 mexPrintf("%s -- Architecture type must be character.\n",THISFUNCTION); 162 mexErrMsgTxt(" "); 163 } 164 else { 165 if (mxGetM(ARCHTYP_IN)*mxGetN(ARCHTYP_IN)) { 166 archtyp = (char *) calloc(mxGetM(ARCHTYP_IN)*mxGetN(ARCHTYP_IN)+1,sizeof(char)); 167 mxGetString(ARCHTYP_IN,archtyp,mxGetM(ARCHTYP_IN)*mxGetN(ARCHTYP_IN)+1); 168 } 169 mexPrintf("%s -- Architecture type is \"%s\".\n", 170 THISFUNCTION,archtyp); 171 } 172 173 if (!mxIsNumeric(ARCHPAR_IN)) { 174 mexPrintf("%s -- Architecture parameter vector must be numeric.\n",THISFUNCTION); 175 mexErrMsgTxt(" "); 176 } 177 else { 178 napar =mxGetM(ARCHPAR_IN)*mxGetN(ARCHPAR_IN); 179 if (mxGetM(ARCHPAR_IN)*mxGetN(ARCHPAR_IN)) { 180 apd=mxGetPr(ARCHPAR_IN); 181 api = (int *) malloc(mxGetM(ARCHPAR_IN)*mxGetN(ARCHPAR_IN)*sizeof(int)); 182 for (i=0; i<mxGetM(ARCHPAR_IN)*mxGetN(ARCHPAR_IN); i++) 183 api[i]=(int)apd[i]; 184 } 185 mexPrintf("%s -- Architecture parameter vector is of size %d by %d.\n", 186 THISFUNCTION,mxGetM(ARCHPAR_IN),mxGetN(ARCHPAR_IN)); 187 } 188 189 argcm=nrhs+1-REQ_ARGS; 190 mexPrintf("argcm=%d\n",argcm); 191 argvm = (char **) malloc(argcm*sizeof(char *)); 192 argvm[0] = (char *) calloc(4+1,sizeof(char)); 193 strcpy(argvm[0],"gmap"); 194 for (i=REQ_ARGS; i<nrhs; i++) 195 if (!mxIsChar(prhs[i])) { 196 mexPrintf("%s -- prhs[%d] must be character.\n",THISFUNCTION,i); 197 mexErrMsgTxt(" "); 198 } 199 else { 200 argvm[i+1-REQ_ARGS] = (char *) calloc(mxGetM(prhs[i])*mxGetN(prhs[i])+1,sizeof(char)); 201 mxGetString(prhs[i],argvm[i+1-REQ_ARGS],mxGetM(prhs[i])*mxGetN(prhs[i])+1); 202 } 203 for (i=0; i<argcm; i++) 204 mexPrintf("argvm[%d]=\"%s\"\n",i,argvm[i]); 205 206 /* Do the actual computations in a subroutine */ 207 208 mexPrintf("Gmapx:\n"); 209 ierr=gmapx(&maptabi, 210 argcm, 211 argvm, 212 nvert, 213 nedge2, 214 adjir, 215 adjjc, 216 vli, 217 vwi, 218 ewi, 219 archtyp, 220 napar, 221 api); 222 mexPrintf("%s -- Error %d from Gmapx.\n",THISFUNCTION,ierr); 223 224 /* for (i=0; i<nvert; i++) 225 mexPrintf("maptabi[%d][0]=%d, maptabi[%d][1]=%d\n", 226 i,maptabi[i][0],i,maptabi[i][1]); */ 227 228 /* Create matrices for the return arguments */ 229 230 if (maptabi) { 231 MAPTAB_OUT=mxCreateDoubleMatrix(nvert, 2, mxREAL); 232 maptabd = mxGetPr(MAPTAB_OUT); 233 k=0; 234 for (j=0; j<2; j++) 235 for (i=0; i<nvert; i++) 236 maptabd[k++]=(double)maptabi[i][j]; 237 free(maptabi); 238 } 239 240 if (argvm) 241 for (i=argcm-1; i>=0; i--) 242 free(argvm[i]); 243 if (api) free(api); 244 if (archtyp) free(archtyp); 245 if (ewi) free(ewi); 246 if (vwi) free(vwi); 247 if (vli) free(vli); 248 if (adjjc) free(adjjc); 249 if (adjir) free(adjir); 250 251 RETURN_OUT=mxCreateDoubleMatrix(1, 1, mxREAL); 252 *mxGetPr(RETURN_OUT)=ierr; 253 254 return; 255 } 256 257 void GmapUsage( void ) 258 { 259 260 mexPrintf("\n"); 261 mexPrintf("Usage: [return,maptab]=Gmap_mex(adjmat,vertlb,vertwt,edgewt,archtyp,archpar,\n"); 262 mexPrintf(" Scotch-specific parameters);\n"); 263 mexPrintf("\n"); 264 268 265 return; 269 }270 271 grafflag = 0; /* Use vertex and edge weights */272 SCOTCH_stratInit (&stradat); /* Set default mapping strategy */273 274 printf("point 0: C_FILENBR=%d, C_fileNbr=%d, C_paraNbr=%d\n",275 C_FILENBR,C_fileNbr,C_paraNbr);276 for (i = 0; i < C_FILENBR; i ++) /* Set default stream pointers */277 C_fileTab[i].pntr = (C_fileTab[i].mode[0] == 'r') ? stdin : stdout;278 for (i = 1; i < argcm; i ++) { /* Loop for all option codes */279 printf("point 1: i=%d; C_fileNbr=%d, C_fileNum=%d, C_paraNbr=%d, C_paraNum=%d\n",280 i,C_fileNbr,C_fileNum,C_paraNbr,C_paraNum);281 if ((argvm[i][0] != '-') || (argvm[i][1] == '\0') || (argvm[i][1] == '.')) { /* If found a file name */282 printf("point 2: i=%d; C_fileNbr=%d, C_fileNum=%d, C_paraNbr=%d, C_paraNum=%d\n",283 i,C_fileNbr,C_fileNum,C_paraNbr,C_paraNum);284 if (C_paraNum < C_paraNbr) { /* If number of parameters not reached */285 if ((C_partNbr = atoi (argvm[i])) < 1) /* Get the number of parts */286 errorPrint ("main: invalid number of parts (\"%s\")", argvm[i]);287 C_paraNum ++;288 continue; /* Process the other parameters */289 }290 printf("point 3: i=%d; C_fileNbr=%d, C_fileNum=%d, C_paraNbr=%d, C_paraNum=%d\n",291 i,C_fileNbr,C_fileNum,C_paraNbr,C_paraNum);292 if (C_fileNum < C_fileNbr) /* A file name has been given */293 C_fileTab[C_fileNum ++].name = argvm[i];294 else295 errorPrint ("main: too many file names given");296 printf("point 4: i=%d; C_fileNbr=%d, C_fileNum=%d, C_paraNbr=%d, C_paraNum=%d\n",297 i,C_fileNbr,C_fileNum,C_paraNbr,C_paraNum);298 }299 else { /* If found an option name */300 switch (argvm[i][1]) {301 case 'H' : /* Give the usage message */302 case 'h' :303 usagePrint (stdout, C_usageList);304 /* return (0); */305 plhs[0]=mxCreateDoubleMatrix(1, 1, mxREAL);306 *mxGetPr(plhs[0])=0.;307 return;308 case 'M' :309 case 'm' :310 SCOTCH_stratExit (&stradat);311 SCOTCH_stratInit (&stradat);312 SCOTCH_stratGraphMap (&stradat, &argvm[i][2]);313 break;314 case 'S' :315 case 's' : /* Source graph parameters */316 for (j = 2; argvm[i][j] != '\0'; j ++) {317 switch (argvm[i][j]) {318 case 'E' :319 case 'e' :320 grafflag |= 2; /* Do not load edge weights */321 break;322 case 'V' :323 case 'v' :324 grafflag |= 1; /* Do not load vertex weights */325 break;326 default :327 errorPrint ("main: invalid source graph option (\"%c\")", argvm[i][j]);328 }329 }330 break;331 case 'V' :332 fprintf (stderr, "gmap/gpart, version %s - F. Pellegrini\n", SCOTCH_VERSION);333 fprintf (stderr, "Copyright 2004,2007,2008 ENSEIRB, INRIA & CNRS, France\n");334 fprintf (stderr, "This software is libre/free software under CeCILL-C -- see the user's manual for more information\n");335 /* return (0); */336 plhs[0]=mxCreateDoubleMatrix(1, 1, mxREAL);337 *mxGetPr(plhs[0])=0.;338 return;339 case 'v' : /* Output control info */340 for (j = 2; argvm[i][j] != '\0'; j ++) {341 switch (argvm[i][j]) {342 case 'M' :343 case 'm' :344 flagval |= C_FLAGVERBMAP;345 break;346 case 'S' :347 case 's' :348 flagval |= C_FLAGVERBSTR;349 break;350 case 'T' :351 case 't' :352 flagval |= C_FLAGVERBTIM;353 break;354 default :355 errorPrint ("main: unprocessed parameter \"%c\" in \"%s\"", argvm[i][j], argvm[i]);356 }357 }358 break;359 default :360 errorPrint ("main: unprocessed option (\"%s\")", argvm[i]);361 }362 }363 }364 printf("point 5\n");365 if ((flagval & C_FLAGPART) != 0) { /* If program run as the partitioner */366 C_fileTab[3].name = C_fileTab[2].name; /* Put provided file names at their right place */367 C_fileTab[2].name = C_fileTab[1].name;368 C_fileTab[1].name = "-";369 }370 printf("point 6\n");371 372 fileBlockOpen (C_fileTab, C_FILENBR); /* Open all files */373 for (i=0; i<C_FILENBR; i++)374 mexPrintf("C_fileTab[%d]: name=\"%s\",pntr=%p,mode=\"%s\"\n",375 i,C_fileTab[i].name,C_fileTab[i].pntr,C_fileTab[i].mode);376 printf("point 7\n");377 378 clockInit (&runtime[0]);379 clockStart (&runtime[0]);380 printf("point 8\n");381 382 SCOTCH_graphInit (&grafdat); /* Create graph structure */383 SCOTCH_graphLoad (&grafdat, C_filepntrsrcinp, -1, grafflag, nvert, nedge2, adjir, adjjc, vertlab, vertwgt, edgewgt); /* Read source graph */384 385 printf("point 9\n");386 SCOTCH_archInit (&archdat); /* Create architecture structure */387 if ((flagval & C_FLAGPART) != 0) /* If program run as the partitioner */388 SCOTCH_archCmplt (&archdat, C_partNbr); /* Create a complete graph of proper size */389 else390 SCOTCH_archLoad (&archdat, C_filepntrtgtinp, archtyp, napar, archpar); /* Read target architecture */391 printf("point 10\n");392 393 clockStop (&runtime[0]); /* Get input time */394 clockInit (&runtime[1]);395 clockStart (&runtime[1]);396 397 SCOTCH_graphMapInit (&grafdat, &mapdat, &archdat, NULL);398 SCOTCH_graphMapCompute (&grafdat, &mapdat, &stradat); /* Perform mapping */399 printf("point 11\n");400 401 clockStop (&runtime[1]); /* Get computation time */402 clockStart (&runtime[0]);403 404 SCOTCH_graphMapSave (&nvert, &maptab, &grafdat, &mapdat, C_filepntrmapout); /* Write mapping */405 406 /* for (i=0; i<nvert; i++)407 printf("maptab[%d][0]=%d, maptab[%d][1]=%d\n",408 i,maptab[i][0],i,maptab[i][1]); */409 if (maptab) {410 plhs[1]=mxCreateDoubleMatrix(nvert, 2, mxREAL);411 maptabm = mxGetPr(plhs[1]);412 k=0;413 for (j=0; j<2; j++)414 for (i=0; i<nvert; i++)415 maptabm[k++]=(double)maptab[i][j];416 free(maptab);417 }418 printf("point 12\n");419 420 clockStop (&runtime[0]); /* Get output time */421 422 if (flagval & C_FLAGVERBSTR) {423 fprintf (C_filepntrlogout, "S\tStrat=");424 SCOTCH_stratSave (&stradat, C_filepntrlogout);425 putc ('\n', C_filepntrlogout);426 }427 printf("point 13\n");428 if (flagval & C_FLAGVERBTIM) {429 fprintf (C_filepntrlogout, "T\tMapping\t\t%g\nT\tI/O\t\t%g\nT\tTotal\t\t%g\n",430 (double) clockVal (&runtime[1]),431 (double) clockVal (&runtime[0]),432 (double) clockVal (&runtime[0]) +433 (double) clockVal (&runtime[1]));434 }435 printf("point 14\n");436 if (flagval & C_FLAGVERBMAP)437 SCOTCH_graphMapView (&grafdat, &mapdat, C_filepntrlogout);438 printf("point 15\n");439 440 fileBlockClose (C_fileTab, C_FILENBR); /* Always close explicitely to end eventual (un)compression tasks */441 442 printf("point 16\n");443 SCOTCH_graphMapExit (&grafdat, &mapdat);444 printf("point 16a\n");445 SCOTCH_graphExit (&grafdat);446 printf("point 16b\n");447 SCOTCH_stratExit (&stradat);448 printf("point 16c\n");449 SCOTCH_archExit (&archdat);450 printf("point 17\n");451 452 if (archpar) free(archpar);453 if (edgewgt) free(edgewgt);454 if (vertwgt) free(vertwgt);455 if (vertlab) free(vertlab);456 if (adjjc) free(adjjc);457 if (adjir) free(adjir);458 459 #ifdef COMMON_PTHREAD460 pthread_exit ((void *) 0); /* Allow potential (un)compression tasks to complete */461 #endif /* COMMON_PTHREAD */462 printf("point 18\n");463 /* return (0); */464 plhs[0]=mxCreateDoubleMatrix(1, 1, mxREAL);465 *mxGetPr(plhs[0])=0.;466 return;467 266 } 267
Note:
See TracChangeset
for help on using the changeset viewer.