Пример #1
0
int main()
{
  
  boost::asio::io_service io;
  boost::asio::io_service io_enb;

  boost::thread_group threadpool;
  boost::thread_group threadpool_1;


  /*
   *  * This will start the ioService processing loop. All tasks 
   *   * assigned with ioService.post() will start executing. 
   *    */
  boost::asio::io_service::work work(io);
  boost::asio::io_service::work work_1(io_enb);

  /*
   *  * This will add 2 threads to the thread pool. (You could just put it in a for loop)
   *   */
  threadpool.create_thread(
              boost::bind(&boost::asio::io_service::run, &io)
          );
  threadpool.create_thread(
              boost::bind(&boost::asio::io_service::run, &io)
          );


  threadpool_1.create_thread(
              boost::bind(&boost::asio::io_service::run, &io_enb)
          );
  int id1 = 1;
  io_enb.post(boost::bind(work_poster, &io, &id1));
  int id2 = 2;
  io_enb.post(boost::bind(work_poster, &io, &id2));
  int id3 = 3;
  io_enb.post(boost::bind(work_poster, &io, &id3));
  
  threadpool.join_all();
  threadpool_1.join_all();

  return 0;
}
Пример #2
0
/** The central function within each kernel. This function
 *  is called for each measurment step seperately.
 *  @param  mdpv         a pointer to the structure created in bi_init,
 *                       it is the pointer the bi_init returns
 *  @param  problemsize  the actual problemsize
 *  @param  results      a pointer to a field of doubles, the
 *                       size of the field depends on the number
 *                       of functions, there are #functions+1
 *                       doubles
 *  @return 0 if the measurment was sucessfull, something
 *          else in the case of an error
 */
int bi_entry( void* mdpv, int problemsize, double* results )
{
  /* ts, te: the start and end time of the measurement */
  /* timeinsecs: the time for a single measurement in seconds */
  double ts = 0.0, te = 0.0, timeinsecs = 0.0;
  /* flops stores the calculated FLOPS */
  double flops = 0.0;
  /* j is used for loop iterations */
  int j = 0;
  /* cast void* pointer */
  mydata_t* mdp = (mydata_t*)mdpv;

  /* calculate real problemsize */
  problemsize = MIN + ( problemsize - 1 ) * INCREMENT;

  /* check wether the pointer to store the results in is valid or not */
  if ( results == NULL ) return 1;

  /* B ########################################################*/
  /* maybe some init stuff in here */
  mdp->dummy = 0;
  /*########################################################*/

  for ( j = 0; j < n_of_works; j++ )
  {
    /* B ########################################################*/
    int index1 = 0 * n_of_works + j;
    int index2 = 1 * n_of_works + j;
    /* reset of reused values */
    ts = 0.0;
    te = 0.0;
    /* choose version of algorithm */
    switch ( j ) {
      case 1: // 2nd version legend text; maybe (ikj)
        /* take start time, do measurment, and take end time */
        ts = bi_gettime(); work_2(); te = bi_gettime();
        break;
      case 0: // 1st version legend text; maybe (ijk)
      default:
        /* take start time, do measurment, and take end time */
        ts = bi_gettime(); work_1(); te = bi_gettime();
    }
    /* calculate the used time and FLOPS */
    timeinsecs = te - ts;
    timeinsecs -= dTimerOverhead;
    // this flops value is a made up! this calulations should be replaced
    // by something right for the choosen algorithm
    flops = (double)problemsize;
    /* If the operation was too fast to be measured by the timer function,
     * mark the result as invalid */
    if( timeinsecs < dTimerGranularity ) timeinsecs = INVALID_MEASUREMENT;
    /* store the results in results[1], results[2], ...
    * [1] for the first function, [2] for the second function
    * and so on ...
    * the index 0 always keeps the value for the x axis
    */
    /* B ########################################################*/
    // the xaxis value needs to be stored only once!
    if ( j == 0 ) results[0] = (double)problemsize;
    results[index1 + 1] = timeinsecs;
    results[index2 + 1] = flops;
    /*########################################################*/
  }

  return 0;
}