Author Message

<  advanced  ~  openMP

PostPosted: Wed Dec 03, 2008 10:41 pm
User avatarJoined: Fri May 04, 2007 11:43 amPosts: 157
anyone here using openMP with OF?
i tried it today and didn't get very far. the main reason i guess were some incompatibilities with normal threading.
i'd be interested in other experiences because i'd like to switch from pthreads to openMP if that's worth the effort.

best
joerg



_________________
---

http://joerg.piringer.net
Offline Profile
PostPosted: Thu Dec 04, 2008 10:34 am
Joined: Wed Dec 12, 2007 10:12 pmPosts: 117Location: London
I'd have a look at TBB if I were you, I found it very easy to get into, the downloadeble PDF tutorial is very good.

http://www.threadingbuildingblocks.org/

http://flickr.com/photos/hahakid/2627848256/

It's more for parallelizing loops, etc (rather than managing individual threads), but as far a I understand that is what OpenMP is mostly used for as well.

/A



_________________
http://www.nanikawa.com

http://www.hahakid.net

http://flickr.com/photos/hahakid/
Offline Profile
PostPosted: Thu Dec 11, 2008 10:10 pm
User avatarJoined: Fri May 04, 2007 11:43 amPosts: 157
today i was successful in using openMP. i just converted my multithreaded app to a singlethreaded one. then parallelized the for loops that do most of the processing. and it worked. much better than the multithreaded one. it distributes the load equally over the 8 cores of the mac pro.
the app processes the feeds of three webcams and does some heavy real time image manipulation with openCV. surprisingly it's much faster to process the data of the three cameras sequentially and have just some parallel loops.
and once i got openMP to work it was just half an hour. just adding some
Code:
#pragma omp parallel for

here and there and checking the performance improvement. i had to remove one or two #pragmas because they slowed down the program. apparently more overhead than performance gain.

to use openMP (on osx) you need XCode 3.1 and change to gcc version 4.2 (in the project settings), tick the use openMP checkbox and add some #pragmas. that's it.

best
joerg



_________________
---

http://joerg.piringer.net
Offline Profile
PostPosted: Fri Dec 12, 2008 1:26 am
User avatarJoined: Tue May 27, 2008 10:03 amPosts: 691Location: London, UK
wow thats awesome! so openmp parallelizes for loops? how does that work? do you write a kernel routine and send that to openmp or something instead of a for loop? do you need mutex's or anything?


Offline Profile
PostPosted: Fri Dec 12, 2008 9:06 am
User avatarJoined: Fri May 04, 2007 11:43 amPosts: 157
no, it's much simpler. you just add a #pragma statement and as long as your loops stick to some simple rules (no data dependencies between loop steps for example) the get parallelized without any additional code. like in this example:
Code:
#define N 100000
int main(int argc, char *argv[])
{
  int i, a[N];
  #pragma omp parallel for
  for (i=0;i<N;i++) a[i]= 2*i;
  return 0;
}

the
Code:
#pragma omp parallel for
is the openMP statement.
it's really easy and fun.

there's some additional support for mutexes and other stuff but i didn't need that.

best
joerg



_________________
---

http://joerg.piringer.net
Offline Profile
PostPosted: Fri Dec 12, 2008 11:17 am
User avatarJoined: Tue May 27, 2008 10:03 amPosts: 691Location: London, UK
wow thats amazing, does the pragma apply to the very next line? I'm wondering whether its possible to have it apply to the for loops in an external library, like opencv...


Offline Profile
PostPosted: Fri Dec 12, 2008 11:18 am
User avatarJoined: Fri May 04, 2007 11:43 amPosts: 157
you can configure openCV for openMP. i think there's a switch for ./configure.

the only problem with openMP is that i was not able to use it with pthreads.

best
joerg[/code]



_________________
---

http://joerg.piringer.net
Offline Profile
PostPosted: Fri Dec 12, 2008 11:29 am
User avatarJoined: Tue May 27, 2008 10:03 amPosts: 691Location: London, UK
sounds great, will check it out thanks...


