mtgp64-fast.c File Reference

Mersenne Twister for Graphic Processors (mtgp64), which generates 64-bit unsigned integers and double precision floating point numbers based on IEEE 754 format. More...

#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include "mtgp64-fast.h"

Functions

static uint64_t ini_func1 (uint64_t x)
 This function represents a function used in the initialization by mtgp64_init_by_array() and mtgp64_init_by_str().
static uint64_t ini_func2 (uint64_t x)
 This function represents a function used in the initialization by mtgp64_init_by_array() and mtgp64_init_by_str().
static int alloc_state (mtgp64_fast_t *mtgp64, const mtgp64_params_fast_t *para)
 This function allocates the internal state vector.
int mtgp64_init (mtgp64_fast_t *mtgp64, const mtgp64_params_fast_t *para, uint64_t seed)
 This function allocates and initializes the internal state array with a 64-bit integer seed.
void mtgp64_init_state (uint64_t array[], const mtgp64_params_fast_t *para, uint64_t seed)
 This function initializes the internal state array with a 64-bit integer seed.
int mtgp64_init_by_array (mtgp64_fast_t *mtgp64, const mtgp64_params_fast_t *para, uint64_t *array, int length)
 This function allocates and initializes the internal state array with a 64-bit integer array.
int mtgp64_init_by_str (mtgp64_fast_t *mtgp64, const mtgp64_params_fast_t *para, char *array)
 This function allocates and initializes the internal state array with a character array.
void mtgp64_free (mtgp64_fast_t *mtgp64)
 This releases the memory allocated by mtgp64_init(), mtgp64_init_by_array(), mtgp64_init_by_str().
void mtgp64_print_idstring (const mtgp64_fast_t *mtgp64, FILE *fp)
 This function prints the Mersenne exponent and SHA1 of characteristic polynomial of generators state transition function.

Variables

static const uint64_t non_zero = 0x4d544750

Detailed Description

Mersenne Twister for Graphic Processors (mtgp64), which generates 64-bit unsigned integers and double precision floating point numbers based on IEEE 754 format.

Author:
Mutsuo Saito (Hiroshima University)
Makoto Matsumoto (Hiroshima University)

Copyright (C) 2009 Mutsuo Saito, Makoto Matsumoto and Hiroshima University. All rights reserved.

The new BSD License is applied to this software, see LICENSE.txt


Function Documentation

static int alloc_state ( mtgp64_fast_t mtgp64,
const mtgp64_params_fast_t para 
) [static]

This function allocates the internal state vector.

Parameters:
[in,out] mtgp64 MTGP all in one structure.
[in] para a parameter structure.
Returns:
allocation status. if 0 O.K.

References MTGP64_STATUS_FAST_T::large_mask, MTGP64_STATUS_FAST_T::large_size, MTGP64_PARAMS_FAST_T::mexp, MTGP64_FAST_T::params, MTGP64_STATUS_FAST_T::size, and MTGP64_FAST_T::status.

Referenced by mtgp64_init(), mtgp64_init_by_array(), and mtgp64_init_by_str().

static uint64_t ini_func1 ( uint64_t  x  )  [static]

This function represents a function used in the initialization by mtgp64_init_by_array() and mtgp64_init_by_str().

Parameters:
[in] x 64-bit integer
Returns:
64-bit integer

Referenced by mtgp64_init_by_array(), and mtgp64_init_by_str().

static uint64_t ini_func2 ( uint64_t  x  )  [static]

This function represents a function used in the initialization by mtgp64_init_by_array() and mtgp64_init_by_str().

Parameters:
[in] x 64-bit integer
Returns:
64-bit integer

Referenced by mtgp64_init_by_array(), and mtgp64_init_by_str().

void mtgp64_free ( mtgp64_fast_t mtgp64  ) 

This releases the memory allocated by mtgp64_init(), mtgp64_init_by_array(), mtgp64_init_by_str().

Parameters:
[in,out] mtgp64 MTGP all in one structure.

References MTGP64_FAST_T::status.

