예제 #1
0
파일: testIO.c 프로젝트: JuliaFEM/SPOOLES
/*--------------------------------------------------------------------*/
int
main ( int argc, char *argv[] )
/*
   -------------------------------------------------
   test Perm_readFromFile and Perm_writeToFile,
   useful for translating between formatted *.permf
   and binary *.permb files.

   created -- 96may02, cca
   -------------------------------------------------
*/
{
char     *inPermFileName, *outPermFileName ;
double   t1, t2 ;
int      msglvl, rc ;
Perm     *perm ;
FILE     *msgFile ;

if ( argc != 5 ) {
   fprintf(stdout, 
      "\n\n usage : %s msglvl msgFile inFile outFile"
      "\n    msglvl   -- message level"
      "\n    msgFile  -- message file"
      "\n    inFile   -- input file, must be *.permf or *.permb"
      "\n    outFile  -- output file, must be *.permf or *.permb"
      "\n", argv[0]) ;
   return(0) ;
}
msglvl = atoi(argv[1]) ;
if ( strcmp(argv[2], "stdout") == 0 ) {
   msgFile = stdout ;
} else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
   fprintf(stderr, "\n fatal error in %s"
           "\n unable to open file %s\n",
           argv[0], argv[2]) ;
   return(-1) ;
}
inPermFileName  = argv[3] ;
outPermFileName = argv[4] ;
fprintf(msgFile, 
        "\n %s "
        "\n msglvl   -- %d" 
        "\n msgFile  -- %s" 
        "\n inFile   -- %s" 
        "\n outFile  -- %s" 
        "\n",
        argv[0], msglvl, argv[2], inPermFileName, outPermFileName) ;
fflush(msgFile) ;
/*
   -----------------------
   read in the Perm object
   -----------------------
*/
if ( strcmp(inPermFileName, "none") == 0 ) {
   fprintf(msgFile, "\n no file to read from") ;
   exit(0) ;
}
perm = Perm_new() ;
MARKTIME(t1) ;
rc = Perm_readFromFile(perm, inPermFileName) ;
MARKTIME(t2) ;
fprintf(msgFile, "\n CPU %9.5f : read in perm from file %s",
        t2 - t1, inPermFileName) ;
if ( rc != 1 ) {
   fprintf(msgFile, "\n return value %d from Perm_readFromFile(%p,%s)",
           rc, perm, inPermFileName) ;
   exit(-1) ;
}
fprintf(msgFile, "\n\n after reading Perm object from file %s",
        inPermFileName) ;
if ( msglvl > 2 ) {
   Perm_writeForHumanEye(perm, msgFile) ;
} else {
   Perm_writeStats(perm, msgFile) ;
}
fflush(msgFile) ;
/*
 -  ------------------------
   write out the Perm object
  - ------------------------
*/
if ( strcmp(outPermFileName, "none") != 0 ) {
   MARKTIME(t1) ;
   rc = Perm_writeToFile(perm, outPermFileName) ;
   MARKTIME(t2) ;
   fprintf(msgFile, "\n CPU %9.5f : write perm to file %s",
           t2 - t1, outPermFileName) ;
}
if ( rc != 1 ) {
   fprintf(msgFile, "\n return value %d from Perm_writeToFile(%p,%s)",
           rc, perm, outPermFileName) ;
}
/*
   --------------------
   free the Perm object
   --------------------
*/
Perm_free(perm) ;

fprintf(msgFile, "\n") ;
fclose(msgFile) ;

