Quick Reference for the Default Interface
Header files and Macros
C++: Include the header file sprng_cpp.h.
FORTRAN: Include the header file sprng_f.h.Define the following macro before including a SPRNG header file:
CHECK_POINTERS to obtain the interface with pointer checking.
FLOAT_GEN to obtain single precision numbers when calling sprng, instead of the double precision default.
USE_MPI to get the same seed on all processors with make_sprng_seed in the MPI version.sprng_f.h defines the macro SPRNG_POINTER to be a FORTRAN integer large enough to hold a C pointer. Generally, automake/autoconf will detect this properly and define SPRNG_POINTER appropriately. However, if this is not the case, then either the macro SPRNG_POINTER=
should be defined before including the header file, or this should be done through a compiler option (typically -DSPRNG_POINTER=8). SPRNG Functions
The C++ call is given first, followed by the FORTRAN call.Note that all C++ functions calls in the default interface have the form
return_type SprngObject->function_name(parameters);
- int init_sprng (int streamnum, int nstreams, int seed, int param)
- Sprng(int streamnum, int nstreams, int seed, int param) (Constructor)
- SPRNG_POINTER init_sprng(integer rng_type, integer streamnum, integer nstreams, integer seed, integer param)
- Initialize a random number stream with seed seed and parameter param. streamnum is the stream number and must be in [0,nstreams-1]. nstreams is the number of different streams that will be initialized (on all the processors). In C++, init_sprng stores the stream ID as the SPRNG object, and returns 1 for success and 0 for failure. In FORTRAN, init_sprng returns the stream ID.
- double sprng()
- real*8 sprng(SPRNG_POINTER stream)
- The next random number in [0,1) from the SPRNG object / stream with ID stream is returned.
- int isprng()
- integer isprng(SPRNG_POINTER stream)
- The next random number in [0,231) from the SPRNG object / stream with ID stream is returned.
- int print_sprng()
- ostream& operator<<(ostream &os, Sprng & SprngObj);
- integer print_sprng(SPRNG_POINTER stream)
- Print information about a stream with SPRNG object / ID stream.
- int make_sprng_seed()
- integer make_sprng_seed()
- Produce a seed. Define USE_MPI to get the same seed on all processors with the MPI version.
- int pack_sprng(char **buffer)
- integer pack_sprng(SPRNG_POINTER stream, character fbuffer)
- Pack the SPRNG object / stream with ID stream into an array and return the number of bytes of storage required. fbuffer is an array of size MAX_PACKED_LENGTH. In C++, SPRNG allocates memory and has the result stored in *buffer.
- int unpack_sprng(char *buffer
- SPRNG_POINTER unpack_sprng(character buffer)
- This function recreates the stream that had been packed into buffer. In C++, this function stores the stream as the SPRNG object and returns 1 for success and 0 for failure. In FORTRAN, this function returns an ID after recreating the stream that had been packed into buffer.
- int free_sprng()
- integer free_sprng(SPRNG_POINTER stream)
- Free memory used to store the SPRNG object / state of the stream with ID stream. Return the number of streams available on the process.
- int spawn_sprng(int nspawned, int ***newstreams)
- integer spawn_sprng(SPRNG_POINTER stream, integer nspawned, SPRNG_POINTER fnewstreams)
- Spawn nspawned new SPRNG object / streams from an exiting one with ID stream. fnewstreams is an array of size at least nspawned in which the ID's of the new streams are stored. In C++, SPRNG allocates memory and makes *newstreams point to this array. The number of streams successfully spawned is returned.