예제 #1
0
void BufferInterface::transferData(bool fromSystemToDevice)throw(BufferException)
{
	assert( "CPU buffer must exist for transfer between host and device" && mCPU_Handle);

	if(
		( hasBufferInContext(OPEN_GL_CONTEXT_TYPE) && PARA_COMP_MANAGER->graphicsAreInControl() )
		||
		! (hasBufferInContext(OPEN_CL_CONTEXT_TYPE))
	)
	{
		//commented out the guard in case of driver bugs fu**ing up when doing too mush time-shared CL-GL-stuff
		//TODO uncomment when stable work is assured
		//if(isCLGLShared())
		{
			PARA_COMP_MANAGER->acquireSharedBuffersForGraphics();
		}

		GUARD(bindGL());
		if(fromSystemToDevice)
		{
			GUARD(writeGL(mCPU_Handle));
		}
		else
		{
			GUARD(readGL(mCPU_Handle));
		}
		return;
	}

	if(
		( hasBufferInContext(OPEN_CL_CONTEXT_TYPE) && PARA_COMP_MANAGER->computeIsInControl() )
		||
		! (hasBufferInContext(OPEN_GL_CONTEXT_TYPE))
	)
	{
		//commented out the guard in case of driver bugs fu**ing up when doing too mush time-shared CL-GL-stuff
		//TODO uncomment when stable work is assured
		//if(isCLGLShared())
		{
			PARA_COMP_MANAGER->acquireSharedBuffersForCompute();
		}

		if(fromSystemToDevice)
		{
			GUARD(writeCL(mCPU_Handle));
		}
		else
		{
			GUARD(readCL(mCPU_Handle));
		}
		return;
	}

	throw(BufferException("BufferInterface::readBack(): need at least one GL or GL usage context in Buffer"));
}
예제 #2
0
파일: realSFS.old.cpp 프로젝트: ANGSD/angsd
int main_2dsfs(int argc,char **argv){
  if(argc==1){
    fprintf(stderr,"./emOptim2 2dsfs pop1 pop2 nChr1 nChr2 [-start FNAME -P nThreds -tole tole -maxIter ] (only works if the two saf files covers the same region)\n");
    return 0;
  }
  argv++;
  argc--;
  fname1 = *(argv++);
  fname2 = *(argv++);
  argc -=2;
  chr1 = atoi(*(argv++));
  chr2 = atoi(*(argv++));
  argc -=2;
  getArgs(argc,argv);
  if(nSites==0){
    if(fsize(fname1)+fsize(fname2)>getTotalSystemMemory())
      fprintf(stderr,"Looks like you will allocate too much memory, consider starting the program with a lower -nSites argument\n");
    //this doesnt make sense if ppl supply a filelist containing safs
     nSites=calcNsites(fname1,chr1);
  }
  fprintf(stderr,"fname1:%sfname2:%s chr1:%d chr2:%d startsfs:%s nThreads=%d tole=%f maxIter=%d nSites:%lu\n",fname1,fname2,chr1,chr2,sfsfname,nThreads,tole,maxIter,nSites);
  float bytes_req_megs = nSites*(sizeof(double)*(chr1+1) + sizeof(double)*(chr2+1)+2*sizeof(double*))/1024/1024;
  float mem_avail_megs = getTotalSystemMemory()/1024/1024;//in percentile
  //  fprintf(stderr,"en:%zu to:%f\n",bytes_req_megs,mem_avail_megs);
  fprintf(stderr,"The choice of -nSites will require atleast: %f megabyte memory, that is approx: %.2f%% of total memory\n",bytes_req_megs,bytes_req_megs*100/mem_avail_megs);
  
#if 0
  //read in positions, not used, YET...
  std::vector<int> p1 = getPosi(fname1);
  std::vector<int> p2 = getPosi(fname2);
  fprintf(stderr,"nSites in pop1: %zu nSites in pop2: %zu\n",p1.size(),p2.size());
#endif

  if(nSites==0){
    if(calcNsites(fname1,chr1)!=calcNsites(fname2,chr2)){
      fprintf(stderr,"Problem with number of sites in file: %s and %s\n",fname1,fname2);
      exit(0);
    }
    nSites=calcNsites(fname1,chr1);
  }
  gzFile gz1=getGz(fname1);
  gzFile gz2=getGz(fname2);
  
  dim=(chr1+1)*(chr2+1);
  
  Matrix<double> GL1=alloc(nSites,chr1+1);
  Matrix<double> GL2=alloc(nSites,chr2+1);
  dim=GL1.y*GL2.y;
  
  double *sfs = new double[dim];
  while(1){
    if(isList ==0){
      readGL(gz1,nSites,chr1,GL1);
      readGL(gz2,nSites,chr2,GL2);
    }else{
      readGL2(gz1,nSites,chr1,GL1);
      readGL2(gz2,nSites,chr2,GL2);
    }
      
    assert(GL1.x==GL2.x);
    if(GL1.x==0)
      break;
    
    if(sfsfname!=NULL){
      readSFS(sfsfname,dim,sfs);
    }else{
      for(int i=0;i<dim;i++)
	sfs[i] = (i+1)/((double)dim);
      normalize(sfs,dim);
    }
    
    setThreadPars(&GL1,&GL2,sfs,nThreads);
    if(calcLike==0){
      if(SIG_COND) 
	em2(sfs,&GL1,&GL2,tole,maxIter);
    }
    double lik;
    if(nThreads>1)
      lik = lik1_master();
    else
      lik = lik1(sfs,&GL1,0,GL1.x);
      
    fprintf(stderr,"likelihood: %f\n",lik);
#if 1
    int inc=0;
    for(int x=0;x<chr1+1;x++){
      for(int y=0;y<chr2+1;y++)
	fprintf(stdout,"%f ",log(sfs[inc++]));
      fprintf(stdout,"\n");
    }
#endif
    if(isList==1)
      break;
  }
  dalloc(GL1,nSites);
  dalloc(GL2,nSites);
  gzclose(gz1);
  gzclose(gz2);
  return 0;
}
예제 #3
0
파일: realSFS.old.cpp 프로젝트: ANGSD/angsd
int main_1dsfs(int argc,char **argv){
  if(argc<2){
    fprintf(stderr,"Must supply afile.saf and number of chromosomes\n");
    return 0;
  }
  fname1 = *(argv++);
  chr1 = atoi(*(argv++));
  argc-=2;
 
  getArgs(argc,argv);
  dim=chr1+1;
  //hook for new EJ banded version
  if(isNewFormat(fname1))
    return main_1dsfs_v2(fname1,chr1,nSites,nThreads,sfsfname,tole,maxIter);

  if(nSites==0){//if no -nSites is specified
    if(fsize(fname1)>getTotalSystemMemory())
      fprintf(stderr,"Looks like you will allocate too much memory, consider starting the program with a lower -nSites argument\n");
    //this doesnt make sense if ppl supply a filelist containing safs
    nSites=calcNsites(fname1,chr1);
  }
  fprintf(stderr,"fname1:%s nChr:%d startsfs:%s nThreads:%d tole=%f maxIter=%d nSites=%lu\n",fname1,chr1,sfsfname,nThreads,tole,maxIter,nSites);
  float bytes_req_megs = nSites*(sizeof(double)*(chr1+1)+sizeof(double*))/1024/1024;
  float mem_avail_megs = getTotalSystemMemory()/1024/1024;//in percentile
  //  fprintf(stderr,"en:%zu to:%f\n",bytes_req_megs,mem_avail_megs);
  fprintf(stderr,"The choice of -nSites will require atleast: %f megabyte memory, that is approx: %.2f%% of total memory\n",bytes_req_megs,bytes_req_megs*100/mem_avail_megs);

  

  Matrix<double> GL1=alloc(nSites,dim);
  gzFile gz1=getGz(fname1);  
  double *sfs=new double[dim];
  
  while(1) {
    if(isList==0)
      readGL(gz1,nSites,chr1,GL1);
    else
      readGL2(gz1,nSites,chr1,GL1);
    if(GL1.x==0)
      break;
    fprintf(stderr,"dim(GL1)=%zu,%zu\n",GL1.x,GL1.y);
   
    
  
    if(sfsfname!=NULL){
      readSFS(sfsfname,dim,sfs);
    }else{
      
      for(int i=0;i<dim;i++)
	sfs[i] = (i+1)/((double)dim);
      if(doBFGS){
	double ts=1;
	for(int i=0;i<dim-1;i++)
	  ts += 0.01/(1.0+i);
	sfs[0]=1.0/ts;
	for(int i=0;i<dim-1;i++)
	  sfs[i+1]  = (0.01/(1.0+i))/ts;
      }
      normalize(sfs,dim);
    }
    //  em2_smart(sfs2,pops,1e-6,1e3);
    setThreadPars(&GL1,NULL,sfs,nThreads);
    if(calcLike==0){
      if(doBFGS==0) 
	em1(sfs,&GL1,tole,maxIter);
      else
	bfgs(sfs,&GL1);
    }
    double lik;
    if(nThreads>1)
      lik = lik1_master();
    else
      lik = lik1(sfs,&GL1,0,GL1.x);
      
    fprintf(stderr,"likelihood: %f\n",lik);
#if 1
    for(int x=0;x<dim;x++)
      fprintf(stdout,"%f ",log(sfs[x]));
    fprintf(stdout,"\n");
    fflush(stdout);
#endif
    if(isList==1)
      break;
  }
  dalloc(GL1,nSites);
  gzclose(gz1);
  delete [] sfs;
  return 0;
}