コード例 #1
0
ファイル: bins.c プロジェクト: BenWibking/tpacf
void binReduce(bin bins[]){

/*  Coordinates the combining of bin counts for distributed processes	*
 *									*
 *  In:	 Process's local array of bins					*
 *	 Number of bins							*
 *	 Number of samples						*
 *									*	
 *  Out: Combined bin counts in process 0's array of bins		*/

	int i,j,Nsp1,Nbp1,index;
	unsigned long long int *Cnts,*Bcnts;
	MPI_Op operator;

	TIMESTART(startTime);
	
	DEBUGPRINT("Entering binReduce\n");

	Nsp1 = NumSamples + 1;
	Nbp1 = NumBins + 1;
	
	Cnts = malloc((Nbp1*Nsp1)*sizeof(unsigned long long int));
	Bcnts = malloc((Nbp1*Nsp1)*sizeof(unsigned long long int)); 
	if(Cnts == NULL || Bcnts == NULL){
		fprintf(stderr,"Failed to allocate memory in binReduce\n");
		return;
	}
	
	for(i=0;i<Nbp1;i++){
		for(j=0;j<=NumSamples;j++){
			index = i*Nsp1 + j;
			Cnts[index] = 0;
			Bcnts[index] = bins[i].Cnt[j];
		}
	}

	MPI_Op_create((MPI_User_function *)long_long_sum,1,&operator);
	MPI_Reduce(&(Bcnts[0]),&(Cnts[0]),Nbp1*Nsp1,MPI_UNSIGNED_LONG_LONG,operator,0,MPI_COMM_WORLD);
	for(i=0;i<Nbp1;i++){
		for(j=0;j<=NumSamples;j++){
			bins[i].Cnt[j] = Cnts[i*Nsp1 + j];
		}
	}
	
	free(Cnts);
	free(Bcnts);

	DEBUGPRINT("Exiting binReduce\n");

	TIMESTOP(wallReduce,startTime);
	
	return;
}
コード例 #2
0
  Color vplIntegrator::Li(LightPath& lightPath, const Ref<BackendScene>& scene, IntegratorState& state)
  {
    /*! Traverse ray. */
    DifferentialGeometry dg;
    //scene->intersector->intersect(lightPath.lastRay);
    rtcIntersect(scene->scene,(RTCRay&)lightPath.lastRay);
    scene->postIntersect(lightPath.lastRay,dg);
    state.numRays++;
    
    Color L = zero;
    const Vector3f wo = -lightPath.lastRay.dir;
    BRDFType directLightingBRDFTypes = (BRDFType)(ALL); 

    /*! Environment shading when nothing hit. */
    if (!lightPath.lastRay)
    {
      if (backplate && lightPath.unbend) {
        const int x = clamp(int(state.pixel.x * backplate->width ), 0, int(backplate->width )-1);
        const int y = clamp(int(state.pixel.y * backplate->height), 0, int(backplate->height)-1);
        L = backplate->get(x, y);
      }
      else {
        if (!lightPath.ignoreVisibleLights)
          for (size_t i=0; i<scene->envLights.size(); i++)
            L += scene->envLights[i]->Le(wo);
      }
      return L;
    }

    /*! face forward normals */
    bool backfacing = false;
    if (dot(dg.Ng, lightPath.lastRay.dir) > 0) {
      backfacing = true; dg.Ng = -dg.Ng; dg.Ns = -dg.Ns;
    }

    /*! Shade surface. */
    CompositedBRDF brdfs;
    if (dg.material) dg.material->shade(lightPath.lastRay, lightPath.lastMedium, dg, brdfs);

    /*! Add light emitted by hit area light source. */
    if (!lightPath.ignoreVisibleLights && dg.light && !backfacing)
      L += dg.light->Le(dg,wo);

    /*! Check if any BRDF component uses direct lighting. */
    bool useDirectLighting = false;
    for (size_t i=0; i<brdfs.size(); i++)
      useDirectLighting |= (brdfs[i]->type & directLightingBRDFTypes) != NONE;

    /*! Direct lighting. Shoot shadow rays to all light sources. */
    if (useDirectLighting)
    {
      for (size_t i=0; i<scene->vpls.size(); i++)
      {
        LightSample ls;
        ls.L = scene->vpls[i].sample(dg, ls.wi, ls.tMax);

        /*! Ignore zero radiance or illumination from the back. */
        //if (ls.L == Color(zero) || ls.wi.pdf == 0.0f || dot(dg.Ns,Vector3f(ls.wi)) <= 0.0f) continue; 
        if (ls.L == Color(zero) || ls.wi.pdf == 0.0f) continue;

        /*! Evaluate BRDF */
        Color brdf = brdfs.eval(wo, dg, ls.wi, ALL);
        if (brdf == Color(zero)) continue;

        /*! Test for shadows. */
        Ray shadowRay(dg.P, ls.wi, dg.error*epsilon, ls.tMax-dg.error*epsilon, lightPath.lastRay.time,dg.shadowMask);
        TIMESTART(stats.atomic.timeRT,rt0);
        rtcOccluded(scene->scene,(RTCRay&)shadowRay);
        TIMESTOP(stats.atomic.timeRT,rt0);
        state.numRays++;
        if (shadowRay) continue;

        /*! Evaluate BRDF. */
        L += ls.L * brdf * rcp(ls.wi.pdf);
      }
    }
    
    return L;
  }
