Code::Blocks Forums

User forums => Help => Topic started by: Gary Roach on September 05, 2017, 01:48:28 am

Title: C program not finding omp.h
Post by: Gary Roach 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.
Title: Re: C program not finding omp.h
Post by: stahta01 on September 05, 2017, 05:53:28 am
Step 1: Use a CB project.
http://wiki.codeblocks.org/index.php/Creating_a_new_project (http://wiki.codeblocks.org/index.php/Creating_a_new_project)
Step 2: Post a full rebuild log.
http://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors)#Q:_How_do_I_troubleshoot_a_compiler_problem.3F (http://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors)#Q:_How_do_I_troubleshoot_a_compiler_problem.3F)
Step 3: Post more information if the problem still exists
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F)
Compiler version is at least needed.

Tim S.
Title: Re: C program not finding omp.h
Post by: stahta01 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.