X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/cd04ab60bef9c99a3c4c810d3986aa9a179ff83b..4b52501b4cd5c33e7180075998e85b6478450cb5:/src/xbt/RngStream.c diff --git a/src/xbt/RngStream.c b/src/xbt/RngStream.c index 2608d16c7f..e4dbbb5a74 100644 --- a/src/xbt/RngStream.c +++ b/src/xbt/RngStream.c @@ -1,10 +1,16 @@ +/* Copyright (c) 2012, 2014. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + /***********************************************************************\ * * File: RngStream.c for multiple streams of Random Numbers * Language: ANSI C * Copyright: Pierre L'Ecuyer, University of Montreal * Date: 14 August 2001 - * License: GPL version 2 or later + * License: GPL version 2 or later * * Notice: Please contact P. L'Ecuyer at * for commercial purposes. @@ -13,6 +19,7 @@ #include "xbt/RngStream.h" +#include "xbt/sysdep.h" #include #include #include @@ -70,19 +77,19 @@ static double A2p0[3][3] = { }; static double A1p76[3][3] = { - { 82758667.0, 1871391091.0, 4127413238.0 }, - { 3672831523.0, 69195019.0, 1871391091.0 }, + { 82758667.0, 1871391091.0, 4127413238.0 }, + { 3672831523.0, 69195019.0, 1871391091.0 }, { 3672091415.0, 3528743235.0, 69195019.0 } }; static double A2p76[3][3] = { - { 1511326704.0, 3759209742.0, 1610795712.0 }, - { 4292754251.0, 1511326704.0, 3889917532.0 }, + { 1511326704.0, 3759209742.0, 1610795712.0 }, + { 4292754251.0, 1511326704.0, 3889917532.0 }, { 3859662829.0, 4292754251.0, 3708466080.0 } }; static double A1p127[3][3] = { - { 2427906178.0, 3580155704.0, 949770784.0 }, + { 2427906178.0, 3580155704.0, 949770784.0 }, { 226153695.0, 1230515664.0, 3580155704.0 }, { 1988835001.0, 986791581.0, 1230515664.0 } }; @@ -269,30 +276,30 @@ static int CheckSeed (unsigned long seed[6]) for (i = 0; i < 3; ++i) { if (seed[i] >= m1) { - fprintf (stderr, "****************************************\n" - "ERROR: Seed[%1d] >= m1, Seed is not set.\n" - "****************************************\n\n", i); - return (-1); + fprintf (stderr, "****************************************\n" + "ERROR: Seed[%1d] >= m1, Seed is not set.\n" + "****************************************\n\n", i); + return (-1); } } for (i = 3; i < 6; ++i) { if (seed[i] >= m2) { - fprintf (stderr, "****************************************\n" - "ERROR: Seed[%1d] >= m1, Seed is not set.\n" - "****************************************\n\n", i); - return (-1); + fprintf (stderr, "****************************************\n" + "ERROR: Seed[%1d] >= m1, Seed is not set.\n" + "****************************************\n\n", i); + return (-1); } } if (seed[0] == 0 && seed[1] == 0 && seed[2] == 0) { fprintf (stderr, "****************************\n" - "ERROR: First 3 seeds = 0.\n" - "****************************\n\n"); + "ERROR: First 3 seeds = 0.\n" + "****************************\n\n"); return (-1); } if (seed[3] == 0 && seed[4] == 0 && seed[5] == 0) { fprintf (stderr, "****************************\n" - "ERROR: Last 3 seeds = 0.\n" - "****************************\n\n"); + "ERROR: Last 3 seeds = 0.\n" + "****************************\n\n"); return (-1); } @@ -311,14 +318,14 @@ RngStream RngStream_CreateStream (const char name[]) RngStream g; size_t len; - g = (RngStream) malloc (sizeof (struct RngStream_InfoState)); + g = (RngStream) xbt_malloc (sizeof (struct RngStream_InfoState)); if (g == NULL) { printf ("RngStream_CreateStream: No more memory\n\n"); exit (EXIT_FAILURE); } if (name) { len = strlen (name); - g->name = (char *) malloc ((len + 1) * sizeof (char)); + g->name = (char *) xbt_malloc ((len + 1) * sizeof (char)); strncpy (g->name, name, len + 1); } else g->name = 0; @@ -349,13 +356,13 @@ void RngStream_DeleteStream (RngStream * p) RngStream RngStream_CopyStream (const RngStream src) { RngStream g; - + if(src == NULL) { printf ("RngStream_CopyStream: 'src' not initialized\n\n"); exit (EXIT_FAILURE); } - g = (RngStream) malloc (sizeof (struct RngStream_InfoState)); + g = (RngStream) xbt_malloc (sizeof (struct RngStream_InfoState)); if (g == NULL) { printf ("RngStream_CopyStream: No more memory\n\n"); exit (EXIT_FAILURE); @@ -415,7 +422,7 @@ int RngStream_SetSeed (RngStream g, unsigned long seed[6]) return -1; /* FAILURE */ for (i = 0; i < 6; ++i) g->Cg[i] = g->Bg[i] = g->Ig[i] = seed[i]; - return 0; /* SUCCESS */ + return 0; /* SUCCESS */ } /*-------------------------------------------------------------------------*/ @@ -538,15 +545,3 @@ int RngStream_RandInt (RngStream g, int i, int j) { return i + (int) ((j - i + 1.0) * RngStream_RandU01 (g)); } - -/* Undefine this terms, or supernovae build will fail. */ -#undef norm -#undef m1 -#undef m2 -#undef a12 -#undef a13n -#undef a21 -#undef a23n -#undef two17 -#undef two53 -#undef fact