src/os.cc
// Generic CPU stress workload that would work on any CPU/Platform.
// Float-point array moving average calculation.
Generic CPU stress workload that would work on any CPU/Platform.
Float-point array moving average calculation.
Generic CPU stress workload that would work on any CPU / Platform . Float - point array moving average calculation .
bool OsLayer::CpuStressWorkload() {
  double float_arr[100];
  double sum = 0;
  unsigned int seed = 12345;
  for (int i = 0; i < 100; i++) {
#ifdef HAVE_RAND_R
    float_arr[i] = rand_r(&seed);
    if (rand_r(&seed) % 2)
      float_arr[i] *= -1.0;
#else
    float_arr[i] = rand();
    if (rand() % 2)
      float_arr[i] *= -1.0;
#endif
  }
  for (int i = 0; i < 100000000; i++) {
    float_arr[i % 100] =
      (float_arr[i % 100] + float_arr[(i + 1) % 100] +
       float_arr[(i + 99) % 100]) / 3;
    sum += float_arr[i % 100];
  }
  if (sum == 0.0)
    logprintf(12, "Log: I'm Feeling Lucky!\n");
  return true;
}
bool OsLayer :: CpuStressWorkload ( ) { double float_arr [ 100 ] ; double sum = 0 ; unsigned int seed = 12345 ; for ( int i = 0 ; i < 100 ; i ++ ) { #ifdef HAVE_RAND_R float_arr [ i ] = rand_r ( & seed ) ; if ( rand_r ( & seed ) % 2 ) float_arr [ i ] *= -1.0 ; #else float_arr [ i ] = rand ( ) ; if ( rand ( ) % 2 ) float_arr [ i ] *= -1.0 ; #endif } for ( int i = 0 ; i < 100000000 ; i ++ ) { float_arr [ i % 100 ] = ( float_arr [ i % 100 ] + float_arr [ ( i + 1 ) % 100 ] + float_arr [ ( i + 99 ) % 100 ] ) / 3 ; sum += float_arr [ i % 100 ] ; } if ( sum == 0.0 ) logprintf ( 12 , " \n " ) ; return true ; }
Generic CPU stress workload that would work on any CPU/Platform.
Generic CPU stress workload that would work on any CPU / Platform .
// Initialize array with random numbers. // Calculate moving average. // Artificial printf so the loops do not get optimized away.