| Thread Closed |
icc compiler |
Share Thread | Thread Tools |
| May10-07, 07:57 AM | #1 |
|
|
icc compiler
Hello,
my colleague has a problem. He has a Monte Carlo simulation writen in C. But his program gives different outputs in case he compile it using g++ or icc. He has nothing changed in his source. He is using standard random number generator drand() with initialization srand((unsigned) time (NULL)). Didn't you have some similar problems with icc compiller? Do you think, that the differencies in outputs could be caused by used compiller? Thank you. |
| May10-07, 08:07 AM | #2 |
|
|
Shouldn't he be getting different outputs every time he runs the program, regardless of how it was compiled?
|
| May10-07, 08:55 AM | #3 |
|
|
No, for the same compiler he obtain every time similar outputs. Results are different only when compilers are different.
|
| May10-07, 10:56 AM | #4 |
|
|
icc compiler
what kind of different outputs (eg unexpected errors)? and what kind of similar outputs(eg. identical results)...what type of optimization,what type of #-bit PC.
Are his randomizations working properly on initial condition? |
| May10-07, 11:01 AM | #5 |
|
Mentor
|
Probably each compiler handles seed generation differently. With each compiler, does it produce the same first number each time? Or maybe some compilers generate code that uses the PC clock in the seed generation?
|
| May10-07, 11:33 AM | #6 |
|
Mentor
|
The two compilers probably use different math libraries. The required behavior of rand() is very poorly specified in the C/C++ standards. Bottom line: Don't use srand/rand. Use of these functions is verboten in many places. Good random number generators include those in the Gnu scientific library and some in Numerical Recipes.
|
| May12-07, 08:34 AM | #7 |
|
|
|
| May12-07, 08:59 PM | #8 |
|
|
In addition to different (and in all likelihood, poor) implementations of rand/srand, there is also the possibility that different compilers may use different floating point instructions or order instructions differently. This matters because floating point operations are in general non-associative.
On a complex chip like a Pentium-4, Xeon, Athlon, Opteron, etc. there are multiple floating point units as well. These different units (x87, SSE) have different internal representations of floating point numbers. Prior to gcc-4.0, gcc would target x87 by default. Don't know what icc targets, but I would guess they've been going after SSE for a longer time. Running on one unit would likely have different rounding characteristics versus the other. I would like to emphasize what D H said: do not use rand/srand unless you really know what you're doing. |
| Thread Closed |
| Thread Tools | |
Similar Threads for: icc compiler
|
||||
| Thread | Forum | Replies | ||
| SML compiler? | Programming & Comp Sci | 1 | ||
| Does anyone here use the compiler for PIC processors from CCS? | Electrical Engineering | 1 | ||
| Compiler | Computing & Technology | 1 | ||
| C++ Compiler? | Computing & Technology | 8 | ||
| Compiler | Computing & Technology | 7 | ||