示例#1
0
// Load the tile into the texture image and draw it within given coordinates
static void imodvDrawTImage(Ipoint *p1, Ipoint *p2, Ipoint *p3, Ipoint *p4,
                            Ipoint *clamp,
                            unsigned char *data,
                            int width, int height)
{
  float xclamp, yclamp, clamp0 = 1. / sTexImageSize;
  double wallStart = wallTime();

  xclamp = clamp->x;
  yclamp = clamp->y;

  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, data);
  /*GLenum error = glGetError();
    if (error)
    imodPrintStderr("GL error on glTexSubImage2D: %s\n", gluErrorString(error)); */
  sWallLoad += wallTime() - wallStart;
  wallStart = wallTime();

  glBegin(GL_QUADS);
  glTexCoord2f(clamp0, clamp0); glVertex3fv((GLfloat *)p1);
  glTexCoord2f(xclamp, clamp0); glVertex3fv((GLfloat *)p2);
  glTexCoord2f(xclamp, yclamp); glVertex3fv((GLfloat *)p3);
  glTexCoord2f(clamp0, yclamp); glVertex3fv((GLfloat *)p4);


  glEnd();
  glFlush();
  sWallDraw += wallTime() - wallStart;
}
示例#2
0
double Time::stop()
{
  if (isRunning_) {
    totalTime_ += ( wallTime() - startTime_ );
    isRunning_ = false;
    startTime_ = 0;
  }
  return totalTime_;
}
示例#3
0
static void sharp_execute_job_mpi (sharp_job *job, MPI_Comm comm)
  {
  int ntasks;
  MPI_Comm_size(comm, &ntasks);
  if (ntasks==1) /* fall back to scalar implementation */
    { sharp_execute_job (job); return; }

  MPI_Barrier(comm);
  double timer=wallTime();
  job->opcnt=0;
  sharp_mpi_info minfo;
  sharp_make_mpi_info(comm, job, &minfo);

  if (minfo.npairtotal>minfo.ntasks*300)
    {
    int nsub=(minfo.npairtotal+minfo.ntasks*200-1)/(minfo.ntasks*200);
    for (int isub=0; isub<nsub; ++isub)
      {
      sharp_job ljob=*job;
      // When creating a_lm, every sub-job produces a complete set of
      // coefficients; they need to be added up.
      if ((isub>0)&&(job->type==SHARP_MAP2ALM)) ljob.flags|=SHARP_ADD;
      sharp_geom_info lginfo;
      lginfo.pair=RALLOC(sharp_ringpair,(job->ginfo->npairs/nsub)+1);
      lginfo.npairs=0;
      lginfo.nphmax = job->ginfo->nphmax;
      while (lginfo.npairs*nsub+isub<job->ginfo->npairs)
        {
        lginfo.pair[lginfo.npairs]=job->ginfo->pair[lginfo.npairs*nsub+isub];
        ++lginfo.npairs;
        }
      ljob.ginfo=&lginfo;
      sharp_execute_job_mpi (&ljob,comm);
      job->opcnt+=ljob.opcnt;
      DEALLOC(lginfo.pair);
      }
    }
  else
    {
    int lmax = job->ainfo->lmax;
    job->norm_l = sharp_Ylmgen_get_norm (lmax, job->spin);

    /* clear output arrays if requested */
    init_output (job);

    alloc_phase_mpi (job,job->ainfo->nm,job->ginfo->npairs,minfo.mmax+1,
      minfo.npairtotal);

    double *cth = RALLOC(double,minfo.npairtotal),
          *sth = RALLOC(double,minfo.npairtotal);
    int *mlim = RALLOC(int,minfo.npairtotal);
    for (int i=0; i<minfo.npairtotal; ++i)
      {
      cth[i] = cos(minfo.theta[i]);
      sth[i] = sin(minfo.theta[i]);
      mlim[i] = sharp_get_mlim(lmax, job->spin, sth[i], cth[i]);
      }

    /* map->phase where necessary */
    map2phase (job, minfo.mmax, 0, job->ginfo->npairs);

    map2alm_comm (job, &minfo);

#pragma omp parallel if ((job->flags&SHARP_NO_OPENMP)==0)
{
    sharp_job ljob = *job;
    sharp_Ylmgen_C generator;
    sharp_Ylmgen_init (&generator,lmax,minfo.mmax,ljob.spin);
    alloc_almtmp(&ljob,lmax);

#pragma omp for schedule(dynamic,1)
    for (int mi=0; mi<job->ainfo->nm; ++mi)
      {
  /* alm->alm_tmp where necessary */
      alm2almtmp (&ljob, lmax, mi);

  /* inner conversion loop */
      inner_loop (&ljob, minfo.ispair, cth, sth, 0, minfo.npairtotal,
        &generator, mi, mlim);

  /* alm_tmp->alm where necessary */
      almtmp2alm (&ljob, lmax, mi);
      }

    sharp_Ylmgen_destroy(&generator);
    dealloc_almtmp(&ljob);

#pragma omp critical
    job->opcnt+=ljob.opcnt;
} /* end of parallel region */

    alm2map_comm (job, &minfo);

  /* phase->map where necessary */
    phase2map (job, minfo.mmax, 0, job->ginfo->npairs);

    DEALLOC(mlim);
    DEALLOC(cth);
    DEALLOC(sth);
    DEALLOC(job->norm_l);
    dealloc_phase (job);
    }
  sharp_destroy_mpi_info(&minfo);
  job->time=wallTime()-timer;
  }
