Exemple #1
0
int main(int argc,char **argv)
{
	if(argc < 2)
	{
		fprintf(stderr,"Usage...\n");
		exit(1);
	}
	
	printf("%lld\n",mydu(argv[1])/2);

	exit(0);
}
Exemple #2
0
inline void
time_step_parallel(zfp::array2d& u, const Constants& c)
{
#ifdef _OPENMP
  // flush shared cache to ensure cache consistency across threads
  u.flush_cache();
  // compute du/dt in parallel
  zfp::array2d du(c.nx, c.ny, u.rate(), 0, u.cache_size());
  #pragma omp parallel
  {
    // create read-only private view of entire array u
    zfp::array2d::private_const_view myu(&u);
    // create read-write private view into rectangular subset of du
    zfp::array2d::private_view mydu(&du);
    mydu.partition(omp_get_thread_num(), omp_get_num_threads());
    // process rectangular region owned by this thread
    for (uint j = 0; j < mydu.size_y(); j++) {
      int y = mydu.global_y(j);
      if (1 <= y && y <= c.ny - 2)
        for (uint i = 0; i < mydu.size_x(); i++) {
          int x = mydu.global_x(i);
          if (1 <= x && x <= c.nx - 2) {
            double uxx = (myu(x - 1, y) - 2 * myu(x, y) + myu(x + 1, y)) / (c.dx * c.dx);
            double uyy = (myu(x, y - 1) - 2 * myu(x, y) + myu(x, y + 1)) / (c.dy * c.dy);
            mydu(i, j) = c.dt * c.k * (uxx + uyy);
          }
        }
    }
    // compress all private cached blocks to shared storage
    mydu.flush_cache();
  }
  // take forward Euler step in serial
  for (uint i = 0; i < u.size(); i++)
    u[i] += du[i];
#endif
}
Exemple #3
0
int64_t mydu(const char *path)
{// ../a/b/c/d/e
	struct stat statres;
	char nextpath[PATHSIZE];
	glob_t globres;
	int i;
	int64_t sum = 0;

	if(lstat(path,&statres) < 0)
	{
		perror("lstat()");
		exit(1);
	}

	if(!S_ISDIR(statres.st_mode))
		return statres.st_blocks;

	// is a dir
	// "../a/b/c/d/e/*"  "../a/b/c/d/e/.*"

	strncpy(nextpath,path,PATHSIZE);
	strncat(nextpath,"/*",PATHSIZE);
	glob(nextpath,0,NULL,&globres);
	/*if error*/

	strncpy(nextpath,path,PATHSIZE);
    strncat(nextpath,"/.*",PATHSIZE);
	glob(nextpath,GLOB_APPEND,NULL,&globres); 

    for(i = 0 ; i < globres.gl_pathc; i++)
	{
		if(path_noloop(globres.gl_pathv[i]))
        	sum += mydu(globres.gl_pathv[i]);
	}
	sum += statres.st_blocks;

	return sum;
}