示例#1
0
文件: main.cpp 项目: 20-sim/bullet3
void boundSearchTest( )
{
	TEST_INIT;

	int maxSize = 1024*256;
	int bucketSize = 256;

	b3OpenCLArray<b3SortData> srcCL(g_context,g_queue,maxSize);
	b3OpenCLArray<unsigned int> upperCL(g_context,g_queue,maxSize);
	b3OpenCLArray<unsigned int> lowerCL(g_context,g_queue,maxSize);
	
	b3AlignedObjectArray<b3SortData> srcHost;
	b3AlignedObjectArray<unsigned int> upperHost;
	b3AlignedObjectArray<unsigned int> lowerHost;
	b3AlignedObjectArray<unsigned int> upperHostCompare;
	b3AlignedObjectArray<unsigned int> lowerHostCompare;
	
	b3BoundSearchCL* search = new b3BoundSearchCL(g_context,g_device,g_queue, maxSize);


	int dx = maxSize/NUM_TESTS;
	for(int iter=0; iter<NUM_TESTS; iter++)
	{
		
		int size = b3Min( 128+dx*iter, maxSize );

		upperHost.resize(bucketSize);
		lowerHost.resize(bucketSize);
		upperHostCompare.resize(bucketSize);
		lowerHostCompare.resize(bucketSize);

		srcHost.resize(size);

		for(int i=0; i<size; i++) 
		{
			b3SortData v;
//			v.m_key = i<2? 0 : 5;
			v.m_key = getRandom(0,bucketSize);

			v.m_value = i;
			srcHost.at(i) = v;
		}

		srcHost.quickSort(b3SortDataCompare());
		srcCL.copyFromHost(srcHost);

		{
			
			for(int i=0; i<bucketSize; i++) 
			{
				lowerHost[i] = -1;
				lowerHostCompare[i] = -1;
				upperHost[i] = -1;
				upperHostCompare[i] = -1;
			}
			upperCL.copyFromHost(upperHost);
			lowerCL.copyFromHost(lowerHost);
		}

		search->execute(srcCL,size,upperCL,bucketSize,b3BoundSearchCL::BOUND_UPPER);
		search->execute(srcCL,size,lowerCL,bucketSize,b3BoundSearchCL::BOUND_LOWER);

		search->executeHost(srcHost,size,upperHostCompare,bucketSize,b3BoundSearchCL::BOUND_UPPER);
		search->executeHost(srcHost,size,lowerHostCompare,bucketSize,b3BoundSearchCL::BOUND_LOWER);

		lowerCL.copyToHost(lowerHost);
		upperCL.copyToHost(upperHost);
		for(int i=0; i<bucketSize; i++)
		{
			TEST_ASSERT(upperHostCompare[i] == upperHost[i]);
			TEST_ASSERT(lowerHostCompare[i] == lowerHost[i]);
		}
		/*
		for(int i=1; i<bucketSize; i++)
		{
			int lhi_1 = lowerHost[i-1];
			int lhi = lowerHost[i];

			for(int j=lhi_1; j<lhi; j++)
			//for(int j=lowerHost[i-1]; j<lowerHost[i]; j++)
			{
				TEST_ASSERT( srcHost[j].m_key < i );
			}
		}

		for(int i=0; i<bucketSize; i++)
		{
			int jMin = (i==0)?0:upperHost[i-1];
			for(int j=jMin; j<upperHost[i]; j++)
			{
				TEST_ASSERT( srcHost[j].m_key <= i );
			}
		}
		*/


		for(int i=0; i<bucketSize; i++)
		{
			int lhi = lowerHost[i];
			int uhi = upperHost[i];

			for(int j=lhi; j<uhi; j++)
			{
				if ( srcHost[j].m_key != i )
				{
					printf("error %d != %d\n",srcHost[j].m_key,i);
				}
				TEST_ASSERT( srcHost[j].m_key == i );
			}
		}

	}

	delete search;

	TEST_REPORT( "boundSearchTest" );
}
示例#2
0
文件: xov.c 项目: EvolBioInf/hotspot
void scanFile(Args *args, FILE *fp){
  char *line, *name, *token, *chr;
  size_t n;
  int status, len, l, start, end;
  int pos[2], p, i, tp, tn;
  Data *data;
  double ll, ul, cf;

  line = NULL;
  while((status = getline(&line,&n,fp)) != -1){
    if(line[0] != '#')
      break;
  }
  if(!args->p)
    printf("# Int\tChr\tStart\tEnd\tLen\t[%%\t%%\t%%]\t[cM/Mb\tcM/Mb\tcM/Mb]\n");
  data = newData(1,args->o);
  while(status != -1){
    data->n = 0;
    name = estrdup(strtok(line,"\t")); /* read name of region */
    chr = estrdup(strtok(NULL,"\t"));  /* read chromosome */
    start = intVal(strtok(NULL,"\t")); /* start position */
    end = intVal(strtok(NULL,"\t"));   /* end position */
    len = end - start + 1;             /* length of region in bp */
    tp = 0; /* total positives */
    tn = 0; /* total negatives */
    while((token = strtok(NULL,"\t")) != NULL){ /* iterating across experiments */
      if(data->n + 1 == data->maxN)
	expandData(data);
      l = strlen(token);
      p = 0;
      for(i=0;i<l;i++){  /* determine positions of commata */
	if(token[i] == '|'){
	  token[i] = '\0';
	  pos[p++] = i+1;
	}
      }
      data->numMol[data->n] = atoi(token); /* number of molecules */
      token += pos[0];
      data->numPos[data->n] = atoi(token);
      token -= pos[0];
      token += pos[1];
      data->numNeg[data->n] = atoi(token);
      token -= pos[1];
      tp += data->numPos[data->n];
      tn += data->numNeg[data->n];
      data->n++;
    }
    if(args->d){
      printData(name,len,data);
      exit(0);
    }
    if(args->p && tp){
      printLikFun(data, args);
      return;
    }
    cf = crossoverFreq(data);
    data->mlXover = cf;
    data->ci = args->c;
    ul = upperCL(data,cf);
    ll = lowerCL(data,cf);
    /* convert to centi-Morgans */
    ll *= 100;
    cf *= 100;
    ul *= 100;
    if(cf < 100){
      printf("%s\t%s\t%d\t%d\t%*d\t%.3f\t%.3f\t%.3f",name,chr,start,end,4,len,ll,cf,ul);
      /* convert to cM per Mb */
      ll = ll / len * 1000000;
      cf = cf / len * 1000000;
      ul = ul / len * 1000000;
      printf("\t%.3f\t%.3f\t%.3f\n",ll,cf,ul);
    }else
      printf("%s\t%d\t%d\t%*d\tNA\tNA\tNA\tNA\tNA\tNA\n",name,start,end,4,len);
    status = getline(&line,&n,fp);
    free(name);
  } 
  free(line);
  freeData(data);
}