First attempts to parallelization

General OpenMP discussion

First attempts to parallelization

Postby andriejz » Wed Jan 09, 2013 3:38 am

Hello,

I wrote a code that simulates the physical processes in the semiconductors. The simulation requires long computation time so I was looking for some way to accelerate the code. I found that two blocks of the code can be performed in parallel.
Unfortunately there is no acceleration with omp support activated. Additionally the program works longer than without omp support.
The code has a structure similar to the following:

for (r = 1; r <= 1000; r++)
{
...some operations 0
#pragma omp parallel
#pragma omp sections
{
#pragma omp section
{
...some operations 1...
}
#pragma omp section
{
...some operations 2...
}
}
}

Interesting is that I found that when I put command Sleep(100) into the first and second section the code is faster with omp support than without it:

for (r = 1; r <= 1000; r++)
{
...some operations 0
#pragma omp parallel
#pragma omp sections
{
#pragma omp section
{
Sleep(100);
...some operations 1...
}
#pragma omp section
{
Sleep(100);
...some operations 2...
}
}
}

Intuition tells me that perhaps the initiation of the parallel areas takes more time than operations in sections 1 and 2.
Is there possibility to obtain to faster code in case of my code ?
I'll be grateful for any help.
Andriej
andriejz
 
Posts: 4
Joined: Tue Jan 08, 2013 3:44 pm

Re: First attempts to parallelization

Postby ftinetti » Wed Jan 09, 2013 7:34 am

Hi Andriej,

How are you measuring runtime? I suggest you use omp_get_wtime()
Sometimes,
when I put command Sleep(100) into the first and second section the code is faster with omp support than without it

means an active wait policy (i.e. spin lock/s). You can verify this guess changing the sleep(100) at the end of each section instead of its current place. Or, directly, set OMP_WAIT_POLICY to passive.

HTH,

Fernando.
ftinetti
 
Posts: 581
Joined: Wed Feb 10, 2010 2:44 pm

Re: First attempts to parallelization

Postby MarkB » Wed Jan 09, 2013 8:06 am

andriejz wrote:Intuition tells me that perhaps the initiation of the parallel areas takes more time than operations in sections 1 and 2.
Is there possibility to obtain to faster code in case of my code ?
I'll be grateful for any help.


Hi Andriej,

Can you estimate the length of time taken by the computation inside the parallel region? The overhead of a parallel region
is typically in the tens to hundreds of microseconds range. If the code you are trying to parallelise takes less time than this, then there
is pretty much no hope!

Mark.
MarkB
 
Posts: 450
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: First attempts to parallelization

Postby andriejz » Wed Jan 09, 2013 3:10 pm

ftinetti wrote:How are you measuring runtime? I suggest you use omp_get_wtime()

I used clock_t from <time.h>

means an active wait policy (i.e. spin lock/s). You can verify this guess changing the sleep(100) at the end of each section instead of its current place. Or, directly, set OMP_WAIT_POLICY to passive.

Unfortunately I use Visual Studio whit openmp 2.0 and according to my knowladge OMP_WAIT_PPOLICY is not supported by it.
But Thank you for your answer :)
andriejz
 
Posts: 4
Joined: Tue Jan 08, 2013 3:44 pm

Re: First attempts to parallelization

Postby andriejz » Wed Jan 09, 2013 3:15 pm

MarkB wrote:Can you estimate the length of time taken by the computation inside the parallel region?


I used clock_t. I'm not sure but I think that this command can not measure such short time :(
andriejz
 
Posts: 4
Joined: Tue Jan 08, 2013 3:44 pm

Re: First attempts to parallelization

Postby ftinetti » Wed Jan 09, 2013 3:41 pm

Hi again,

I used clock_t from <time.h>

Please use omp_get_wtime() and report what you obtain.

Unfortunately I use Visual Studio whit openmp 2.0 and according to my knowladge OMP_WAIT_PPOLICY is not supported by it.

Well... OMP_WAIT_PPOLICY is an environment variable, so you should be able to set it.

HTH,

Fernando.
ftinetti
 
Posts: 581
Joined: Wed Feb 10, 2010 2:44 pm

Re: First attempts to parallelization

Postby andriejz » Thu Jan 10, 2013 2:16 am

Hi,
ftinetti wrote:Please use omp_get_wtime() and report what you obtain.

I compared clock_t and omp_get_wtime() . To do this I set a large number of outer loops. Unfortunately both methods give the same results.



Well... OMP_WAIT_PPOLICY is an environment variable, so you should be able to set it.

I can not set OMP_WAIT_POLICY in Visual Studio Maybe I'm wrong but I think that there is no such environment variable:
viewtopic.php?f=3&t=1467#p5790

Thanks
Andriej
andriejz
 
Posts: 4
Joined: Tue Jan 08, 2013 3:44 pm

Re: First attempts to parallelization

Postby kazempour » Wed Feb 20, 2013 2:24 pm

Hi there,

Note that the most guarantee way to measure time is OMP_GET_WTIME(). The other ones adds up the timing results of all threads...
One important issue is that you should use float kind for timers, and you can multiply the time by a constant, e.g. 1000, and report times in milliseconds, but if the work is not so much time consuming the reported times may be wrong.
You can also try:
>> time run.exe
to compare the timings...

Regards,
Mahdi
kazempour
 
Posts: 13
Joined: Wed Jul 25, 2012 4:11 am


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 5 guests