473,386 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

What OpenMP brings to C++?

Hello guys,

Looks like this technology is comming along with VS2005. Anybody has an
expirience of using it along with C++? What are the patterns?

Thanks,
Vladimir.
Nov 17 '05 #1
5 3126
With parallel pipelines it will generate faster code (hopefully.)
ben
Hello guys,

Looks like this technology is comming along with VS2005. Anybody has an
expirience of using it along with C++? What are the patterns?

Thanks,
Vladimir.

Nov 17 '05 #2
Hello,

Thanks for your response.
With parallel pipelines it will generate faster code (hopefully.)
ben


I am not sure what the "parallel pipelines" means. The OpenMP 2.0 standard
is mostly talking about "parallel regions".

There is how I see OpenMP in nutshells:
The traditional (Windows) approach to dial with multithreading is based on a
function that are executed in parallel with caller (CreateThread). In OpenMP
to make a piece of code to run in parallel I do not need to move it to a
function and think about marshaling data to this function. I just declare
this region as a parallel, declare thread specific and shared variables and
compiler takes care about the rest. As well now compiler can utilize the
knowledge it gets from my declaration and generate a better code. I see this
as a benefit.

One thing that concerns me is that the OpenMP syntax is kind of noisy and do
not look neutral inside a C++ program.

Another thing is that looks like C++ community does not talk about OpenMP a
lot (or at least I do not see those discussions in comp.lang.c++.moderated
and comp.std.c++), all though several major compiler vendors has been
supporting or are going to support OpenMP. There are talks about making a
library like boost::thread a part of the C++ standard library. So again this
means that OpenMP and traditional approach coexist in parallel and no one
look at OpenMP as a replacement for a traditional approach.

Looks like OpenMP is widely (going to be) supported by compiler vendors
like MS, Intel etc. This big investment on there side kind of contradicts to
the amount of attention this technology gets from C++ community.

So basically my questions boils down to following:
Is OpenMP going to replace traditional approach or this two solutions are
targeting different kind of problems?

Regards,
Vladimir.
Nov 17 '05 #3
Vladimir_petter wrote:
I am not sure what the "parallel pipelines" means. The OpenMP 2.0 standard
is mostly talking about "parallel regions".

There is how I see OpenMP in nutshells:
The traditional (Windows) approach to dial with multithreading is based on a
function that are executed in parallel with caller (CreateThread). In OpenMP
to make a piece of code to run in parallel I do not need to move it to a
function and think about marshaling data to this function. I just declare
this region as a parallel, declare thread specific and shared variables and
compiler takes care about the rest. As well now compiler can utilize the
knowledge it gets from my declaration and generate a better code. I see this
as a benefit.

Yes, OpenMP is an additional multithreading mechanism than the other
provided ones, like .NET multithreading etc.

One thing that concerns me is that the OpenMP syntax is kind of noisy and do
not look neutral inside a C++ program.

Yes, it works with #pragma directives, and I guess this involves less
run-time decisions/overhead, and also are less safe. For example:
#include <vector>

int main()
{
using std::vector;
vector<int>someVec(100);
#pragma omp for
for(vector<int>::size_type i=0; i<someVec.size(); ++i)
someVec[i]=10*i;
}

C:\c>cl /clr temp.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.41013
for Microsoft (R) .NET Framework version 2.00.41013.0
Copyright (C) Microsoft Corporation. All rights reserved.

temp.cpp
Microsoft (R) Incremental Linker Version 8.00.41013
Copyright (C) Microsoft Corporation. All rights reserved.

/out:temp.exe
temp.obj

C:\c>
With this #pragma directive of the OpenMP 2 standard, the programmer
provides the guarantee that each assignment is independent of the other
assignments, and thus the compiler creates separate threads for each
assignment, taking advantage of the possible presence of multiple
processors in a system.
Of course, according to the ISO C++ standard unknown #pragmas are
ignored, and thus the above code has no problem of portability to
compilers that do not support OpenMP:
C:\MinGW\bin\g++.exe -std=c++98 -pedantic-errors -Wall
-fexpensive-optimizations -O3 -ffloat-store -mcpu=pentiumpro temp.cpp -o
temp.exe

