Re: [Haskell-cafe] Optimization flag changing result of code execution

I am using GHC 7.6.1 mwc-random 0.12.0.1 vector 0.9.1 primitive 0.4.1 Azeem On 16.03.2013 13:31, Azeem -ul-Hasan wrote:
Nope that isn't the case either. Even if I make use of defaultSeed through create the problem still remains. The problem seems to be in the generation of a vector of (a,a) i.e in the part
V.generateM ((round $ p*(fromIntegral $ l*z)) `div` 2) (\i-> R.uniformR ((0,0) , (l-1,l-1)) gen)
in line 16. Thanks again.
I've tried to run you program and I've got approximately same results regardless of optimization level. Which versions of GHC, mwc-random, vector and primitive do you use?

Same here, I used mwc-random to generate random strings. It works in
ghci and when compiled with -O0, but with -O1 and -O2 I've been getting
exclusively a's and b's.
On Sun, 17 Mar 2013 18:48:06 +0500 Azeem -ul-Hasan
I am using GHC 7.6.1 mwc-random 0.12.0.1 vector 0.9.1 primitive 0.4.1
Azeem
On 16.03.2013 13:31, Azeem -ul-Hasan wrote:
Nope that isn't the case either. Even if I make use of defaultSeed through create the problem still remains. The problem seems to be in the generation of a vector of (a,a) i.e in the part
V.generateM ((round $ p*(fromIntegral $ l*z)) `div` 2) (\i-> R.uniformR ((0,0) , (l-1,l-1)) gen)
in line 16. Thanks again.
I've tried to run you program and I've got approximately same results regardless of optimization level. Which versions of GHC, mwc-random, vector and primitive do you use?

On 09.07.2013 22:10, kudah wrote:
Same here, I used mwc-random to generate random strings. It works in ghci and when compiled with -O0, but with -O1 and -O2 I've been getting exclusively a's and b's.
It looks like MWC generates only 0 and 1 for some reason. I've tried to write simple test but everything works fine. Could you post test case and compiler/libraries/OS versions you use?

I've attached the script that I had trouble with. It tries to replicate
one directory structure in another directory, while replacing filenames
and file contents with random data. When compiled with -O1 or -O2
resulting file and directory names are composed only of a's and b's,
but file contents seem properly randomized.
ghc-7.6.2, vector-0.10.0.1, primitive-0.5.0.1, mwc-random-0.12.0.1,
Gentoo Linux i686 3.8.2-pf.
On Tue, 09 Jul 2013 22:43:36 +0400 Aleksey Khudyakov
On 09.07.2013 22:10, kudah wrote:
Same here, I used mwc-random to generate random strings. It works in ghci and when compiled with -O0, but with -O1 and -O2 I've been getting exclusively a's and b's.
It looks like MWC generates only 0 and 1 for some reason. I've tried to write simple test but everything works fine. Could you post test case and compiler/libraries/OS versions you use?
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 10.07.2013 01:38, kudah wrote:
I've attached the script that I had trouble with. It tries to replicate one directory structure in another directory, while replacing filenames and file contents with random data. When compiled with -O1 or -O2 resulting file and directory names are composed only of a's and b's, but file contents seem properly randomized.
No luck. On my computer script works correctly with and without optimizations. My best guess that uniformR is problematic. Does
(\g -> randName g 20) =<< create
show different behavior with and without optimizations?

Yes, it does. Without optimizations the result is
"ndgorsfesnywaiqraloa", while with optimizations the result is always
"aaaaaaaaaabbaaaaaaaa".
On Wed, 10 Jul 2013 02:21:10 +0400 Aleksey Khudyakov
On 10.07.2013 01:38, kudah wrote:
I've attached the script that I had trouble with. It tries to replicate one directory structure in another directory, while replacing filenames and file contents with random data. When compiled with -O1 or -O2 resulting file and directory names are composed only of a's and b's, but file contents seem properly randomized.
No luck. On my computer script works correctly with and without optimizations. My best guess that uniformR is problematic. Does
(\g -> randName g 20) =<< create
show different behavior with and without optimizations?

On 10 July 2013 14:10, kudah
Yes, it does. Without optimizations the result is "ndgorsfesnywaiqraloa", while with optimizations the result is always "aaaaaaaaaabbaaaaaaaa".
Sorry for taking so long. So problem is uniformR. You can reproduce bug reliably and I cannot. Are you on 32-bit system? I only tested on 64-bit ones. If this isn't the case I'm out of ideas. I finally wrote test case that doesn't depends on anything besides mwc-random (it's in attachment). Could you check whether it still triggers the bug

