Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8177195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:26:57+00:00 2026-06-06T23:26:57+00:00

I am running Ubuntu 12 on Virtual box and I am using GCC to

  • 0

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 :
  3. 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 platform and I am getting the same results.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:26:59+00:00Added an answer on June 6, 2026 at 11:26 pm

    I really don’t understand why every new OpenMP-related question here on SO contains code that uses clock() to (wrongly) measure wall-clock execution time, provided that OpenMP has a portable high resolution timer, available via a call to omp_get_wtime()?

    First, using shared variables as loop counters inside a parallel region is a terrible terrible idea. Here is why, although you have a Nehalem or later microarchitecture based CPU which makes this less of a problem.

    Second, Visual Studio applies different optimisation levels in Debug and Release configurations. In debug mode optimisation is disabled (/Od) while in release mode optimisation for speed is enabled (/O2). You say that in debug mode VS code runs as fast as the GCC code. This probably means that you run GCC with its default optimisation level of no optimisation. Compile with -O2 or even with -O3 to get code on par with what VS generates in release mode.

    Third, you are running Ubuntu inside a virtual machine. How many CPUs does the virtual machine has access to?

    Fourth, why are you reimplementing the OpenMP parallel for worksharing directive?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running windows 7 and have installed an Ubuntu machine using virtual box.
I'm running an ubuntu guest on a mac osx host using virtual box. I'm
Been trying to get my project up and running on an Ubuntu Virtual Box
I'm running an Ubuntu 11.10 64-bit server on virtual box and want to seamlessly
I'm having a really strange problem. I have 2 virtual machines running ubuntu 11.4
I'm running Ubuntu on EC2 (using the alestic community AMI) and on startup my
I'm running Ubuntu to compile a set of code which requires python 2.4. How
I'm using VirtualBox on Windows to run an Ubuntu OS, which is running the
This an extract from a c program that should demonstrate a bufferoverflow. void foo()
I'm running Apache2 on Ubuntu on my virtual machine (dev server). I have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.