ConsoleSleeperMultiThread.cpp
Go to the documentation of this file.
1 #include "../../src/terralib/Defines.h"
2 #include "ProgressExamples.h"
4 
5 // System
6 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
7  #include <windows.h>
8 #endif
9 
10 // C++ library
11 #include <iostream>
12 
13 // OpenMP
14 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
15  #include <omp.h>
16 #endif
17 
18 #define TOTAL_STEPS 3000
19 #define PART_1 1000
20 #define PART_2 2000
21 
22 #define TOTAL_STEPS_INTERNAL 500
23 
25 {
28  task.setMessage("Console Progress Test");
29 
30  task.useMultiThread(true);
31  task.useTimer(true);
32 
33  #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
34  omp_set_num_threads(omp_get_num_procs());
35  #pragma omp parallel for
36  #endif
37  for(int i = 0; i < TOTAL_STEPS; ++i)
38  {
39  if(task.isActive())
40  {
41  #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
42  Sleep(5);
43  #endif
44 
45  task.pulse();
46  }
47 
48  if(i == PART_1 || i == PART_2)
49  {
50  te::common::TaskProgress taskInternal;
51  taskInternal.setTotalSteps(TOTAL_STEPS_INTERNAL);
52  taskInternal.setMessage("Console Progress Internal Task");
53 
54  for(int i = 0; i < TOTAL_STEPS_INTERNAL; ++i)
55  {
56  if(taskInternal.isActive())
57  {
58  #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
59  Sleep(5);
60  #endif
61 
62  taskInternal.pulse();
63  }
64  }
65  }
66  }
67 }
void ConsoleSleeperMultiThread()
void useMultiThread(bool flag)
Used to define if task is running in thread mode.
void setMessage(const std::string &message)
Set the task message.
This class can be used to inform the progress of a task.
#define PART_2
void useTimer(bool flag)
Used to define if task use progress timer information.
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
These routines show how to use the progress bar.
#define TOTAL_STEPS
bool isActive() const
Verify if the task is active.
void setTotalSteps(int value)
Set the task total stepes.
#define TOTAL_STEPS_INTERNAL
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
#define PART_1