Hi,
I am running Ubuntu 12 on Virtual box and I am using GCC to compile this simple C program that has simple OpenMp pragmas :

#include <stdio.h>
#include <omp.h>
#define MAX 10000000000

void main()
{
    unsigned long long i,j,k,l;
    int threadnumber;
    #pragma omp parallel shared(i,j,k,l)
    {
        threadnumber = omp_get_thread_num();
        if(threadnumber == 0)
        {
            for(i = 0; i < (MAX / 4); i++)
                ;
        }
        else if(threadnumber == 1)
        {
            for(j = (MAX / 4); j < (MAX / 2); j++)
                ;
        }
        else if(threadnumber == 2)
        {
            for(k = (MAX / 2); k < (3 * (MAX / 4));k++)
                ;
        }
        else
        {
            for(l = (3 * (MAX / 4)); l < MAX; l++)
                ;
        }
    }
}

My Processor is an Intel Core i5 one.
The program is indeed working in parallel (verified through adding some printf()s) , I have set the environment variable(OMP_NUM_THREADS) to 4.
The problem is that code is taking much time than this one which is not parallel :

#include <stdio.h>
#define MAX 10000000000

void main()
{
    unsigned long long i;
    for(i = 0; i < MAX; i++)
        ;
}

I have also tried to add clock() calls before and after the loop in both versions and I am getting a higher time in the parallel version.
I have also tried to measure the time using : time ./a.out and I am getting (in the parallel version only) different "real" time than what is returned by clock() !
I have compiled both codes on visual studio and here are the results :
1) In Debug mode : both codes are given nearly equal times and that time is near to what is given by GCC.
2) In Release mode : Both codes are faster and the parallel one shows a great improvement in time.
The Problem in a nutshell :
1) I want to run the program in parallel with that same efficiency as in the release version of visual studio's compiler.
2) Is there a parameter or option that I should pass to GCC other than the "-fopenmp" to make it build a release version exactly like visual studio.
3) I want to know if it is an Ubuntu thing problem or a GCC one or WHAT ???
P.S : I have tried running the same procedure on an Ubuntu with wubi installation and on an Ubuntu as a standalone OS (on an ext4 File System) and on the same paltform and I am getting the same results !!!!
Please this is urgent ...

Please guys this is urgent !!
NO answer up till now ?!?!

use this Click Here

ifeq ($(BUILD),debug)   
# "Debug" build - no optimization, and debugging symbols
CFLAGS += -O0 -g
else
# "Release" build - optimization, and no debug symbols
CFLAGS += -O2 -s -DNDEBUG
endif

all: foo

debug:
    make "BUILD=debug"

foo: foo.o
    # The rest of the makefile comes here...
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.