Exemplo n.º 1
0
int getDependencies(nfs_sparse_mat_t *M, llist_t *C, s32 *deps, s32 origC, long testMode)
/***************************************************/
{ double blstart, blstop, difficulty;
  int    res;
  s32   i, j;
  u64   *tmpDeps;

  difficulty = (M->numCols/64.0)*(M->cIndex[M->numCols] + M->numCols*M->numDenseBlocks);
  difficulty /= 1000000.0;
  printf("Matrix difficulty is about %1.2lf\n", difficulty);
  if (!testMode) printf("Doing block Lanczos...\n");
  blstart = sTime();
  tmpDeps = (u64 *)malloc(M->numCols*sizeof(u64));
  res = blockLanczos64(tmpDeps, MultB64, MultB_T64, (void *)M, M->numCols,
		       testMode);
  blstop = sTime();
  printf("Returned %d. Block Lanczos took %1.2lf seconds.\n", res, blstop-blstart);
  msgLog("", "BLanczosTime: %1.1lf", blstop-blstart);
  if (res < 0) return res;

  /******************************************************/
  /* Now, we need to translate the dependencies back to */
  /* deps for the original matrix.                      */
  /******************************************************/
  memset(deps, 0x00, origC*sizeof(s32));

  for (i=0; i<M->numCols; i++) {
    for (j=C->index[i]; j<C->index[i+1]; j++)
      deps[C->data[j]] ^= (s32)(tmpDeps[i]&0xFFFFFFFF);
  }

  free(tmpDeps);  
  return 0;
}
Exemplo n.º 2
0
// 异步写文件的接口
void CMessage::AsyWriteFile(const char* pszFileName, const char* pszContent)
{
	CMessage msgLog(MSG_MEM_WRITE_FILE);
	msgLog.Add(pszFileName);
	msgLog.Add(pszContent);
	msgLog.SendToSM();
}
Exemplo n.º 3
0
void out( const char * string ) {
	int i;
#ifdef LOGGING_ENABLED
	if( !msgLog( string ) ) {
		printf("! ");
	}
#endif

#ifdef COMPILE_WITH_BLACKFIN
	for( i = 0; i < MAX_OUTPUT_LENGTH; i++ ) {
		if( string[i] != '\0' ) {
			sendChar( string[i] );
		} else {
			break;
		}
	}
#else
	printf( string );
#endif
}
Exemplo n.º 4
0
s32 doRowOps3(llist_t **P, llist_t *R, multi_file_t *prelF, s32 maxRelsInFF, s32 minFull)
/***************************************************************************************/
{ s32 numFull, numLP[10], j;
  llist_t *PL;
  s32 numLargeP;

  PL = getLPList(prelF);
  numLargeP = totalLargePrimes;
  printf("----------------------------\n");
  printf("There are %" PRId32 " large primes versus %" PRId32 " relations.\n", 
          numLargeP, initialRelations);
  msgLog(NULL, "largePrimes: %" PRId32 " , relations: %" PRId32,
         numLargeP, initialRelations);
  printf("----------------------------\n");

  *P = PL;
  for (j=0; j<10; j++)
    numLP[j]=0;
  for (j=0; j<PL->numFields; j++) 
    numLP[PL->index[j+1]-PL->index[j]] += 1;
  printf("Num large primes  |  Relations\n");
  printf("------------------------------\n");
  j=0;
  do {
    printf("                %" PRId32 " | %" PRId32 "\n", j, numLP[j]);
    j++;
  } while ((j<10) && (numLP[j]>0));
  printf("------------------------------\n");

#ifdef GGNFS_TPIE
  numFull = combParts_tpie(R, PL, maxRelsInFF, minFF, minFull);
#else
  numFull = combParts(R, PL, maxRelsInFF, minFF, minFull);
#endif
  return numFull;
}
Exemplo n.º 5
0
int main(int argC, char *args[])
/****************************************************/
{ char       fbName[64], prelName[40], newRelName[64], depName[64], colName[64];
  char       str[128], line[128];
  int        i, qcbSize = DEFAULT_QCB_SIZE, seed=DEFAULT_SEED, retVal=0;
  u32        maxRelsInFF=MAX_RELS_IN_FF;
  double     startTime, stopTime;
  s32        totalRels, relsInFile;
  nfs_fb_t   FB;
  multi_file_t prelF, lpF;
  FILE      *fp;

  lxmalloc(4000000,0);
  prelF.numFiles = DEFAULT_NUM_FILES;
  lpF.numFiles = 0;
  prelF.prefix[0] = lpF.prefix[0]=0;
  fbName[0] = newRelName[0] = 0;
  strcpy(depName, DEFAULT_DEPNAME);
  strcpy(colName, DEFAULT_COLNAME);
  strcpy(lpF.prefix, DEFAULT_LPI_NAME);
  strcpy(prelF.prefix, DEFAULT_PRELPREFIX);
  line[0]=0;
  printf(START_MSG, GGNFS_VERSION);
  minFF=0;

  for (i=1; i<argC; i++) {
    if (strcmp(args[i], "-fb")==0) {
      if ((++i) < argC) 
        strncpy(fbName, args[i], 64);
    } else if (strcmp(args[i], "-cols")==0) {
      if ((++i) < argC) 
        strncpy(colName, args[i], 64);
    } else if (strcmp(args[i], "-prel")==0) {
      if ((++i) < argC) 
        strncpy(prelF.prefix, args[i], 32);
    } else if (strcmp(args[i], "-qs")==0) {
      if ((++i) < argC)
        qcbSize = atoi(args[i]);
    } else if (strcmp(args[i], "-minff")==0) {
      if ((++i) < argC)
        minFF = atoi(args[i]);
    } else if (strcmp(args[i], "-seed")==0) {
      if ((++i) < argC)
        seed = atoi(args[i]);
    } else if (strcmp(args[i], "-v")==0) {
      verbose++;
    } else if (strcmp(args[i], "-maxrelsinff")==0) {
      if ((++i) < argC) 
        maxRelsInFF = atoi(args[i]);
    }
  }
  maxRelsInFF=MIN(MAX_RELS_IN_FF,maxRelsInFF);
  srand(seed);
  startTime = sTime();

  if ((fbName[0]==0) || (prelF.prefix[0]==0)) {
    printf("USAGE: %s %s\n", args[0], USAGE);
    exit(0);
  }
  msgLog("", "GGNFS-%s : matbuild", GGNFS_VERSION);
  sprintf(prelName, "%s.%d", prelF.prefix, 0);
  initFB(&FB);
  if (loadFB(fbName, &FB)) {
    printf("Could not load FB from %s!\n", fbName);
    exit(-1);
  }

  if (minFF < FB.rfb_size + FB.afb_size + 64 + 32)
    minFF = FB.rfb_size + FB.afb_size + 64 + 32;
  if (verbose)
    printf("Getting QCB of size %d...\n", qcbSize);

  /* Very strange! Why is this being done here?? */
  generateQCB(&FB, qcbSize); 

  count_prelF(&prelF);

  totalRels=0;
  for (i=0; i<prelF.numFiles; i++) {
    sprintf(prelName, "%s.%d", prelF.prefix, i);
    if ((fp = fopen(prelName, "rb"))) {
      rewind(fp);
      fread(&relsInFile, sizeof(s32), 1, fp);
      fclose(fp);
    }
    totalRels += relsInFile;
  }

  finalFF = getCols(colName, &prelF, &lpF, &FB, minFF, maxRelsInFF);
  msgLog("", "Heap stats for matbuild run.");
  logHeapStats();

  if (finalFF > 0)
    msgLog("", "rels:%" PRId32 ", initialFF:%" PRId32 ", finalFF:%" PRId32, 
           initialRelations, initialFF, finalFF);
  if (finalFF < minFF) {
    printf("More columns needed (current = %" PRId32 ", min = %" PRId32 ")\n",
           finalFF, minFF);
    exit(0);
  }

  /* Write some header information that will eventually be needed
     in the `deps' file.
  */
  if (!(fp = fopen("depinf", "wb"))) {
    fprintf(stderr, "Error opening %s for write!\n", "depinf");
  } else {
    sprintf(str, "NUMCOLS: %8.8" PRIx32, finalFF); writeBinField(fp, str);
    sprintf(str, "COLNAME: %s.index", colName); writeBinField(fp, str);
    sprintf(str, "MAXRELS: %8.8" PRIx32, totalRels); writeBinField(fp, str);
    sprintf(str, "RELPREFIX: %s", prelF.prefix); writeBinField(fp, str);
    sprintf(str, "RELFILES: %x", prelF.numFiles); writeBinField(fp, str);
    sprintf(str, "LPFPREFIX: %s", lpF.prefix); writeBinField(fp, str);
    sprintf(str, "LPFFILES: %x", lpF.numFiles); writeBinField(fp, str);
    sprintf(str, "END_HEADER"); writeBinField(fp, str);
    fclose(fp);
  }
  printf("`depinf' written. You can now run matprune.\n");
  msgLog("", "depinf file written. Run matprune.");

  stopTime = sTime();
  printf("Total elapsed time: %1.2lf seconds.\n", stopTime-startTime);

  return retVal;
}
Exemplo n.º 6
0
int main(int argC, char *args[])
/****************************************************/
{ char       colName[64], depName[64], str[1024];
  double     startTime, stopTime;
  s32       *deps, origC;
  u32        seed=DEFAULT_SEED;
  long       testMode=0;
  struct stat fileInfo;
  nfs_sparse_mat_t M;
  llist_t    C;
  int        i;
  FILE      *fp, *ifp;

  strcpy(colName, DEFAULT_COLNAME);
  strcpy(depName, DEFAULT_DEPNAME);
  printf(START_MSG, GGNFS_VERSION);
  seed=time(0);
  /* This probably shouldn't be needed, but whatever. */
  seed = ((seed % 1001)*seed) ^ (171*seed);

  for (i=1; i<argC; i++) {
    if (strcmp(args[i], "-v")==0) {
      verbose++;
    } else if (strcmp(args[i], "-seed")==0) {
      if ((++i) < argC) {
        seed = atol(args[i]);
      }
    } else if (strcmp(args[i], "-save")==0) {
      if ((++i) < argC) {
        matsave_interval = 60 * atoi(args[i]);
      }
    } else if (strcmp(args[i], "-test")==0) {
      testMode = 1;
    } else if (strcmp(args[i], "--help")==0) {
      printf("USAGE: %s %s\n", args[0], USAGE);
      exit(0);
    }
  }
  srand(seed);
  if (stat("depinf", &fileInfo)) {
    printf("Could not stat depinf! Are you trying to run %s to soon?\n", args[0]);
    return -1;
  }
  seedBlockLanczos(seed);
  startTime = sTime();
  msgLog("", "GGNFS-%s : matsolve (seed=%" PRIu32 ")", GGNFS_VERSION, seed);
  printf("Using PRNG seed=%" PRIu32 ".\n", seed);

  readSparseMat(&M, "spmat");
  ll_read(&C, "sp-index");
  printf("Verifying column map..."); fflush(stdout);
  ll_verify(&C);
  printf("done.\n");


  printf("Matrix loaded: it is %" PRId32 " x %" PRId32 ".\n", M.numRows, M.numCols);
  if (M.numCols < (M.numRows + 64)) {
    printf("More columns needed (current = %" PRId32 ", min = %" PRId32 ")\n",
           M.numCols, M.numRows+64);
    free(M.cEntry); free(M.cIndex);
    exit(-1);
  }
  if (checkMat(&M, delCols, &numDel)) {
    printf("checkMat() returned some error! Terminating...\n");
    exit(-1);
  }

  /* We need to know how many columns there were in the original, unpruned
     matrix, so we know how much memory to allocate for the dependencies.
  */
  if (!(ifp = fopen("depinf", "rb"))) {
    fprintf(stderr, "Error opening depinf for read!\n");
    exit(-1);
  }
  readBinField(str, 1024, ifp);
  while (!(feof(ifp)) && strncmp(str, "END_HEADER",10)) {
    if (strncmp(str, "NUMCOLS: ", 9)==0) {
      sscanf(&str[9], "%" SCNx32, &origC);
    }
    readBinField(str, 1024, ifp);
  }
  fclose(ifp); 
  printf("Original matrix had %" PRId32 " columns.\n", origC);

  if (!(deps = (s32 *)malloc(origC*sizeof(s32)))) {
    printf("Could not allocate %" PRIu32 " bytes for the dependencies.\n", (u32)(origC*sizeof(s32)) );
    free(M.cEntry); free(M.cIndex); return -1;
  }

  if (getDependencies(&M, &C, deps, origC, testMode) == 0) {
    if (!(ifp = fopen("depinf", "rb"))) {
      fprintf(stderr, "Error opening depinf for read!\n");
      exit(-1);
    }
    printf("Writing dependencies to file %s.\n", depName);
    if (!(fp = fopen(depName, "wb"))) {
      fprintf(stderr, "Error opening %s for write!\n", depName);
      fclose(ifp);
    } else {
      /* Get the header information from depinf. */
      readBinField(str, 1024, ifp);
      while (!(feof(ifp)) && strncmp(str, "END_HEADER",10)) {
        writeBinField(fp, str);
        readBinField(str,1024,ifp);
      }
      if (strncmp(str, "END_HEADER",10)) {
        fprintf(stderr, "Error: depinf is corrupt!\n");
        fclose(ifp); fclose(fp); exit(-1);
      }
      writeBinField(fp, str);
      fclose(ifp);
      fwrite(deps, sizeof(s32), origC, fp);
      fclose(fp);
    }
  }

  stopTime = sTime();
  printf("Total elapsed time: %1.2lf seconds.\n", stopTime-startTime);
  msgLog("", "Heap stats for matsolve run:");
  logHeapStats();



  free(M.cEntry); free(M.cIndex); free(deps);
  return 0;
}  
Exemplo n.º 7
0
Arquivo: tmp.c Projeto: FairSky/ggnfs
static void master(void)
/********************************************************************/
/* One of the MPI processes will be distinguished as a master node. */
/* That master node will call this function only, so this is the    */
/* function that controls all the slave nodes.                      */
/********************************************************************/
{ node_t           nodeList[MAX_NODES];
  int              numNodes, j, numSlaves, numOnCall;
  long             colsPerNode, c0, c1;
  nfs_sparse_mat_t M;
  double           blstart, blstop;
  long            *deps;

  /* Load the matrix. */

  /* This is not yet done, as it could be a bit tricky.
     It might not fit into RAM on a single node, which means 
     we should really preprocess it first on a machine with
     plenty of RAM, save the preprocessed version to disk,
     and use that one here. Then, instead of loading the
     whole matrix at once, the master node should just load
     columns as they are needed to send to the workers.
       All this function really needs to know is the matrix
     stats - dimensions and such. So we should here fill those
     fields in.  Then make the initializeNode() function above
     read the needed columns from disk and send them out.
  */
  M.numCols = M.numRows = 0; /* Change this to the real deal. */



  /* Find out how many nodes there are. */
  MPI_Comm_size(MPI_COMM_WORLD, &numNodes);
  nodeList[0].status = ST_MASTER;

  /****************************************************************/
  /* If we have more than a handful of nodes, say more than 8,    */
  /* we should leave at least one `on call' in case another one   */
  /* dies. Why? Consider the alternative: if a node dies and we   */
  /* don't have a backup available, then we either have to        */
  /* give one node twice the work, or re-distribute and re-assign */
  /* the matrix columns. This would:                              */
  /*  (1) Hugely complicate the code.                             */
  /*  (2) Waste bandwidth.                                        */
  /*  (3) Waste time.                                             */
  /* Of course, we could assume that no node ever fails, but that */
  /* is a very bad idea. The is the best compromise between       */
  /* robustness and efficiency that I can think of.               */
  /* If you don't like it, you can change this single line of     */
  /* code, but beware that the resulting code will not be fault   */
  /* tolerant at all!                                             */
  /****************************************************************/
  numOnCall = ((numNodes >= 8) ? (MIN(1, 0.05*numNodes)) : 0);

  for (i=1; i<numNodes; i++)
    nodeList[i].status=ST_WORKING;
  for (i=0; i<numOnCall; i--)
    nodeList[numNodes-1-i].status = ST_ONCALL;

  /* How many columns does each node get? */
  for (i=1; i<numNodes; i++)
    if (nodeList[i].status == ST_WORKING)
      numSlaves++;
  colsPerNode = M->numCols/numSlaves;

  /* Initialize the slave nodes with their needed columns. */
  c0 = 0; c1 = c0 + colsPerNode;
  for (i=0,j=0; i<numSlaves; i++) {
    do {
      j++;
    } while (nodeList[j].status != ST_WORKING);
    nodeList[j].c0 = c0;
    nodeList[j].c1 = c1;
    initializeNode(&nodeList[j]);
    c0 = c1;
    c1 = MIN(c0+colsPerNode, M->numCols);
  }

  /* We should now be able to just do: */
  srand(seed);
  seedBlockLanczos(seed);
  startTime = sTime();
  msgLog("", "GGNFS-%s : mpi-matsolve", GGNFS_VERSION);
  msgLog("", "Running on %d (of %d) nodes.", numSlaves, numNodes);
  

  blstart = sTime();
  if (!(deps = (long *)malloc(M.numCols*sizeof(long)))) {
    fprintf(stderr, "Severe memory allocation error!\n");
    res = -1;
  } else {
    res = blockLanczos32(deps,  mpi-multB32, mpi-multB_T32, NULL, M.numCols);
    blstop = sTime();
    printf("Returned %d. Block Lanczos took %1.2lf seconds.\n", res, blstop-blstart);
    msgLog("", "BLanczosTime: %1.1lf", blstop-blstart);
  }

  /* Shutdown all of the nodes except this one. */
  for (i=1; i<numNodes; i++) {
    MPI_Send(0, 0, MPI_INT, i, DIETAG, MPI_COMM_WORLD);
  }

  /* Now retrieve the actual dependencies (i.e., if there was a matrix
     pruning step, then we need to get back to the original matrix).
     Then store them to file.
  */


}
Exemplo n.º 8
0
// 清空文件内容
void CMessage::AsyClearFile(const char* pszFileName)
{
	CMessage msgLog(MSG_MEM_CLEAR_FILE);
	msgLog.Add(pszFileName);
	msgLog.SendToSM();
}
Exemplo n.º 9
0
// 打开文件
void CMessage::AsyOpenFile(const char* pszFileName)
{
	CMessage msgLog(MSG_MEM_OPEN_FILE);
	msgLog.Add(pszFileName);
	msgLog.SendToSM();
}