int mtgp64_init ( mtgp64_fast_t mtgp64,
const mtgp64_params_fast_t para,
uint64_t  seed 
)

This function allocates and initializes the internal state array with a 64-bit integer seed.

The allocated memory should be freed by calling mtgp64_free(). para should be one of the elements in the parameter table (mtgp64-param-ref.c).

Parameters:
[out] mtgp64 MTGP structure.
[in] para parameter structure
[in] seed a 64-bit integer used as the seed.
Returns:
memory allocation result. if 0 O.K.

References alloc_state(), MTGP64_STATUS_FAST_T::array, MTGP64_STATUS_FAST_T::idx, mtgp64_init_state(), MTGP64_STATUS_FAST_T::size, and MTGP64_FAST_T::status.

int mtgp64_init_by_array ( mtgp64_fast_t mtgp64,
const mtgp64_params_fast_t para,
uint64_t *  array,
int  length 
)

This function allocates and initializes the internal state array with a 64-bit integer array.

The allocated memory should be freed by calling mtgp64_free(). para should be one of the elements in the parameter table (mtgp64-param-ref.c).

Parameters:
[out] mtgp64 MTGP structure.
[in] para parameter structure
[in] array a 64-bit integer array used as a seed.
[in] length length of the array.
Returns:
memory allocation result. if 0 O.K.

References alloc_state(), MTGP64_STATUS_FAST_T::array, MTGP64_STATUS_FAST_T::idx, ini_func1(), ini_func2(), MTGP64_PARAMS_FAST_T::mexp, non_zero, MTGP64_FAST_T::params, MTGP64_STATUS_FAST_T::size, MTGP64_FAST_T::status, and MTGP64_PARAMS_FAST_T::tbl.

int mtgp64_init_by_str ( mtgp64_fast_t mtgp64,
const mtgp64_params_fast_t para,
char *  array 
)

This function allocates and initializes the internal state array with a character array.

The allocated memory should be freed by calling mtgp64_free(). para should be one of the elements in the parameter table (mtgp64-param-ref.c). This is the same algorithm with mtgp64_init_by_array(), but hope to be more useful.

Parameters:
[out] mtgp64 MTGP structure.
[in] para parameter structure
[in] array a character array used as a seed. (terminated by zero.)
Returns:
memory allocation result. if 0 then O.K.

References alloc_state(), MTGP64_STATUS_FAST_T::array, MTGP64_STATUS_FAST_T::idx, ini_func1(), ini_func2(), MTGP64_PARAMS_FAST_T::mexp, non_zero, MTGP64_FAST_T::params, MTGP64_STATUS_FAST_T::size, MTGP64_FAST_T::status, and MTGP64_PARAMS_FAST_T::tbl.

void mtgp64_init_state ( uint64_t  array[],
const mtgp64_params_fast_t para,
uint64_t  seed 
)

This function initializes the internal state array with a 64-bit integer seed.

The allocated memory should be freed by calling mtgp64_free(). para should be one of the elements in the parameter table (mtgp64-param-ref.c).

This function is call by cuda program, because cuda program uses another structure and another allocation method.

Parameters:
[out] array MTGP internal status vector.
[in] para parameter structure
[in] seed a 64-bit integer used as the seed.

References MTGP64_PARAMS_FAST_T::mexp, and MTGP64_PARAMS_FAST_T::tbl.

Referenced by make_kernel_data(), and mtgp64_init().

void mtgp64_print_idstring ( const mtgp64_fast_t mtgp64,
FILE *  fp 
)

This function prints the Mersenne exponent and SHA1 of characteristic polynomial of generators state transition function.

Parameters:
[in] mtgp64 MTGP all in one structure.
[in,out] fp FILE pointer.

References MTGP64_PARAMS_FAST_T::mexp, MTGP64_FAST_T::params, and MTGP64_PARAMS_FAST_T::poly_sha1.


Variable Documentation

const uint64_t non_zero = 0x4d544750 [static]

Generated on Tue Jan 5 13:44:41 2010 for MTGP by  doxygen 1.6.1