[Omp] can any one help me in this..

Ruud van der Pas Ruud.Vanderpas at Sun.COM
Fri Nov 24 11:30:19 PST 2006


Hi Garimella,

> I am new to programming in OpenMp.I have written OpenMp code in c++.I am 
> running it on sunfire v880  contains 6 processors using cc compiler.
>  
> topin%CC -xopenmp -o program.cpp????
>  
> Is this is correct.Is that the flag given is correct
>  
> But when I am compiling.I am getting only one warning i.e. optimization 
> level changed from o to 3 to support parallelized code.

This is correct. Unless you use -xopenmp=noopt, you will need
to set the optimization level to -xO3 at least.

In general, I would recommend to use one or more optimization
options on the compiler, as it should give you better performance.

> when I am running the code I am getting same processor utilization code 
> as for 1 processor and for 6 processor.How can i know wheather the 
> threads are parallelized or not.

You can add the -g0 option and use the er_src command on the resulting
object file: % er_src -src <name_of_src_file> <name_of_object_file>

This will display parallelization messages (plus other messages
related to the optimizations performed by the compiler) on your screen.
Below I append a simple example.

Be aware of the following. When you run the OpenMP application you
need to set OMP_NUM_THREADS to a value higher than one. By default
it is set to 1 on Sun systems.

> If any one can help me in that please reply me back.please tell me how 
> to write the open mp code for this for loops.before the for loops is any 
> initializations r important.

I hope the above and the example below are useful. If not, please
let us know.

Kind regards,
Ruud
----------------------------------------------------------------
Senior Staff Engineer             Email: ruud.vanderpas at sun.com
Systems Group                     Phone: +31-33-4515000 (x15920)
Sun Microsystems                  Fax  : +31-33-4515001
----------------------------------------------------------------
% cat loop.cpp
#include <stdio.h>
#include <stdlib.h>

#define n 10000

int main()
{
    int a[n], b[n];

#pragma omp parallel for shared(a,b)
    for (int i=0; i<n; i++)
        a[i] += b[i];
}
% CC -xO3 -g0 -c -xopenmp loop.cpp
% er_src -src loop.cpp loop.o
Source file: ./loop.cpp
Object file: ./loop.o
Load Object: ./loop.o




      1. #include <stdio.h>
      2. #include <stdlib.h>
      3.
      4. #define n 10000
      5.
      6. int main()
         <Function: main>
      7. {
      8.    int a[n], b[n];
      9.

    Source OpenMP region below has tag R1
    Private variables in R1: (main)#block 1::i
    Shared variables in R1: (main)::a, (main)::b
     10. #pragma omp parallel for shared(a,b)

    Source loop below has tag L1
    L1 parallelized by explicit user directive
    L1 parallel loop-body code placed in function _$d1A10.main along with 0 inner loops
    Copy in M-function of loop below has tag L2
    Copy in M-function of loop below has tag L3
    Bounds test for L3 moved to top of loop
     11.    for (int i=0; i<n; i++)
     12.        a[i] += b[i];
     13. }
%


More information about the Omp mailing list