temp.cpp: In function `int main()':
temp.cpp:11: warning: ignoring #pragma omp for


However if we make a mistake, boom. :-)
But this really helps very much in hand-tuning, and given the guarantees
we provide to the compiler, there is much room for compile-time
optimisation.
I think that OpenMP should be viewed as separate and supplementary to
the platform multithreading support, that is when we design
multithreading applications, we should not take under consideration
OpenMP, but use it separately when we are writing the code.
But I may miss something, so someone may correct me.

Another thing is that looks like C++ community does not talk about OpenMP a
lot (or at least I do not see those discussions in comp.lang.c++.moderated
and comp.std.c++), all though several major compiler vendors has been
supporting or are going to support OpenMP. There are talks about making a
library like boost::thread a part of the C++ standard library. So again this
means that OpenMP and traditional approach coexist in parallel and no one
look at OpenMP as a replacement for a traditional approach.

Yes!
Looks like OpenMP is widely (going to be) supported by compiler vendors
like MS, Intel etc. This big investment on there side kind of contradicts to
the amount of attention this technology gets from C++ community.

Consider this under the view of the upcoming multicore processors in the
mainstream, due to the end of 2005 - beginning of 2006.
So basically my questions boils down to following:
Is OpenMP going to replace traditional approach or this two solutions are
targeting different kind of problems?

I think they are targeting different levels of multithreading optimisation.

--
Ioannis Vranos
Nov 17 '05 #4
Hello Ioannis,

Thanks for your response,

As I've read in one of the Intel papers one can distinguish to type of
parallelism:
- A "concurrent programming" is the multithreading programming we all got
used to.
- A "parallel programming" is something new for the PC world. So far only
Intel Itanium processor provides this with Explicit Instruction Level
Parallelism.

I can see advantages of using Open MP for "parallel programming" (cause C++
language does not give us any othe way to express this), but I kind of doubt
that it is good for concurrent programming.

In the example you've provided:
#include <vector>

int main()
{
using std::vector;
vector<int>someVec(100);
#pragma omp for
for(vector<int>::size_type i=0; i<someVec.size(); ++i)
someVec[i]=10*i;
}
I can see that this loop can be great deal optimized using parallel
programming (on Itanium), but making this loops parallel using concurrent
programming just does not make sense to me. It simply too expensive to
delegate a single x86 (or x64) "add" instruction in a separate thread. Take
on account that to make it working compiler should generate a function with
a body that would be equal to the parallel region and sometimes generate a
structure to marshal data to execute in an OpenMP thread.
That is one of the things that bothers me a lot. In all OpenMP peppers I've
read so far there are examples like that do not make sense to parallelize in
concurrent program. It is just a waste of CPU.
I think that OpenMP should be viewed as separate and supplementary to the
platform multithreading support, that is when we design multithreading
applications, we should not take under consideration OpenMP, but use it
separately when we are writing the code.
Then where is a criteria what tasks should be solved using OpenMP and which
we solve in the old way?
But I may miss something, so someone may correct me.

Looks like OpenMP is widely (going to be) supported by compiler vendors
like MS, Intel etc. This big investment on there side kind of contradicts
to the amount of attention this technology gets from C++ community.

Consider this under the view of the upcoming multicore processors in the
mainstream, due to the end of 2005 - beginning of 2006.


I do not understand how multicore CPU is related to this problem. As far as
I understand multicore CPU still lives us in the "concurrent programming"
world. You buy one chip, but actually this is 2 CPU in one box. So this
could be well handled in the old fashioned way.
So basically my questions boils down to following:
Is OpenMP going to replace traditional approach or this two solutions
are targeting different kind of problems?

I think they are targeting different levels of multithreading
optimization.


In that case the question is what are the criteria that would help us to
decide which way to choose for a particular problem.

In particularly I do not see Open MP overlap nicely with idea of (IOCP)
thread pool.

Vladimir.
Nov 17 '05 #5
"Vladimir_petter" <vl*****@hotmail.com> wrote in message
news:Oq**************@TK2MSFTNGP15.phx.gbl...
I can see advantages of using Open MP for "parallel programming" (cause C++ language does not give us any othe way to express this), but I kind of doubt that it is good for concurrent programming.
It's providing an important feature that, as far as I know, has only been a
language construct in one language: Occam (for transputers). There, every
compound statement was either PAR or SEQ (IIRC).PAR meant the statements
inside it could be executed in parallel, SEQ that they must be execured in
series. One could nest PAR statements inside SEQ ones and vice versa
I can see that this loop can be great deal optimized using parallel
programming (on Itanium), but making this loops parallel using concurrent
programming just does not make sense to me. It simply too expensive to
delegate a single x86 (or x64) "add" instruction in a separate thread ..[snip] That is one of the things that bothers me a lot. In all OpenMP peppers I've read so far there are examples like that do not make sense to parallelize in concurrent program. It is just a waste of CPU.
It's a (big) hint to the optimizing comiler. If the compiler decides that
parallelization isn't worth it, it won't do it. (In an ideal world...)
In that case the question is what are the criteria that would help us to
decide which way to choose for a particular problem.

In particularly I do not see Open MP overlap nicely with idea of (IOCP)
thread pool.

Vladimir.


You're right, threads are relatively large-scale things when compared to the
parallelizing of loops etc. And I think this is the essence of the answer.
Small-scale parallelization is done by coding in OpenMP or Occam's PAR/SEQ
construct; larger-scale parallelization using threading, multitasking, DCOM,
CORBA etc.

S.
Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Alper AKCAYOZ | last post by:
Hello Esteemed Developers and Experts, I have been using Microsoft Visual C++ .NET for 1 year. During this time, I have searhed some topics over internets. Most of the topics about .NET is...
35
by: GTO | last post by:
I do not believe that C# is the future of C++. I also do not believe that adding two thousand new library functions to the standard library is the future of C++. But what is the future of C++? Is...
1
by: Rodrigo Perottoni | last post by:
I'm trying compiling and running the OpenMP Benchmark, but I have some problems. Anyone knows how I compiling and running OpenMP? Thank You.
8
by: Gabest | last post by:
I really like the new openmp implementation of vc, but I ran into a something which may be a bug. Please see the following little example: void funct() { __declspec(align(16)) BYTE buff;...
126
by: ramyach | last post by:
Hi friends, I need to write a parallel code in 'C' on the server that is running SGI Irix 6.5. This server supports MIPS Pro C compiler. I don't have any idea of parallel C languages. I looked...
0
by: Klaas Vantournhout | last post by:
Hi all, I am searching for compilers which can handle openMP. I know that gnu gcc will include it in their 4.2 version and that it is back ported to the 4.1 of FC5. I also know that it is...
7
by: s.z.s | last post by:
Hi! Is anybody using an openmp compiler under cygwin? I tried to install gcc 4.2.2 without success and now I'm looking for alternatives. Thanks, Steffen
6
by: Renato Perini | last post by:
Hi all!!! I'm trying to find a *good* book about OpenMP and C, but I can't find anything specific. Can you advice me some good (and updated) books about OpenMP using the C interface? I'd like a...
0
by: Alien | last post by:
Hi, I am having bit of confusion about !$OPENMP DO/!$OPENMP END DO and !$OPENMP PARALLEL DO/!$OPENMP END PARALLEL DO directives. Having looked at my notes, the only difference I can find is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.