Author Topic: C program not finding omp.h  (Read 10954 times)

Offline Gary Roach

  • Single posting newcomer
  • *
  • Posts: 2
C program not finding omp.h
« on: September 05, 2017, 01:48:28 am »
It is my understanding that to switch on openMP the make file has to be called with "make -fopenmp".
I am trying to run a threaded program using Code::Blocks and keep getting the compiler build message of:
                                      |   |=== Build file: "no target" in "no project" (compiler: unknown) ===|
/home/gary/testing/hello.c|    |In function ‘main’:|
/home/gary/testing/hello.c|24|error: assignment to expression with array type|
                                      |   |=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

I'm not sure whether this is an IDE setup problem or a code problem. I am running:
Debian (9) Stretch
KDE Desktop
Athlon FX 4  core processor

The code I am trying to compile and build is:
/*Test program for lecture on openMP parallel computing*/

#include <stdio.h>
#include <omp.h>
static long num_steps = 100000;  double step;
#define PAD  8 //assume 64 byte L1 cache line size
#define NUM_THREADS 4

void main()
{

    double step;
    int i,nthreads; double pi, sum[NUM_THREADS][PAD];
    step = 1.0/(double)num_steps;
    omp_set_num_threads(NUM_THREADS);
#pragma omp parallel
{   int i, id, nthrds;
    double x;
    id = omp_get_thread_num();
    nthrds = omp_get_num_threads();

    if(id == 0) nthreads = nthrds;

    for(i=id,sum[id]=0.0; i<num_steps; i=i+nthrds)
    {
        x = (i+0.5)*step;
        sum[id][0] += 4.0/(1.0+x*x);
    }
    for(i=0,pi=0.0;i<nthreads;i++)pi += step*sum[0];
    printf("PI %.20f \n",pi);
}
}

If someone would sort out where my root problem resides it would be sincerely appreciated. I'm new to Code::Blocks and to threaded programming. I am really confused.

Gary R.

Online stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Online stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: C program not finding omp.h
« Reply #2 on: September 05, 2017, 06:17:53 am »
Full build log of your posted program after I fixed the compiler related errors.

Code
-------------- Clean: default in test omp thread (compiler: GNU GCC Compiler)---------------

Cleaned "test omp thread - default"

-------------- Build: default in test omp thread (compiler: GNU GCC Compiler)---------------

gcc -Wall -fopenmp -g -std=c11 -Wno-unused-local-typedefs  -c "/home/stahta01/devel/open_source_code/no_version_control/CB_wizard_testing/test omp thread/main.c" -o obj/main.o
/home/stahta01/devel/open_source_code/no_version_control/CB_wizard_testing/test omp thread/main.c: In function ‘main’:
/home/stahta01/devel/open_source_code/no_version_control/CB_wizard_testing/test omp thread/main.c:13:9: warning: unused variable ‘i’ [-Wunused-variable]
     int i,nthreads; double pi, sum[NUM_THREADS+PAD];
         ^
g++  -o "bin/test omp thread" obj/main.o   -lgomp
Output file is bin/test omp thread with size 11.94 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 1 warning(s) (0 minute(s), 0 second(s))

Edit: The program only used one thread for me; but, I think that was because of the old hardware it is running on. Single CPU system.

gcc version info on my system
Code
gcc (Debian 6.3.0-18) 6.3.0 20170516

Tim S.

« Last Edit: September 05, 2017, 07:46:46 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org