I'm trying to get OpenMP programs to compile using CB. I read previous OpenMP discussions on this forum, written about 7 years ago. However, I did not understand what they were talking about, and i'm sure CB has changed since 2010. Does anyone know what i need to click, what settings i need to change, so that my OpenMP programs will compile? I get error messages when i try to compile simple five line programs. Thanks,
Edward
http://forums.next.codeblocks.org/index.php?topic=22123.0 (http://forums.next.codeblocks.org/index.php?topic=22123.0)
Thanks, but just too complicated for me.
Quote from: biotech54 on September 22, 2017, 05:38:00 AM
Thanks, but just too complicated for me.
If using a project and posting a build log is too complex for you.
Then, using OpenMP is likely too complex for you, at least till you can do both of those items.
Tim S.
oh sorry, i didn't know you wanted to see the build log. Here is the program, and build log. I'm using Windows 7.
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
void hello();
int main()
{
int threadCount = 4
#pragma omp parallel num_threads(threadCount)
hello();
return 0;
}
void hello(){
int myRank = omp_get_thread_num();
int threadCount = omp_get_num_threads();
printf("thread %d of %d\n", myRank, threadCount);
}
-------------- Build: Debug in OpenMPTest (compiler: GNU GCC Compiler)---------------
mingw32-gcc.exe -Wall -g -c C:\MyHomeComputer\MyCppProjects\OpenMPTest\main.c -o obj\Debug\main.o
C:\MyHomeComputer\MyCppProjects\OpenMPTest\main.c: In function 'main':
C:\MyHomeComputer\MyCppProjects\OpenMPTest\main.c:11:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
#pragma omp parallel num_threads(threadCount)
^
C:\MyHomeComputer\MyCppProjects\OpenMPTest\main.c:12:4: error: expected ',' or ';' before 'hello'
hello();
^
C:\MyHomeComputer\MyCppProjects\OpenMPTest\main.c:10:8: warning: unused variable 'threadCount' [-Wunused-variable]
int threadCount = 4
^
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 2 warning(s) (0 minute(s), 0 second(s))
sorry, i had a typo, i missed a semicolon, here is the build log.
-------------- Build: Debug in OpenMPTest (compiler: GNU GCC Compiler)---------------
mingw32-gcc.exe -Wall -g -c C:\MyHomeComputer\MyCppProjects\OpenMPTest\main.c -o obj\Debug\main.o
C:\MyHomeComputer\MyCppProjects\OpenMPTest\main.c: In function 'main':
C:\MyHomeComputer\MyCppProjects\OpenMPTest\main.c:10:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
#pragma omp parallel num_threads(threadCount)
^
C:\MyHomeComputer\MyCppProjects\OpenMPTest\main.c:9:8: warning: unused variable 'threadCount' [-Wunused-variable]
int threadCount = 4;
^
mingw32-g++.exe -o bin\Debug\OpenMPTest.exe obj\Debug\main.o
obj\Debug\main.o: In function `hello':
C:/MyHomeComputer/MyCppProjects/OpenMPTest/main.c:18: undefined reference to `omp_get_thread_num'
C:/MyHomeComputer/MyCppProjects/OpenMPTest/main.c:19: undefined reference to `omp_get_num_threads'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
3 error(s), 2 warning(s) (0 minute(s), 0 second(s))
link to the library gomp if I recall correctly.
Tim S.
https://gcc.gnu.org/onlinedocs/libgomp/Enabling-OpenMP.html
You can add compiler commands in
Project->Build options->Select your project on the left side->Compiler settings->other compiler options
As stahta01 noted you probably will also need to link against a openmp library. You can google for it. The additional libraries can be added into
Project->Build options->Select your project on the left side->Linker settings->Link linraries
I checked both openmp website and gcc websites, unable to find the omp library, so I couldn't get the second step done
Quote from: biotech54 on September 25, 2017, 02:40:35 AM
I checked both openmp website and gcc websites, unable to find the omp library, so I couldn't get the second step done
Did you try linking to the gomp library before going on a search for the omp library?
Note: This is my last attempt to help you!
Tim S.
Ok, i tried it on my system with different compiler. The result:
| | Compiler version | | | result | | | |
| | TDM-GCC-4.9 | | | Ok | | |
| | TDM-GCC-5.X | | | libgomp.spec not found, missing in the installation direcotry | | |
| | TDM-GCC-6 | | | Ok | | |
so this is dependent of your compiler. You need TDM-GCC-6 or TDM-GCC-4. TDM-GCC-5 wont work because of missing libgomp.spec
My project used the compiler options
-fopenmp and the library
gomp in the linker->library settings
BlueHazzard, where did you find TDM-GCC-6?. The project seems abandoned after 5.1...
Quote from: Miguel Gimenez on September 25, 2017, 11:56:35 AM
BlueHazzard, where did you find TDM-GCC-6?. The project seems abandoned after 5.1...
it is a "kind of TDM-GCC": http://forums.next.codeblocks.org/index.php/topic,22103.0.html
Quote from: biotech54 on September 22, 2017, 04:33:41 AM
I'm trying to get OpenMP programs to compile using CB. I read previous OpenMP discussions on this forum, written about 7 years ago. However, I did not understand what they were talking about, and i'm sure CB has changed since 2010. Does anyone know what i need to click, what settings i need to change, so that my OpenMP programs will compile? I get error messages when i try to compile simple five line programs. Thanks,
Edward
Step 1: Setup a new GCC compiler in Settings->Compiler by simply cloning the 'GNU GCC compiler', let's say it's 'OpenMP GNU GCC compiler'
Step 2: Configure as in attached pictures