9

I cannot find which library to link in GCC (4.8) under Windows (Vista). I tried the -fopenmp -llibgomp -lgomp compiler directives, but none works.

I already have GCC with POSIX (so std::thread is working if enabling C++11). The problem seems that searching for the right library does not provide useful results (even searching in GCC/MinGW documentation).

So basically I can't get this answer working (the answer claimed to work on most compilers, but it doesn’t provide additional information on how to get it working, so I can't verify if it is really working or not).

It would be nice to provide now additional information to get it working on most systems...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CoffeDeveloper
  • 7,961
  • 3
  • 35
  • 69

1 Answers1

9

MinGW-w64 based on GCC 4.8.1 from here has no problems so far.

Example: C


main.c

#include <omp.h>
#include <stdio.h>

int
main() {
  double x = omp_get_wtime();

  printf("%f\n", x);
}

Build:

gcc main.c -lgomp -o test.exe

Result:

1381572544.299000

Example: C++


main.cpp

#include <iostream>
#include <omp.h>

using std::cout;
using std::endl;

int
main() {
  double x = omp_get_wtime();

  cout << x << endl;
}

Build:

g++ main.cpp -lgomp -o test.exe

Result:

1.38158e+009

Conclusion


Probably something is wrong with your MinGW distribution. Otherwise I don't see any reason for it not to work. Try the above one and see how it goes.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alexander Shukaev
  • 16,674
  • 8
  • 70
  • 85
  • I re-downloaded GCC 4.8 distribution, now it compiled but measured times have a resolution of 15 milliseconds :/ no more than ctime – CoffeDeveloper Oct 12 '13 at 11:18
  • 1
    The feature you want to test is very implementation dependent. Maybe both of them already use high-resolution OS clock by default under the hood, and that's why you don't see any difference. Another possibility is that your benchmark has some wrong assumptions and/or is measuring too small unit of workload to capture the difference between these 2 timers. – Alexander Shukaev Oct 12 '13 at 11:21
  • It worked for me. Thanks. I didn't know one has to add this. – vincent mathew Nov 10 '15 at 10:39