Пример #1
0
int
orderSave (
const Order * const         ordeptr,
FILE * const                stream)
{
  PASTIX_INT               vertnbr;
  PASTIX_INT               vertnum;
  PASTIX_INT               cblknum;
  int               o;

  if (ordeptr->rangtab == NULL) {
    errorPrint ("orderSave: cannot save ordering without column block data");
    return     (1);
  }
  if (ordeptr->permtab == NULL) {
    errorPrint ("orderSave: cannot save ordering without direct permutation data");
    return     (1);
  }

  vertnbr = ordeptr->rangtab[ordeptr->cblknbr] -  /* Get number of nodes */
            ordeptr->rangtab[0];

  if (fprintf (stream, "0\n%ld\t%ld\n",
               (long) ordeptr->cblknbr,
               (long) vertnbr) == EOF) {
    errorPrint ("orderSave: bad output (1)");
    return     (1);
  }

  for (cblknum = 0, o = 1; (o == 1) && (cblknum < ordeptr->cblknbr); cblknum ++) { /* Save column-block range array */
    o = intSave (stream, ordeptr->rangtab[cblknum]);
    putc (((cblknum & 7) == 7) ? '\n' : '\t', stream);
  }
  o = intSave (stream, ordeptr->rangtab[cblknum]);
  putc ('\n', stream);

  for (vertnum = 0; (o == 1) && (vertnum < (vertnbr - 1)); vertnum ++) { /* Save direct permutation */
    o = intSave (stream, ordeptr->permtab[vertnum]);
    putc (((vertnum & 7) == 7) ? '\n' : '\t', stream);
  }
  o = intSave (stream, ordeptr->permtab[vertnum]);
  putc ('\n', stream);

  if (o != 1)
    errorPrint ("orderSave: bad output (2)");

  return (1 - o);
}
Пример #2
0
static
int
C_graphScat (
FILE * const                stream,
SCOTCH_Num                  procnbr,
char * const                nameptr)
{
  SCOTCH_Num          versval;
  SCOTCH_Num          propval;
  char                proptab[4];
  int                 flagtab[3];
  SCOTCH_Num          baseval;
  SCOTCH_Num          vertglbnbr;
  SCOTCH_Num          edgeglbnbr;
  SCOTCH_Num          procnum;

  if (intLoad (stream, &versval) != 1) {          /* Read version number */
    errorPrint ("C_graphScat: bad input (1)");
    return     (1);
  }
  if (versval != 0) {                             /* If version not zero */
    errorPrint ("C_graphScat: only centralized graphs supported");
    return     (1);
  }

  if ((intLoad (stream, &vertglbnbr) != 1) ||     /* Read rest of header */
      (intLoad (stream, &edgeglbnbr) != 1) ||
      (intLoad (stream, &baseval)    != 1) ||
      (intLoad (stream, &propval)    != 1) ||
      (propval < 0)                        ||
      (propval > 111)) {
    errorPrint ("C_graphScat: bad input (2)");
    return     (1);
  }
  sprintf (proptab, "%3.3d", (int) propval);      /* Compute file properties */
  flagtab[0] = proptab[0] - '0';                  /* Vertex labels flag      */
  flagtab[1] = proptab[1] - '0';                  /* Edge weights flag       */
  flagtab[2] = proptab[2] - '0';                  /* Vertex loads flag       */

  for (procnum = 0; procnum < procnbr; procnum ++) {
    char *              nametmp;
    FILE *              ostream;
    SCOTCH_Num          vertlocnbr;
    SCOTCH_Num          vertlocnum;
    SCOTCH_Num          edgelocnbr;

    nametmp = nameptr;
    if ((fileNameDistExpand (&nametmp, procnbr, procnum, -1) != 0) ||
        ((ostream = fopen (nametmp, "w+")) == NULL)) {
      errorPrint ("C_graphScat: cannot open file");
      return     (1);
    }
    memFree (nametmp);                            /* Expanded name no longer needed */

    vertlocnbr = DATASIZE (vertglbnbr, procnbr, procnum);

    if (fprintf (ostream, "2\n" SCOTCH_NUMSTRING "\t" SCOTCH_NUMSTRING "\n" SCOTCH_NUMSTRING "\t" SCOTCH_NUMSTRING "\n" SCOTCH_NUMSTRING "\t%015d\n" SCOTCH_NUMSTRING "\t%3s\n", /* Write file header */
                 (SCOTCH_Num) procnbr,
                 (SCOTCH_Num) procnum,
                 (SCOTCH_Num) vertglbnbr,
                 (SCOTCH_Num) edgeglbnbr,
                 (SCOTCH_Num) vertlocnbr,
                 0,                               /* Number of edges not yet known */
                 (SCOTCH_Num) baseval,
                 proptab) == EOF) {
      errorPrint ("C_graphScat: bad output (1)");
      return     (1);
    }

    for (vertlocnum = edgelocnbr = 0; vertlocnum < vertlocnbr; vertlocnum ++) {
      SCOTCH_Num          degrval;

      if (flagtab[0] != 0) {                      /* If must read label               */
        SCOTCH_Num          vlblval;              /* Value where to read vertex label */

        if (intLoad (stream, &vlblval) != 1) {    /* Read label data */
          errorPrint ("C_graphScat: bad input (3)");
          return     (1);
        }
        intSave (ostream, vlblval);
        putc ('\t', ostream);
      }
      if (flagtab[2] != 0) {                      /* If must read vertex load        */
        SCOTCH_Num          veloval;              /* Value where to read vertex load */

        if (intLoad (stream, &veloval) != 1) {    /* Read vertex load data    */
          errorPrint ("C_graphScat: bad input (4)");
          return     (1);
        }
        intSave (ostream, veloval);
        putc ('\t', ostream);
      }
      if (intLoad (stream, &degrval) != 1) {      /* Read vertex degree */
        errorPrint ("C_graphScat: bad input (5)");
        return     (1);
      }
      intSave (ostream, degrval);

      edgelocnbr += degrval;

      for ( ; degrval > 0; degrval --) {
        SCOTCH_Num          edgeval;              /* Value where to read edge end */

        if (flagtab[1] != 0) {                    /* If must read edge load        */
          SCOTCH_Num          edloval;            /* Value where to read edge load */

          if (intLoad (stream, &edloval) != 1) {  /* Read edge load data    */
            errorPrint ("C_graphScat: bad input (6)");
            return     (1);
          }
          putc ('\t', ostream);
          intSave (ostream, edloval);
        }

        if (intLoad (stream, &edgeval) != 1) {    /* Read edge data */
          errorPrint ("C_graphScat: bad input (7)");
          return     (1);
        }
        putc ('\t', ostream);
        intSave (ostream, edgeval);
      }
      putc ('\n', ostream);
    }

    rewind (ostream);

    if (fprintf (ostream, "2\n" SCOTCH_NUMSTRING "\t" SCOTCH_NUMSTRING "\n" SCOTCH_NUMSTRING "\t" SCOTCH_NUMSTRING "\n" SCOTCH_NUMSTRING "\t%015lld\n" SCOTCH_NUMSTRING "\t%3s\n", /* Write file header */
                 (SCOTCH_Num) procnbr,
                 (SCOTCH_Num) procnum,
                 (SCOTCH_Num) vertglbnbr,
                 (SCOTCH_Num) edgeglbnbr,
                 (SCOTCH_Num) vertlocnbr,
                 (long long)  edgelocnbr,         /* Now we know the exact number of edges */
                 (SCOTCH_Num) baseval,
                 proptab) == EOF) {
      errorPrint ("C_graphScat: bad output (2)");
      return     (1);
    }

    fclose (ostream);
  }

  return (0);
}