return(1) ; }
예제 #2
0
/*--------------------------------------------------------------------*/
int
main ( int argc, char *argv[] )
/*
   -----------------------------------------------
   generate a nested dissection permutation object 
   for a n1 x n2 x n3 regular grid.

   created -- 96feb01, cca
   -----------------------------------------------
*/
{
Perm        *perm ;
FILE        *msgFile ;
int         j, msglvl, n1, n2, n3, nvtx ;
int         *newToOld, *oldToNew, *temp ;

if ( argc != 7 ) {
   fprintf(stdout, 
"\n\n usage : %s msglvl msgFile n1 n2 n3 permFile"
"\n        generate separators"
"\n msglvl   -- message level"
"\n msgFile  -- message file"
"\n n1       -- number of points in first direction"
"\n n2       -- number of points in second direction"
"\n n3       -- number of points in third direction"
"\n permFile -- file to contain the Perm structure"
"\n", argv[0]) ;
   return(1) ;
}
msglvl  = atoi(argv[1]) ;
if ( strcmp(argv[2], "stdout") == 0 ) {
   msgFile = stdout ;
} else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
   fprintf(stderr, "\n error in test4, file %s, line %d"
           "\n unable to open file %s", __FILE__, __LINE__, argv[2]) ;
   exit(-1) ; 
}
n1 = atoi(argv[3]) ;
n2 = atoi(argv[4]) ;
n3 = atoi(argv[5]) ;
/*
   -----------------------------
   create the permutation object
   -----------------------------
*/
nvtx = n1 * n2 * n3 ;
perm = Perm_new() ;
Perm_initWithTypeAndSize(perm, 3, nvtx) ;
newToOld = perm->newToOld ;
oldToNew = perm->oldToNew ;
/*
   ---------------------
   call the nd procedure
   ---------------------
*/
mkNDperm(n1, n2, n3, newToOld, 0, n1-1, 0, n2-1, 0, n3-1) ;
/*
   -----------------------------------------
   fill in the new-to-old permutation vector
   -----------------------------------------
*/
for ( j = 0 ; j < nvtx ; j++ ) {
   perm->oldToNew[perm->newToOld[j]] = j ;
}
if ( msglvl > 2 ) {
   Perm_writeForHumanEye(perm, msgFile) ;
}
/*
   ----------------------------------------
   write the permutation vector to its file
   ----------------------------------------
*/
if ( strcmp("none", argv[6]) != 0 ) {
   Perm_writeToFile(perm, argv[6]) ;
}
/*
   ------------------------
   free the working storage
   ------------------------
*/
Perm_free(perm) ;

return(1) ; }
예제 #3
0
/*
   ------------------------------------------------
   given a permutation and a vector to map vertices 
   into compressed vertices, create and return a 
   permutation object for the compressed vertices.

   created -- 96may02, cca
   ------------------------------------------------
*/
Perm *
Perm_compress (
   Perm   *perm,
   IV     *eqmapIV
) {
int    n, N, v, vcomp, vnew ;
int    *eqmap, *head, *link, *newToOld, *oldToNew, *vals ; 
Perm   *perm2 ;
/*
   ---------------
   check the input
   ---------------
*/
if (  perm == NULL 
   || (n = perm->size) <= 0
   || eqmapIV == NULL 
   || n != IV_size(eqmapIV)
   || (eqmap = IV_entries(eqmapIV)) == NULL ) {
   fprintf(stderr, "\n fatal error in Perm_compress(%p,%p)"
           "\n bad input\n", perm, eqmapIV) ;
   if ( perm != NULL ) {
      Perm_writeStats(perm, stderr) ;
   }
   if ( eqmapIV != NULL ) {
      IV_writeStats(eqmapIV, stderr) ;
   }
   spoolesFatal();
}
n = perm->size ;
if ( (oldToNew = perm->oldToNew) == NULL ) {
   Perm_fillOldToNew(perm) ;
   oldToNew = perm->oldToNew ;
}
if ( (newToOld = perm->newToOld) == NULL ) {
   Perm_fillNewToOld(perm) ;
   newToOld = perm->newToOld ;
}
/*
   ---------------------------------
   create the new permutation object
   ---------------------------------
*/
N = 1 + IVmax(n, eqmap, &v) ;
perm2 = Perm_new() ;
Perm_initWithTypeAndSize(perm2, 3, N) ;
/*
   --------------------------------------------
   get the head/link structure for the vertices
   --------------------------------------------
*/
head = IVinit(N, -1) ;
link = IVinit(n, -1) ;
for ( v = 0 ; v < n ; v++ ) {
   vcomp = eqmap[v] ;
   link[v] = head[vcomp] ;
   head[vcomp] = v ;
}
/*
   ---------------------------
   get the two vectors to sort
   ---------------------------
*/
IVramp(N, perm2->newToOld, 0, 1) ;
vals = IVinit(N, -1) ;
for ( vcomp = 0 ; vcomp < N ; vcomp++ ) {
   v = head[vcomp] ;
   vnew = perm->oldToNew[v] ;
   for ( v = link[v] ; v != -1 ; v = link[v] ) {
      if ( vnew > perm->oldToNew[v] ) {
         vnew = perm->oldToNew[v] ;
      }
   }
   vals[vcomp] = vnew ;
}
IV2qsortUp(N, vals, perm2->newToOld) ;
for ( vcomp = 0 ; vcomp < N ; vcomp++ ) {
   perm2->oldToNew[perm2->newToOld[vcomp]] = vcomp ;
}
/*
   ---------------------
   free the working data
   ---------------------
*/
IVfree(head) ;
IVfree(link) ;
IVfree(vals) ;

return(perm2) ; }