Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: biotech54 on September 22, 2017, 04:33:41 am

Title: OpenMP
Post by: 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
Title: Re: OpenMP
Post by: stahta01 on September 22, 2017, 05:10:02 am
http://forums.codeblocks.org/index.php?topic=22123.0 (http://forums.codeblocks.org/index.php?topic=22123.0)
Title: Re: OpenMP
Post by: biotech54 on September 22, 2017, 05:38:00 am
Thanks, but just too complicated for me.
Title: Re: OpenMP
Post by: stahta01 on September 22, 2017, 05:41:41 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.
Title: Re: OpenMP
Post by: biotech54 on September 22, 2017, 05:57:29 am
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))
 


Title: Re: OpenMP
Post by: biotech54 on September 22, 2017, 05:59:07 am
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))
 
Title: Re: OpenMP
Post by: stahta01 on September 22, 2017, 03:35:21 pm
link to the library gomp if I recall correctly.

Tim S.
Title: Re: OpenMP
Post by: BlueHazzard on September 22, 2017, 04:22:09 pm
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
Title: Re: OpenMP
Post by: 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
Title: Re: OpenMP
Post by: stahta01 on September 25, 2017, 03:36:20 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.
Title: Re: OpenMP
Post by: BlueHazzard on September 25, 2017, 09:45:38 am
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
Code
-fopenmp
and the library
Code
gomp
in the linker->library settings

Title: Re: OpenMP
Post by: 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...

Title: Re: OpenMP
Post by: BlueHazzard on September 25, 2017, 12:28:54 pm
BlueHazzard, where did you find TDM-GCC-6?. The project seems abandoned after 5.1...

it is a "kind of TDM-GCC": http://forums.codeblocks.org/index.php/topic,22103.0.html
Title: Re: OpenMP
Post by: Misa on June 20, 2021, 06:17:11 pm
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