コード例 #3
0
ファイル: hufftest.c プロジェクト: CARV-ICS-FORTH/scoop
int main(int argc, char **argv) {
  PHASH freq = NewHash();
  int freqfid, codefid;
  int nrSource, delta;
  double clk;
  int count = 0;

  INDATA srcFile, compFile;
  
  /* Must be passed the name of a file to compress */
  if(argc < 2) {
    printf("Must give a file to compress\n");
    exit(1);
  }
  TIMESTART(clk);

  initLFIOFile(&srcFile, argv[1]);
  
  /* Read the file, 2 bytes at a time and create the frequency table */
  nrSource = 0;
  while(canFetch(&srcFile, 2)) {
    U16 wrd = fetchWordLE(&srcFile);
    nrSource += 2;
    bumpFrequency(freq, wrd);
  }
  finishIOFile(&srcFile);
  printf("Read %d bytes\n", nrSource);
  /* Open the code and frequency files */
  freqfid = CREAT("huffman.freq");
  codefid = CREAT("huffman.code");
  compressfid = CREAT("huffman.compressed");
  if(freqfid < 0 || codefid < 0 || compressfid < 0) {
    ERROR0(1, "Cannot create frequency and code files\n");
  }
  createCompressTables(freq, freqfid, codefid);
  close(freqfid); close(codefid);
  FreeHash(freq);
  
  /* Now read again and compress */
  initCompressor("huffman.code");
  initLFIOFile(&srcFile, argv[1]);
  outPoint = 0; written = 0;
  startCompress(&writeByte);
  /* Read the file, 2 bytes at a time and compress */
  while(canFetch(&srcFile, 2)) {
    U16 wrd = fetchWordLE(&srcFile);
    writeCompressedSymbol(wrd);
  }
  endCompress();
  flushOut();
  close(compressfid);
  finishIOFile(&srcFile);

  /* Now decompress and compare */
  for(count=0;count<30;count++) {
    initLFIOFile(&compFile, "huffman.compressed");
    initLFIOFile(&srcFile, argv[1]);
    startDecompress();
    delta = nrSource;
    while(delta > 0) {
      int comp = fetchCompressedSymbol(&compFile);
      int src  = fetchWordLE(&srcFile);
      if(src != comp) {
        ERROR3(-1, "Src(%04x) != Comp(%04x) (at offset %d)\n",
               src, comp, nrSource - delta);
      }
      delta -= 2;
    }
    endDecompress(&compFile);
    finishIOFile(&srcFile); finishIOFile(&compFile);
  }
  finalizeCompressor();


  TIMESTOP(clk);
  
  // sm: according to my man pages, the 'l' flag doesn't apply
  // to the 'f' format, which is always a double argument
  printf("Source %d bytes. Compressed %d bytes. Ratio: %5.2f\n",
         nrSource, written, (double)nrSource / (double)written);
  printf("Run hufftest in %8.3fms\n", clk / 1000.0);
  exit (0);
  return 0;
}