示例#4
0
int main(int argc, char** argv)
{

bookType* bt;
int bookCnt = 0, i;
char nullString[]="\0";
char inputFile[FILE_LEN] = {0};
char* inputFolder = nullString;
char* timeFile = nullString;
char* outputFile = nullString;
double* simMat;

int nprocs, myrank, error;



double timeStart, timeMid, timeEnd, timeElapsed;
double timeParaElapsed, timeSerialElapsed, timeParaEnd, timeParaStart;
int initSecond;

int ntag = 100;
MPI_Status status;


MPI_Init(&argc, &argv);
struct timeval init_tv;
gettimeofday(&init_tv, (struct timezone*)0);
initSecond = init_tv.tv_sec;

// record the start time
wallTime( &timeStart, &initSecond);

//////////////////////////
// Argument process
commandLineFlagType flag[] =
 {
 {"inputFolder", _string,  &inputFolder },
 {"timeFile",       _string, &timeFile },
 {"outputFile",      _string, &outputFile },
 };


// set the number of processes


int numFlags = sizeof ( flag ) / sizeof ( commandLineFlagType );
usageErrorType parseErrorCode = parseArgs ( argc, argv, numFlags, flag ) ;

if ( parseErrorCode == argError  || parseErrorCode == parseError )
{
 usage( argv[0] );
 return ( 1 );
}

// make sure the "inputFolder" contains a "/" in the end
if (inputFolder[strlen(inputFolder) - 1] != '/')
{
  char* tmpIF = (char*) malloc(strlen(inputFolder)+2);
  strcpy(tmpIF, inputFolder);
  strcat(tmpIF, "/");
  inputFolder = tmpIF;
}

error = MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
error = MPI_Comm_rank(MPI_COMM_WORLD, &myrank);


  wallTime( &timeParaStart, &initSecond);
  // word load shared among nprocs nodes, all nodes work parallelly
  struct dirent *dir;
  char *filename;
  DIR* d;

  d = opendir(inputFolder);
  if (d)
  {

  while ((dir = readdir(d)) != NULL)
  {
    if (dir->d_type == DT_REG)
    {
      bookCnt ++;
      i = bookCnt % nprocs;
      if (i == myrank)
      {
        strcpy(inputFile, dir->d_name);
	
	 bt = (bookType*) malloc(sizeof(bookType));
	 memset(bt, 0, sizeof(bookType));

	 bt->fileName = (char*) malloc(strlen(inputFolder) + strlen(inputFile) + 1);
	 strcpy(bt->fileName, inputFolder);
	 strcat(bt->fileName, inputFile);


	 // 2. fill the structs with the desired content (P)
	 CreateFileObjects(bt);

	 // 3. sort the word list according to the word frequency (P)
	 SortWordForBook(bt);
	 // DebugPrintList(bt->wordList);
	 RemoveStopWords(bt);


	char wordFile[FILE_LEN] = {0};	
	sprintf(wordFile, "words/%s.dat", inputFile);
	DebugPrintList(bt->wordList, wordFile);
      }
      // MPI_Send(inputFile, FILE_LEN, MPI_CHAR, i,  ntag, MPI_COMM_WORLD);
      // printf("Node %d sent %s to %d\n", myrank, inputFile, i);
    }
  }
 }
 else
 {
  perror("Folder read error");
  return ERROR_READ;
 }
 closedir(d); 

 wallTime( &timeParaEnd, &initSecond);

 printf("rank=%d np=%d\n", myrank, nprocs);

  // tell node 0 that the work is done
  if (myrank != 0)
  {
	MPI_Send(&myrank, 1, MPI_INT, 0, ntag, MPI_COMM_WORLD);
  }

  if (myrank == 0)
  {
   int numSum = 0;
   int num = 0;

   // wait until all other nodes report
   for (i = 1; i < nprocs; i++)
   {
	MPI_Recv(&num, 1, MPI_INT, i, ntag, MPI_COMM_WORLD, &status);
	numSum += num;
   }
   
   printf("numSum=%d nprocs=%d\n", numSum, nprocs); 

   if (numSum != (nprocs - 1)*(nprocs)/2)
   {
	printf("Some node didn't report\n");
	return 1; 
   }

   wallTime( &timeEnd, &initSecond);

   timeElapsed = timeEnd - timeStart;
   timeParaElapsed = timeParaEnd - timeParaStart;
   timeSerialElapsed = timeElapsed - timeParaElapsed;

   printf("SaveTime(%d): %1f %1f %1f %1f \n", nprocs,  timeStart, timeParaStart, timeParaEnd, timeEnd);

   pSaveRunStat(timeStart, timeEnd, timeElapsed, timeSerialElapsed, timeFile);
  }	

 // all  nodes receive file name 
 // MPI_Recv(inputFile, FILE_LEN, MPI_CHAR, 0, ntag, MPI_COMM_WORLD, &status);

 // printf("Node  %d recv %s (%d)\n", myrank,  inputFile, i);
MPI_Finalize () ; 


return 0;

}
示例#5
0
void Time::start(bool reset_in)
{
  isRunning_ = true;
  if (reset_in) totalTime_ = 0;
  startTime_ = wallTime();
}
示例#6
0
double Time::totalElapsedTime(bool readCurrentTime) const
{
  if(readCurrentTime)
    return wallTime() - startTime_ + totalTime_;
  return totalTime_;
}