Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

system.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <math.h>
00005 #include <time.h>
00006 #include <sys/time.h>
00007 #include <sys/resource.h>
00008 #include <unistd.h>
00009 #include <signal.h>
00010 #include <gsl/gsl_rng.h>
00011 #include <mpi.h>
00012 
00013 #include "allvars.h"
00014 #include "proto.h"
00015 
00016 
00029 double get_random_number(int id)
00030 {
00031   return RndTable[(id % RNDTABLE)];
00032 }
00033 
00034 
00037 void set_random_numbers(void)
00038 {
00039   int i;
00040 
00041   for(i = 0; i < RNDTABLE; i++)
00042     RndTable[i] = gsl_rng_uniform(random_generator);
00043 }
00044 
00045 
00049 double second(void)
00050 {
00051 #ifdef WALLCLOCK
00052   return MPI_Wtime();
00053 #else
00054   return ((double) clock()) / CLOCKS_PER_SEC;
00055 #endif
00056   
00057   /* note: on AIX and presumably many other 32bit systems, 
00058    * clock() has only a resolution of 10ms=0.01sec 
00059    */
00060 }
00061 
00062 
00070 double timediff(double t0, double t1)
00071 {
00072   double dt;
00073 
00074   dt = t1 - t0;
00075 
00076   if(dt < 0)    /* overflow has occured (for systems with 32bit tick counter) */
00077     {
00078 #ifdef WALLCLOCK
00079       dt = 0;
00080 #else
00081       dt = t1 + pow(2, 32) / CLOCKS_PER_SEC - t0;
00082 #endif
00083     }
00084 
00085   return dt;
00086 }
00087 
00088 
00091 double dmax(double x, double y)
00092 {
00093   if(x > y)
00094     return x;
00095   else
00096     return y;
00097 }
00098 
00101 double dmin(double x, double y)
00102 {
00103   if(x < y)
00104     return x;
00105   else
00106     return y;
00107 }
00108 
00111 int imax(int x, int y)
00112 {
00113   if(x > y)
00114     return x;
00115   else
00116     return y;
00117 }
00118 
00121 int imin(int x, int y)
00122 {
00123   if(x < y)
00124     return x;
00125   else
00126     return y;
00127 }

Generated on Sun May 22 17:33:29 2005 for GADGET-2 by  doxygen 1.3.9.1