4

Is there anyway to use openmp with dev c++. I have seen links on how to use in Visual Studio, but i am more comfortable with Dev C++ interface. Adding /openmp in the linker command line doesnt work either. I couldnt find the library to download too. Am i missing something. I tried running this sample code:

#include <stdio.h> 
#include <stdlib.h>

int main(int argc, char *argv[])
{
    #pragma omp parallel
    { 
       printf("Hello, world.\n");
    }
   return 0;
 }

From where I read it was mentioned Output on a computer with 2 Cores and 2 threads will be hello world printed twice. I have a core i7 but it was printed only once.

3
  • Where do you create a second thread? And FYI those headers are deprecated in C++. Commented Nov 7, 2011 at 15:09
  • @Tomalak The second thread is created by OpenMP, and the headers are just fine if this is C (but yeah, the question suggests that it’s C++). Commented Nov 7, 2011 at 15:11
  • 2
    Dev-C++ is outdated. Its development has stopped half a decade ago. Please use a modern IDE. Commented Nov 7, 2011 at 15:14

5 Answers 5

11

Tools > Compiler Options > Check the option "Add the following commands when compiler is called" > in the text area put "-fopenmp"

Compile and execute again :)

Sign up to request clarification or add additional context in comments.

1 Comment

This helps. I think this is the answer that should be selected as the right one since the other one doesn't tell you how to do this on Dev C++.
4

I do not know Dev C++, but to enable openmp you also need to add the flag -fopenmp to your compiler. Additional to linking to omp.

With g++ it look like this

g++ yourProgram.cpp -o yourProgram -lgomp -fopenmp

-fopenmp will tell the compiler to generate parallel code. I hope this will help.

1 Comment

Dev-C++ is an IDE. It invokes g++ by default (albeit the MinGW port).
2

You have to include -fopenmp in

  1. Project-> Project Option->Parameters - Link and
  2. Tools ->Compiler Options (General) (check "add the following commands when calling the compiler" and include -fopenmp in the textBox

I have also included #include <omp.h> dev-c++ version 5.6.1

Comments

0

there is only the parallel region , the processor is informed that there is what parallelize , but as is parallelize the code they have to say via builders, probably what you want to use : #pragma omp sections

Comments

0

I guess you also have to include the header file #include < omp.h > separately

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.