Skip to content

Commit

Permalink
Add Linux memory check; set N_RAYS based on available RAM
Browse files Browse the repository at this point in the history
Add check for available memory in Linux (in addition to extant Mac check).  Use
that value to compute N_RAYS to fill that space.  Criteria is to use no more
than 4 GB of RAM for a cycle of rays, or 1/4 of the system memory, whichever is
smaller.

The idea will be to allow the code to loop through the ray-tracing multiple
times in order to build up the proper S/N in the various downstream optical
planes.

	modified:   src/init.c
  • Loading branch information
tbowers7 committed Sep 22, 2017
1 parent f64a9e3 commit bbf20e9
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

/* Include packages */
#include <stdio.h>
#include <gsl/gsl_math.h>

#if HAVE__LINUX // Linux system information
# include <sys/sysinfo.h>
Expand All @@ -41,6 +42,7 @@

/* Local headers */
#include "init.h"
#include "rays.h"


int init_get_sysinfo(void){
Expand All @@ -49,35 +51,49 @@ int init_get_sysinfo(void){
#if HAVE__LINUX
struct sysinfo s;
sysinfo(&s);
//printf("Linux-y-linux?\n");
SYS_RAM = 0;
SYS_RAM = (double)s.totalram / 1024. / 1024.; // in MB

#elif HAVE__MAC
size_t size;
unsigned long long memsize;
sysctlbyname("HW_MEMSIZE", &memsize, &size, NULL, 0);

SYS_RAM = (double)memsize / 1024. / 1024.; // In MB
//printf("Memory size: %ld %0d MB\n",memsize,(int)floor(SYS_RAM));

#else
//printf("Something else?\n");
SYS_RAM = 0;
#endif




#endif

return 0;
}


int init_set_nrays(void){

/* Variable Declarations */
size_t raysize;
int memsize;

/* Check against system type -- if SYS_RAM == 0, default to set value */
if(SD_SYS == 52){
N_RAYS = 1e7;
return 1;
}

/*********************************************************/
/* We want the RAM used by a set of rays to be 4GB or */
/* 1/4 of the total system memory, whichever is smaller. */
/*********************************************************/

/* Determine amount of "usable" memory, given dictum */
memsize = GSL_MIN_INT( 4096, (int)floor((float)SYS_RAM / 4.) );

/* Get size of a single ray */
raysize = sizeof(scope_ray);

/* How to do everything */
N_RAYS = 1e7;
/* Compute number of rays that will fit within the RAM */
N_RAYS = (unsigned int) floor( (double)memsize * 1024. * 1024. /
(double)raysize );

return 0;
}

0 comments on commit bbf20e9

Please sign in to comment.