YANE-Framework Tutorial 1.1.0

examples/parallelcomputing/src/simplecomputation.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  * Copyright (C) 2011 by www.nonlinearmpc.com                              *
00004  *                                                                         *
00005  * Authors:                                                                *
00006  *  Juergen Pannek <juergen.pannek@googlemail.com>                         *
00007  *  Michael Schamel <michael.schamel@uni-bayreuth.de>                      *
00008  *                                                                         *
00009  ***************************************************************************/
00010 
00011 #include "simplecomputation.h"
00012 #include <yane/utils.h>
00013 
00014 #include <string>
00015 #include <sstream>
00016 #include <iostream>
00017 
00018 using namespace std;
00019 using namespace yane::Utils;
00020 
00021 // Constructor
00022 SimpleComputation::SimpleComputation ( const std::string & name,
00023         DebugMaster * dm, int threads ) :
00024         ParallelComputing ( name, dm, threads )
00025 {
00026 }
00027 
00028 // Compute
00029 void SimpleComputation::compute ( ParallelComputing::T_TASKINFO * task,
00030         DebugClient * debugclient )
00031 {
00032         // Get computation info
00033         T_COMPUTATIONINFO * tmp = ( T_COMPUTATIONINFO * ) task->task_data.ptr;
00034 
00035         if ( debugclient )
00036         {
00037                 stringstream out;
00038                 out << "wait: " << tmp->sleep << " sec.";
00039                 debugclient->sendDebugInfo ( out.str ( ) );
00040         }
00041 
00042         usleep ( ( int ) ( tmp->sleep * 1000000.0 ) );
00043 }
00044