X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org X-SBRS: 3.6 X-IronPort-AV: E=Sophos;i="4.31,305,1215414000"; d="scan'208";a="44763341" From: Richard Stanton To: Mike Marchywka , "cygwin AT cygwin DOT com" Date: Mon, 4 Aug 2008 09:40:36 -0700 Subject: RE: cygwin gcc: Different numerical results in thread vs in main() Message-ID: <40C7B1BFC291ED4E9D10436D07736A33127AB73D21@EXMAIL7.haas.uc.berkeley.edu> References: <40C7B1BFC291ED4E9D10436D07736A33127AB73CD1 AT EXMAIL7 DOT haas DOT uc DOT berkeley DOT edu> In-Reply-To: Accept-Language: en-US Content-Language: en-US acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id m74GfmJX029932 1) The result from the within thread calculation matches my Mac output (note that the Mac is also an Intel based machine, and I'm also using gcc there, albeit version 4.0.1, so clearly something is operating differently there). The main() result is different from the Mac output. 2) Checking the calculation using Maple, neither result is correct. Here is a comparison (after printing out t itself to 30 decimal places, to adjust for rounding error there): True: 0.00056090488683290218488507... Main: 0.0005609048868329022342546 Thread: 0.0005609048868329021258344 The errors in the two calculations are not very different, but they're in opposite directions. 3) I can get the results to match (each other and the Mac output) by compiling with the line c:\projects\threads]gcc -march=pentium4 -msse -mfpmath=sse -o thread1 -lpthread c:\projects\threads]thread1 Main: t/1+t = 0.00056090488683290212583443246074921 Thread 0: t/1+t = 0.00056090488683290212583443246074921 Thread 1: t/1+t = 0.00056090488683290212583443246074921 ... Thanks very much for all the helpful suggestions. -----Original Message----- From: Mike Marchywka [mailto:marchywka AT hotmail DOT com] Sent: Monday, August 04, 2008 8:06 AM To: Richard Stanton; cygwin AT cygwin DOT com Subject: RE: cygwin gcc: Different numerical results in thread vs in main() > Try compiling with -ffloat-store then report back. google for > "float-store excess precision gcc" to understand why this may help. Did you try disassembling the code? As I'm sure you know, only java AFAIK guarantees certain reproducible behaviour for floating point. If you change the optimization or debug, all the results could change. You shouldn't do floating equality tests but I appreciate your concern. Which, if either, of these results are accurate or match the MAC? You can take a look at the docs at intel to get some idea of the floating point situation on your processor, they have good online ia32 architecture details. Mike Marchywka 586 Saint James Walk Marietta GA 30067-7165 415-264-8477 (w)<- use this 404-788-1216 (C)<- leave message 989-348-4796 (P)<- emergency only marchywka AT hotmail DOT com Note: If I am asking for free stuff, I normally use for hobby/non-profit information but may use in investment forums, public and private. Please indicate any concerns if applicable. Note: Hotmail is possibly blocking my mom's entire ISP - try me on marchywka AT yahoo DOT com if no reply here. Thanks. > From: stanton AT haas DOT berkeley DOT edu > To: cygwin AT cygwin DOT com > Date: Mon, 4 Aug 2008 07:29:14 -0700 > Subject: Re: cygwin gcc: Different numerical results in thread vs in main() > > Thanks for the helpful information, David. Oddly, -ffloat-store doesn't seem to make any difference: > > [c:\projects\threads]gcc -ffloat-store -o thread1 thread1.c -lpthread > > [c:\projects\threads]thread1 > Main: t/1+t = 0.0005609048868329022342546 > Thread 0: t/1+t = 0.0005609048868329021258344 > Thread 1: t/1+t = 0.0005609048868329021258344 > Thread 2: t/1+t = 0.0005609048868329021258344 > Thread 3: t/1+t = 0.0005609048868329021258344 > > -----Original Message----- > From: Billinghurst, David (RTATECH) [mailto:David DOT Billinghurst AT riotinto DOT com] > Sent: Sunday, August 03, 2008 10:16 PM > To: Richard Stanton > Subject: RE: cygwin gcc: Different numerical results in thread vs in main() > > Try compiling with -ffloat-store then report back. google for > "float-store excess precision gcc" to understand why this may help. > > I don't recommend -ffloat-store as a fix, but it can help diagnose the problem. > > David > >> -----Original Message----- >> From: cygwin-owner AT cygwin DOT com >> [mailto:cygwin-owner AT cygwin DOT com] On Behalf Of Richard Stanton >> Sent: Monday, 4 August 2008 15:03 >> To: cygwin AT cygwin DOT com >> Subject: cygwin gcc: Different numerical results in thread vs in >> main() >> >> The following program performs exactly the same calculation 5 times, >> once inside main(), and again in 4 thread functions. >> Though the calculations are identical, the results are not. >> When I compile and run the same program on my Mac, all the results are >> identical. By the way, this is using the latest gcc 3.4.4. >> >> Richard Stanton >> >> ------------------ >> >> [c:\projects\threads]thread1 >> Main: t/1+t = 0.0005609048868329022342546 >> Thread 0: t/1+t = 0.0005609048868329021258344 >> Thread 1: t/1+t = 0.0005609048868329021258344 >> Thread 2: t/1+t = 0.0005609048868329021258344 >> Thread 3: t/1+t = 0.0005609048868329021258344 >> >> >> #include >> #include >> >> #define NUM_THREADS 4 >> >> double t = 0.0005612196776927068104374; >> >> void * thread_function (void *arg) >> { >> int i; >> int id = *((int *)arg); >> >> printf("Thread %d: t/1+t = %30.25lf\n", id, t/(1.0+t)); >> >> return NULL; >> } >> >> >> int main() >> { >> int i; >> int arg[NUM_THREADS] = {0,1,2,3}; >> pthread_t thread[NUM_THREADS]; >> pthread_attr_t attr; >> >> printf("Main: t/1+t = %30.25lf\n", t/(1.0+t)); >> >> /* initialize and set the thread attributes */ >> pthread_attr_init( &attr ); >> pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE ); >> >> /* creating threads */ >> for ( i=0; i> if ( pthread_create( &thread[i], &attr, thread_function, >> (void *)&arg[i] )) { >> fprintf(stderr,"Creating thread %d failed!",i); >> return 1; >> } >> } >> >> /* joining threads (== waiting for them to exit) */ >> for ( i=0; i> if ( pthread_join ( thread[i], NULL ) ) { >> fprintf(stderr,"Joing thread %d failed!",i); >> return 1; >> } >> } >> >> return 0; >> } > > > -- > Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple > Problem reports: http://cygwin.com/problems.html > Documentation: http://cygwin.com/docs.html > FAQ: http://cygwin.com/faq/ > _________________________________________________________________ Got Game? Win Prizes in the Windows Live Hotmail Mobile Summer Games Trivia Contest http://www.gowindowslive.com/summergames?ocid=TXT_TAGHM -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/