示例#1
0
void
test_tbbt(void)
{
    intn        test_size;
    intn        i, j;
    int32       ins_arr[MAX_TEST_SIZE];
    int32       rem_arr[MAX_TEST_SIZE];
    intn        t;
    TBBT_TREE  *tree;
    VOIDP      *r;

    t = (intn)time(NULL);
    SEED((uintn)t);

    for (test_size = 3; test_size <= MAX_TEST_SIZE; test_size++)
      {
          MESSAGE(7, printf("\nTesting trees with %d elements\n", test_size);
              );
          MESSAGE(8, printf("Testing tree #:");
              );
示例#2
0
文件: conv.c 项目: schwehr/hdf4
void
test_conv(void)
{
    clock_t c1,c2,c3,c4;
    uint8 *src_uint8,
	  *dst_uint8,
	  *dst2_uint8;
    uint16 *src_uint16,
	  *dst_uint16,
	  *dst2_uint16;
    uint32 *src_uint32,
	  *dst_uint32,
	  *dst2_uint32;
    int8 *src_int8,
	  *dst_int8,
	  *dst2_int8;
    int16 *src_int16,
	  *dst_int16,
	  *dst2_int16;
    int32 *src_int32,
	  *dst_int32,
	  *dst2_int32;
    float32 *src_float32,
	  *dst_float32,
	  *dst2_float32;
    float64 *src_float64,
	  *dst_float64,
	  *dst2_float64;
    intn i,r;
    intn t;
    int32 ret;

    SEED((int)time(NULL));   /* seed with effectively random number */

    for(t=0; (size_t)t<sizeof(test_type)/sizeof(int32); t++) {
        MESSAGE(5,printf("Testing %s Number-Types\n",test_name[t]););
        MESSAGE(6,printf("seeding int8 array\n"););
示例#3
0
void RandGen::srand48(long seedval) {
  SEED(X0, LOW(seedval), HIGH(seedval));
}
示例#4
0
int main(int argc, char *argv[]) {
  
  int size;
  int itr;
  void *ptr[BUFLEN];
  int i,j;
  double randvar;
  int fail = 0;
  //size_t global[LOOPCNT][2];
  long int global[LOOPCNT][2];
  
  
  clock_t begin, end;
  double time_spent;
  
  for(j = 0; j < LOOPCNT; j++) {
      global[j][0] = -1;
      global[j][1] = -1;
  }
  
  /* Set the PSEUDO_RANDOM_SEED for pseduo random seed initialization based on time, i.e.,
   * the random values changes after each execution 
   */
  if(PSEUDO_RANDOM_SEED)
    SEED(time(NULL));
  
  assert(MAX_HEAP_SIZE >= 1024*1024 && "MAX_HEAP_SIZE is too low; Recommended setting is at least 1MB for test_stress2");
  
  for(i=0; i < BUFLEN; i++) {
    ptr[i] = NULL;
  }
  
  begin = clock();
  
  for(i = 0; i < LOOPCNT; i++) {
    itr = (int)(RAND() * BUFLEN);
    
    randvar = RAND();
    
    if(randvar < ALLOC_CONST && ptr[itr] == NULL) {
      size = (int)(RAND() * MAX_ALLOC_SIZE);
      if(size > 0) {
	ptr[itr] = dmalloc(size);
	//memset(ptr[itr], 0, size);
      }
      else
	continue;
      if(ptr[itr] == NULL) {
	DEBUG("malloc at iteration %d failed for size %d\n", i,size);
	fflush(stderr);
	++fail;
	continue;
      }
      /* Range check */
      for(j = 0; j < i; j++) {
	if(global[j][0] == -1) {
	  continue;
	}
	if(((long)ptr[itr] >= global[j][0]) && ((long)ptr[itr]+size <= global[j][1])) {
	  printf("[s] = %ld, [e] = %ld, [p] = %ld, [itr] = %d, [size] = %ld\n", global[j][0], global[j][1], (long)ptr[itr], i, (long)size);
	  printf("Correctness check failed\n");
	  exit(EXIT_FAILURE);
	}
      }
      global[i][0] = (long)ptr[itr];
      global[i][1] = (long)ptr[itr] + (long)size;
      printf("Assigned: [s] = %ld, [e] = %ld, [p] = %ld, [itr] = %d, [size] = %ld\n", global[i][0], global[i][1], (long)ptr[itr],i, (long)size);
      
    } else if(randvar >= ALLOC_CONST && ptr[itr] != NULL) {
      DEBUG("Freeing ptr[%d]\n", itr);
      for(j = 0; j < i; j++) {
	if(global[j][0] == (long)ptr[itr]) {
	  global[j][0] = -1;
	  global[j][1] = -1;
	}
      }
      dfree(ptr[itr]);
      ptr[itr] = NULL;
    }
  }
  
  /*
   * now -- free them
   * */
  for(i=0; i < BUFLEN; i++) {
    if(ptr[i] != NULL) {
      dfree(ptr[i]);
      ptr[i] = NULL;
    }
  }
  end = clock();
  
  print_freelist();
  DEBUG("\n");
  time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  
  printf("Test case summary\n");
  printf("Loop count: %d, malloc successful: %d, malloc failed: %d, execution time: %g seconds\n\n", LOOPCNT, LOOPCNT-fail, fail, time_spent);
  
  printf("Stress testcases2 passed!\n");
  return 0;
}
示例#5
0
OP_ERROR
SOP_Rain::cookMySop(OP_Context &context)
{
    //UT_Interrupt    *boss;
    if (error() < UT_ERROR_ABORT)
    {
        //boss = UTgetInterrupt();
        //boss->opStart("Start generating rain");
        
        fpreal now = TIME(context.getTime());
        long nPoints = NPOINTS( now );
        UT_Vector3 rainDirection = RAINDIRECTION(now);
        //rainDirection.normalize(); //TODO: check for (0,0,0) vector

        RainData rain(  now,
                        nPoints, BOUNDMIN (now), BOUNDMAX (now),
                        rainDirection, 
                        DICEMIN(now), DICEMAX(now), SEED(now),
                        SPEED (now),
                        SPEEDVARIENCE (now));

        if(rain.getAllocationState() == false || isPointsNumberChanged_ == true)
        {
            rain.allocate(nPoints);
        }
        if( rain.getAllocationState() == true && 
            ( rain.getCachedState() == false || isParameterChanged_ == true ) )
        {   
            rain.computeInitialPositions();
            rain.setCachedState(true);     
        }

        if (isPointsGenerated_ == false)
        {
            printf("Generate Points procedure\n");
            gdp->clearAndDestroy();

            generatePoints(gdp, nPoints);
            isPointsGenerated_ = true;
        }
        

        for (   GA_Iterator pr_it(gdp->getPrimitiveRange());
                !pr_it.atEnd();
                ++pr_it)
        {
            GEO_Primitive* prim = gdp->getGEOPrimitive(*pr_it);
            GA_Range range = prim->getPointRange();
            rain.shiftPositions( gdp, range);            
        }


     

        //boss->opEnd();
    }
    isParameterChanged_ = false;
    isPointsNumberChanged_ = false;
    //unlockInputs();
    return error();
}
示例#6
0
OP_ERROR
SOP_Ocean::cookMySop(OP_Context &context)
{
    float now = context.getTime();

    //std::cout << "cook ocean, t = " << now << std::endl;

    // lock inputs
    if (lockInputs(context) >= UT_ERROR_ABORT )
    {
        return error();
    }


    GEO_Point		*ppt;
    UT_Interrupt	*boss;

    // Check to see that there hasn't been a critical error in cooking the SOP.
    if (error() < UT_ERROR_ABORT)
    {
        boss = UTgetInterrupt();

        // Start the interrupt server
        boss->opStart("Updating Ocean");

        duplicatePointSource(0,context);

        int   gridres  = 1 << int(GRID_RES(now));
        float stepsize = GRID_SIZE(now) / (float)gridres;

        bool do_chop     = CHOP(now);
        bool do_jacobian = JACOBIAN(now);
        bool do_normals  = NORMALS(now) && !do_chop;

        if (!_ocean || _ocean_needs_rebuild)
        {
            if (_ocean)
            {
                delete _ocean;
            }

            if (_ocean_context)
            {
                delete _ocean_context;
            }

            _ocean = new drw::Ocean(gridres,gridres,stepsize,stepsize,
                                    V(0),L(0),1.0,W(0),1-DAMP(0),ALIGN(0),
                                    DEPTH(0),SEED(0));
            _ocean_scale   = _ocean->get_height_normalize_factor();

            _ocean_context = _ocean->new_context(true,do_chop,do_normals,do_jacobian);

            _ocean_needs_rebuild = false;
//             std::cout << "######### SOP, rebuilt ocean, norm_factor = " << _ocean_scale 
//                       << " chop = " << do_chop 
//                       << " norm = " << do_normals
//                       << " jacobian = " << do_jacobian
//                       << std::endl;
        }

        float chop_amount = CHOPAMOUNT(now);

        // sum up the waves at this timestep
        _ocean->update(TIME(now),*_ocean_context,true,do_chop,do_normals,do_jacobian,
                       _ocean_scale * SCALE(now),chop_amount);

        bool linterp = ! INTERP(now);


        // get our attribute indices
        GA_RWAttributeRef normal_index;
        GA_RWAttributeRef jminus_index;
        GA_RWAttributeRef eminus_index;

        if (do_normals)
        {
            normal_index = gdp->addNormalAttribute(GEO_POINT_DICT);
        }
        if (do_jacobian)
        {
            // jminus_index = gdp->addPointAttrib("mineigval",sizeof(float),GB_ATTRIB_FLOAT,0);
            // eminus_index = gdp->addPointAttrib("mineigvec",sizeof(UT_Vector3),GB_ATTRIB_VECTOR,0);
            jminus_index = gdp->addTuple(GA_STORE_REAL32,GA_ATTRIB_POINT,"mineigval",1,GA_Defaults(0));
            eminus_index = gdp->addFloatTuple(GA_ATTRIB_POINT,"mineigvec",1,GA_Defaults(0));
        }

        // this is not that fast, can it be done quicker ???
        GA_FOR_ALL_GPOINTS(gdp, ppt)
            {
                UT_Vector4 p = ppt->getPos();

                
                if (linterp)
                {
                    _ocean_context->eval_xz(p(0),p(2));
                }
                else
                {
                    _ocean_context->eval2_xz(p(0),p(2));
                }

                if (do_chop) 
                {
                    p.assign( p(0) + _ocean_context->disp[0],
                              p(1) + _ocean_context->disp[1],
                              p(2) + _ocean_context->disp[2] );
                }
                else
                {
                    // ppt->getPos()(1) += _ocean_context->disp[1];
                	UT_Vector4 tmp_p = ppt->getPos();
                	tmp_p(1) += _ocean_context->disp[1];
                	ppt->setPos(tmp_p);
                }

                if (do_normals)
                {
                	/*
					  UT_Vector3* normal = (UT_Vector3*) ppt->castAttribData<UT_Vector3>(normal_index);
					  normal->assign(_ocean_context->normal[0],
					                 _ocean_context->normal[1],
					                 _ocean_context->normal[2]);
					  normal->normalize();
                    */
                	ppt->getValue<UT_Vector3>(normal_index).assign(_ocean_context->normal[0],
																   _ocean_context->normal[1],
																   _ocean_context->normal[2]);
                	ppt->getValue<UT_Vector3>(normal_index).normalize();
                }

                if (do_jacobian)
                {/*
                    float *js = (float*)ppt->castAttribData<float>(jminus_index);
                    *js = _ocean_context->Jminus;
                    UT_Vector3* eminus = (UT_Vector3*)ppt->castAttribData<UT_Vector3>(eminus_index);
                    eminus->assign(_ocean_context->Eminus[0],0,_ocean_context->Eminus[1]);
                    */
                    ppt->setValue<float>(jminus_index,_ocean_context->Jminus);
                    ppt->getValue<UT_Vector3>(eminus_index).assign(_ocean_context->Eminus[0],0,_ocean_context->Eminus[1]);
                }
				ppt->setPos(p);
            }
示例#7
0
OP_ERROR aaOceanSOP::cookMySop(OP_Context &context)
{
    if (lockInputs(context) >= UT_ERROR_ABORT)
        return error();

    duplicateSource(0, context);
    setVariableOrder(3, 2, 0, 1);
    setCurGdh(0, myGdpHandle);
    setupLocalVars();

    // variable declarations
    float now  = context.getTime();

    // Flag the SOP as being time dependent (i.e. cook on time changes)
    flags().timeDep = 1;
    
    // start pulling in SOP inputs and send to aaOcean 
    enableEigens = (ENABLEEIGENS() != 0);
    if(pOcean->isChoppy() && enableEigens)
        enableEigens = TRUE;
    now = now + TIMEOFFSET(now);

    pOcean->input(  RESOLUTION(), 
                    SEED(),
                    OCEANSCALE(now),
                    OCEANDEPTH(now),
                    SURFACETENSION(now),
                    VELOCITY(now), 
                    CUTOFF(now), 
                    WINDDIR(now), 
                    WINDALIGN(), 
                    DAMP(now), 
                    WAVESPEED(now), 
                    WAVEHEIGHT(now),
                    CHOP(now), 
                    now,
                    LOOPTIME(now),
                    enableEigens,
                    FALSE);

    // get the user-specified attribute that holds uv-data
    getUVAttributeName(UvAttribute);
    if(UvAttribute.length() == 0)
        UvAttribute = "uv";
    const char* UVAttribName = (const char *)UvAttribute;
    uvRef = gdp->findFloatTuple(GA_ATTRIB_POINT, UVAttribName, 3);

    if(uvRef.isValid() == TRUE)
    {
        uvAttribute = uvRef.getAttribute();
        uvTuple = uvRef.getAIFTuple(); 
    }
    else
    {
        // uv attribute not found
        char msg[256];
        sprintf(msg, "[aaOcean] Specified UV attribute \'%s\' not found on geometry.\
                     \nUV's are required for aaOcean to cook", UVAttribName);
        std::cout<<msg;
        std::cout.flush();
        addError(SOP_MESSAGE, msg); 
        unlockInputs();
        return error();
    }

    // setup local variables to output Eigens
    if(enableEigens)
    {
        eVecPlusRef  = gdp->addFloatTuple(GA_ATTRIB_POINT, eVecPlusName,    3);
        eVecMinusRef = gdp->addFloatTuple(GA_ATTRIB_POINT, eVecMinusName,   3);
        eValuesRef   = gdp->addFloatTuple(GA_ATTRIB_POINT, eValuesName,     1);

        eVecPlusHandle  = GA_RWHandleV3(eVecPlusRef.getAttribute());
        eVecMinusHandle = GA_RWHandleV3(eVecMinusRef.getAttribute());
        eValuesHandle   = GA_RWHandleF(eValuesRef.getAttribute());
    }
    
    // inputs validated. Begin writing ocean data to output handles
    int npts = gdp->getNumPoints();
    #pragma omp parallel for 
    for (int pt_offset = 0; pt_offset < npts; ++pt_offset)
    {
        UT_Vector3F pos = gdp->getPos3(pt_offset);
        UT_Vector3F UV;
        
        uvTuple->get(uvAttribute, pt_offset, UV.data(), 3);
        // Houdini V coord runs in opposite direction compared to Softimage/Maya
        // Conforming with other apps to make ocean shape consistent across apps
        float u = UV.x();
        float v = 1.0f - (fmod(UV.y(), 1.0f));

        pos.y() += pOcean->getOceanData(u, v, aaOcean::eHEIGHTFIELD);
        if(pOcean->isChoppy())
        {
            pos.x() += pOcean->getOceanData(u, v, aaOcean::eCHOPX);
            pos.z() += pOcean->getOceanData(u, v, aaOcean::eCHOPZ);
        }
        gdp->setPos3(pt_offset, pos);

       if(enableEigens)
        {
            UT_Vector3F eigenVectorPlusValue;
            UT_Vector3F eigenVectorMinusValue;
            float eigenValue;

            eigenVectorPlusValue.x() =  pOcean->getOceanData(u, v, aaOcean::eEIGENPLUSX);
            eigenVectorPlusValue.y() =  0.0f;
            eigenVectorPlusValue.z() =  pOcean->getOceanData(u, v, aaOcean::eEIGENPLUSZ);

            eigenVectorMinusValue.x() = pOcean->getOceanData(u, v, aaOcean::eEIGENMINUSX);
            eigenVectorMinusValue.y() = 0.0f;
            eigenVectorMinusValue.z() = pOcean->getOceanData(u, v, aaOcean::eEIGENMINUSZ);

            eigenValue = pOcean->getOceanData(u, v, aaOcean::eFOAM);

            eVecPlusHandle.set(pt_offset,eigenVectorPlusValue);
            eVecMinusHandle.set(pt_offset,eigenVectorMinusValue);
            eValuesHandle.set(pt_offset,eigenValue);
        }
    }
    unlockInputs();

    return error();
}