This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.Billinghurst@riotinto.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@cygwin.com
> [mailto:cygwin-owner@cygwin.com] On Behalf Of Richard Stanton
> Sent: Monday, 4 August 2008 15:03
> To: cygwin@cygwin.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 <stdio.h>
> #include <pthread.h>
>
> #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<NUM_THREADS; 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<NUM_THREADS; 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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]