Test triggers the bug, only zeros and ones like you said, but only for native-sized types: -O2: Int 0 0 0 0 0 1 0 0 1 0 1 1 0 0 0 0 0 0 0 0 Int32 41 37 25 85 27 84 70 8 70 32 36 1 14 92 1 74 17 28 38 76 Int64 37 77 57 75 17 58 28 77 23 51 1 13 50 35 21 11 70 43 6 5 Word 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 Word32 52 45 86 4 85 44 71 59 91 10 65 89 41 78 84 88 3 60 71 0 Word64 12 82 25 1 11 14 76 58 1 77 9 25 57 20 41 8 2 29 21 29 ghci: Int 53 13 24 58 66 71 19 16 73 54 95 87 2 34 62 67 2 45 56 2 Int32 41 37 25 85 27 84 70 8 70 32 36 1 14 92 1 74 17 28 38 76 Int64 37 77 57 75 17 58 28 77 23 51 1 13 50 35 21 11 70 43 6 5 Word 41 19 99 69 27 58 92 45 9 38 51 39 50 14 2 21 25 94 96 2 Word32 52 45 86 4 85 44 71 59 91 10 65 89 41 78 84 88 3 60 71 0 Word64 12 82 25 1 11 14 76 58 1 77 9 25 57 20 41 8 2 29 21 29 I run a 32-bit system, as I've said before.
Gentoo Linux _i686_ 3.8.2-pf
Could perhaps be something with my system, I'll test on Ubuntu later
today, and if there are no problems with compiling mwc-random on ghc
git — on it too.
On Wed, 17 Jul 2013 12:19:29 +0400 Aleksey Khudyakov
On 10 July 2013 14:10, kudah
wrote: Yes, it does. Without optimizations the result is "ndgorsfesnywaiqraloa", while with optimizations the result is always "aaaaaaaaaabbaaaaaaaa".
Sorry for taking so long. So problem is uniformR. You can reproduce bug reliably and I cannot. Are you on 32-bit system? I only tested on 64-bit ones. If this isn't the case I'm out of ideas.
I finally wrote test case that doesn't depends on anything besides mwc-random (it's in attachment). Could you check whether it still triggers the bug

This has all the marks of a 64-bit-only code running on a 32 bit machine.
It looks like you're getting the high bits of the rng with a signed shift
right, ultimately yielding only the sign bit.
I suspect mwc-random needs to use Int64 rather than Int internally in a few
critical places.
On Wed, Jul 17, 2013 at 7:22 AM, kudah
Test triggers the bug, only zeros and ones like you said, but only for native-sized types:
-O2: Int 0 0 0 0 0 1 0 0 1 0 1 1 0 0 0 0 0 0 0 0 Int32 41 37 25 85 27 84 70 8 70 32 36 1 14 92 1 74 17 28 38 76 Int64 37 77 57 75 17 58 28 77 23 51 1 13 50 35 21 11 70 43 6 5 Word 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 Word32 52 45 86 4 85 44 71 59 91 10 65 89 41 78 84 88 3 60 71 0 Word64 12 82 25 1 11 14 76 58 1 77 9 25 57 20 41 8 2 29 21 29
ghci: Int 53 13 24 58 66 71 19 16 73 54 95 87 2 34 62 67 2 45 56 2 Int32 41 37 25 85 27 84 70 8 70 32 36 1 14 92 1 74 17 28 38 76 Int64 37 77 57 75 17 58 28 77 23 51 1 13 50 35 21 11 70 43 6 5 Word 41 19 99 69 27 58 92 45 9 38 51 39 50 14 2 21 25 94 96 2 Word32 52 45 86 4 85 44 71 59 91 10 65 89 41 78 84 88 3 60 71 0 Word64 12 82 25 1 11 14 76 58 1 77 9 25 57 20 41 8 2 29 21 29
I run a 32-bit system, as I've said before.
Gentoo Linux _i686_ 3.8.2-pf
Could perhaps be something with my system, I'll test on Ubuntu later today, and if there are no problems with compiling mwc-random on ghc git — on it too.
On Wed, 17 Jul 2013 12:19:29 +0400 Aleksey Khudyakov
wrote: On 10 July 2013 14:10, kudah
wrote: Yes, it does. Without optimizations the result is "ndgorsfesnywaiqraloa", while with optimizations the result is always "aaaaaaaaaabbaaaaaaaa".
Sorry for taking so long. So problem is uniformR. You can reproduce bug reliably and I cannot. Are you on 32-bit system? I only tested on 64-bit ones. If this isn't the case I'm out of ideas.
I finally wrote test case that doesn't depends on anything besides mwc-random (it's in attachment). Could you check whether it still triggers the bug
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 2013.07.17, at 08:03, Jan-Willem Maessen wrote:
This has all the marks of a 64-bit-only code running on a 32 bit machine.
This discussion is interesting, but I'm not sure why so much of it is taking place here instead of on the mwc-random issue tracker: https://github.com/bos/mwc-random/issues It's way past time to file an issue and/or talk to the maintainer.

On 17.07.2013 16:11, Brian Lewis wrote:
On 2013.07.17, at 08:03, Jan-Willem Maessen wrote:
This has all the marks of a 64-bit-only code running on a 32 bit machine.
This discussion is interesting, but I'm not sure why so much of it is taking place here instead of on the mwc-random issue tracker: https://github.com/bos/mwc-random/issues
It's way past time to file an issue and/or talk to the maintainer.
Issue turned out to be GHC bug. Here are relevant tickets https://github.com/bos/mwc-random/issues/25 http://ghc.haskell.org/trac/ghc/ticket/8072 No workaround for mwc-random yet
participants (5)
-
Aleksey Khudyakov
-
Azeem -ul-Hasan
-
Brian Lewis
-
Jan-Willem Maessen
-
kudah