Offline Profile
PostPosted: Sun Jan 04, 2009 1:55 pm
Joined: Mon Jun 02, 2008 8:24 pmPosts: 409Location: Kiel - Germany
Hi,

I am also really interested to get my for loops parrallelized. I did what you said but when I change the GCC version to 4.2 it throws some errors:

8 of these: /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory

if I only toggle use openMP and stick to GCC version 4.0 I don't get the errors but the speed neither seems to improve.-

Any ideas?

Thanks!


EDIT:

Okay, I read a little bit about all that stuff. As far as I can tell you need GCC 4.2 to make use of OpenMP.

GCC 4.2 only works with the Base SDK for Mac OSX 10.5. If I select that with my OF project it throws a whole bunch of errors since OF does not really like that SDK as far as I can tell.

If I make an emtpy cocoa project everything works fine.

So how did you manage to do that? If it is too difficult would you mind uploading an empty xcode project using of and openMP?

Thank you!


Offline Profile
PostPosted: Sun Jan 04, 2009 9:42 pm
User avatarJoined: Fri May 04, 2007 11:43 amPosts: 157
in fact it's really easy as i mentioned in a different thread:
http://www.openframeworks.cc/forum/viewtopic.php?t=1387

but i am using the 00573-xcode-fat-ycam-day3 version of OF.

i hope that helps

best
joerg



_________________
---

http://joerg.piringer.net
Offline Profile
PostPosted: Sun Jan 04, 2009 11:49 pm
Joined: Mon Jun 02, 2008 8:24 pmPosts: 409Location: Kiel - Germany
thanks, I will try that. Is your of Version allready using poco? I am using this one:
http://www.openframeworks.cc/files/0057 ... ithGui.zip

So the changes should be similar right?

So you are not compiling for mac osx 10.5?


Offline Profile
PostPosted: Mon Jan 05, 2009 7:48 am
User avatarJoined: Fri May 04, 2007 11:43 amPosts: 157
yes it's with poco (which is causing most of the trouble). and i also use the 10.5 sdk.

best
joerg



_________________
---

http://joerg.piringer.net
Offline Profile
PostPosted: Mon Jan 05, 2009 11:42 am
Joined: Mon Jun 02, 2008 8:24 pmPosts: 409Location: Kiel - Germany
Wow thank you, I got it to work!

What an incredible change in Performance. Even though I am on a first generation MBP (I think they have 2 cores, not sure though) I get almost big speed improvement for this simple loop:

Code:
//#pragma omp parallel for
for(int i=0; i<1000000; i++){
}


approx. 410 fps with using openMP
and 270 without it.

I am seriously impressed with this :)


Offline Profile
PostPosted: Mon Jan 05, 2009 3:10 pm
User avatarJoined: Thu May 31, 2007 2:32 pmPosts: 292Location: PDX
Wow. That's super impressive. So, excuse my naivety on these matters, but OpenMP is just being used to parallelize for loops that are doing the image processing for 3 simultaneous camera feeds and there's no shared memory problems with that? Did you have to do anything special to get the camera data into a parallelizable state that's markedly different than what you would do for a multithreaded app?


Offline Profile
PostPosted: Mon Jan 05, 2009 4:59 pm
User avatarJoined: Fri May 04, 2007 11:43 amPosts: 157
the fun thing is: i don't need to rewrite the program much other than adding the pragmas and take care so that the for loops don't have data dependencies in themselves. all the rest is sequential. so the program processes the data of the three cameras after each other. only the processing loops are parallel.

best
joerg



_________________
---

http://joerg.piringer.net
Offline Profile

Display posts from previous:  Sort by:

All times are UTC
Page 1 of 2
19 posts
Go to page 1, 2  Next
Users browsing this forum: No registered users and 0 guests
Search for:
Post new topic  Reply to topic
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
cron