From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30972 invoked by alias); 21 May 2008 07:35:05 -0000 Received: (qmail 30950 invoked by uid 22791); 21 May 2008 07:35:03 -0000 X-Spam-Check-By: sourceware.org Received: from rv-out-0708.google.com (HELO rv-out-0708.google.com) (209.85.198.251) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 21 May 2008 07:34:39 +0000 Received: by rv-out-0708.google.com with SMTP id c5so2224390rvf.56 for ; Wed, 21 May 2008 00:34:37 -0700 (PDT) Received: by 10.140.172.19 with SMTP id u19mr4951274rve.31.1211355276491; Wed, 21 May 2008 00:34:36 -0700 (PDT) Received: by 10.141.179.6 with HTTP; Wed, 21 May 2008 00:34:36 -0700 (PDT) Message-ID: Date: Wed, 21 May 2008 11:29:00 -0000 From: "diego sandoval" To: gcc-help@gcc.gnu.org Subject: openMP gcc vs icc, erratic results with gcc MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-05/txt/msg00216.txt.bz2 Hi everybody, I just started working with openMP, i installed first gcc-4.2.3 and then gcc-4.3.0, both of them having support for openMP. I tried a code to calculate the product \pi*\e. When i compile the code with gcc (both 4.2.3 and 4.3.0) withtout -fopenmp the result is correct. When i try with the -fopenmp option the result is erroneous. I also tried with the intel compiler icc (with -openmp) in order to verify the code correctness . There was no problem. I dont know what is wrong with gcc and this particular code but the results are erratic. If anyone of you can help me ... thanks in advance. Let me ellaborate on this problem. I am using gcc-4.3.0 in slackware 12.0 vanilla, i have a quad core smp machine $ uname -a Linux ra 2.6.24.3-smp #1 SMP Wed Feb 27 18:46:56 COT 2008 i686 Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz GenuineIntel GNU/Linux $ gcc-4.3.0 -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: ./configure --prefix=/home/medrano/compilers/gcc-4.3.0/ --enable-shared --enable-languages=c,c++ --enable-threads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld --verbose --program-suffix=-4.3.0 Thread model: posix gcc version 4.3.0 (GCC) I tried the openMP code below from http://www.kallipolis.com/openmp/taylor_mp.c which is supposed to calculate the product \pi*\e using the taylor series. $ gcc-4.3.0 -O2 -fopenmp taylor_mp.c -o taylor.gcc.out $ icc -O2 -openmp taylor_mp.c -o taylor.intel.out The results are: $ ./taylor.gcc.out Reached result 5.142145 in 10640.000 seconds ### wrong result $ ./taylor.gcc.out Reached result 10.795894 in 10660.000 seconds ### wrong result $ ./taylor.intel.out Reached result 8.539734 in 9950.000 seconds ### right result $ ./taylor.intel.out Reached result 8.539734 in 9570.000 seconds ### right result /* * taylor.c * * This program calculates the value of e*pi by first calculating e * and pi by their taylor expansions and then multiplying them * together. */ #include #include #define num_steps 20000000 int main(int argc, char *argv[]) { double start, stop; /* times of beginning and end of procedure */ double e, pi, factorial, product; int i; /* start the timer */ start = clock(); /* Now there is no first and seccond, we calculate e and pi */ #pragma omp parallel sections shared(e, pi) { #pragma omp section { printf("e started\n"); e = 1; factorial = 1; /* rather than recalculating the factorial from scratch each iteration we keep it in this varialbe and multiply it by i each iteration. */ for (i = 1; i