Added a small .cpp file (console program) to show how a pipeline is done in OpenMP.

Originally committed to SVN as r2066.
This commit is contained in:
Rodrigo Braz Monteiro 2008-03-16 00:32:42 +00:00
parent da0a10ce99
commit 0a0f383b4a
3 changed files with 59 additions and 3 deletions

View file

@ -0,0 +1,55 @@
#include <iostream>
#include <omp.h>
double wasteTime(double in)
{
double accum = in;
for (size_t i=0;i<5000000;i++) {
accum = accum + accum/2.0 - accum/3.0;
}
return accum;
}
int main()
{
using namespace std;
cout << "OpenMP test:\n";
bool run = true;
int n = 0;
omp_set_num_threads(8);
#pragma omp parallel shared(run,n)
{
while (run) {
int myTask;
double lol = 0.0;
#pragma omp critical (secA)
{
myTask = n;
n++;
if (myTask >= 50) run = false;
if (run) {
cout << "Thread #" << omp_get_thread_num() << " on task " << myTask << "/1.\n";
lol -= wasteTime(myTask * 1.0);
cout << "Thread #" << omp_get_thread_num() << " got " << lol << " on task " << myTask << "/1. Task done.\n";
}
}
if (run) {
#pragma omp critical (secB)
{
cout << "Thread #" << omp_get_thread_num() << " on task " << myTask << "/2.\n";
lol += wasteTime(myTask * 2.0);
cout << "Thread #" << omp_get_thread_num() << " got " << lol << " on task " << myTask << "/2. Task done.\n";
}
#pragma omp critical (secC)
{
cout << "Thread #" << omp_get_thread_num() << " on task " << myTask << "/3.\n";
lol -= wasteTime(myTask * 3.0);
cout << "Thread #" << omp_get_thread_num() << " finished task " << myTask << " with the useless result of " << lol << "\n";
}
}
}
}
}

View file

@ -40,8 +40,8 @@
#include "text_file_reader.h"
#include "text_file_writer.h"
int main() {
int main()
{
using namespace std;
using namespace Gorgonsub;
@ -60,7 +60,7 @@ int main() {
// Load subtitles
cout << "Loading file... ";
timer.Start();
control.LoadFile(L"subs_in.ass",L"UTF-16LE");
control.LoadFile(L"subs_in.ass",L"UTF-8");
timer.Pause();
cout << "Done in " << timer.Time() << " ms.\n";
//system("pause");

View file

@ -120,6 +120,7 @@
AdditionalIncludeDirectories="../include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
RuntimeLibrary="2"
OpenMP="false"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="true"