[SciPy-dev] random module not working on opteron

Arnd Baecker arnd.baecker at web.de
Sun Oct 23 16:19:37 EDT 2005


On Sun, 23 Oct 2005, Robert Kern wrote:

> Arnd Baecker wrote:

[...]

> > Can anyone with a 64 Bit machine confirm this behaviour?
> > What could one do to hunt this one down?
>
> I would first check if the RandomKit functions work correctly from C.
> See the files randomkit.[ch] ; the functions should be self-explanatory.
> It's entirely possible that they're not 64-bit safe; I never had the
> opportunity to check.

Ok, referring to a famous scene of the Life of Brian:
after more than 5 years of not speaking C at all
you are stepping on my feet and I speak C again - a miracle!
(What a pleasure, no need to pay attention to white space,
I love all those variable declarations and ";"... Thank you ;-).

Now to the facts:
- the code below works fine on my PIV
- on the opteron it gives problems and hangs:

Value: 1791095845l max=4294967295l
Value: 0.997185
Now with random seed:
Value: 920722385l max=4294967295l
   Value: 915381373.352906                    # <----- not ok! (rk_double)
Now test the distributions:
rk_uniform: 566004099.864036                  # <----- not ok!
rk_normal:                                    # (hangs)

The problem is caused by calling rk_random_seed
(Commenting this one out, everything seems fine).

I am not sure what is going on in that routine
(and have to leave investigating this at the moment ...)
Maybe you can have a look at that routine
and spot anything which might be problematic?
(either 64 Bit, or the clock stuff???)

Best, Arnd

/* test_randomkit.c

  cd newcore/scipy/corelib/mtrand
gcc -I/usr/include/python2.3/ test_randomkit.c randomkit.c distributions.c -lm



*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#include "randomkit.h"

#include "distributions.h"


int main(int argc, char *argv[])
{


  rk_state state;
  unsigned long seed = 1, random_value;

  rk_seed(seed, &state); // Initialize the RNG

  random_value = rk_random(&state); // Generate random values in [0..RK_MAX]

  printf("Value: %ul max=%ul\n",random_value,RK_MAX);
  printf("Value: %f \n",rk_double(&state));
  printf("Value: %f \n",rk_double(&state));
  printf("Value: %f \n",rk_double(&state));

  printf("Now with random seed:\n");

  rk_randomseed(&state);
  printf("Value: %ul max=%ul\n",rk_random(&state),RK_MAX);
  printf("Value: %f \n",rk_double(&state));


  printf("Now test the distributions:\n");
  printf("rk_uniform: %f\n",rk_uniform(&state,0.0,1.0));
  printf("rk_normal: %f\n",rk_normal(&state,0.0,1.0));


  return(0);
}






More information about the SciPy-Dev mailing list