Changeset 22f928f for memlog.cpp


Ignore:
Timestamp:
05/31/15 09:46:11 (9 years ago)
Author:
Hal Finkel <hfinkel@…>
Branches:
master
Children:
4598848
Parents:
a7b97b9
git-author:
Hal Finkel <hfinkel@…> (05/31/15 09:46:11)
git-committer:
Hal Finkel <hfinkel@…> (05/31/15 09:46:11)
Message:

use the job id under batch systems; misc cleanups

File:
1 edited

Legend:

Unmodified
Added
Removed
  • memlog.cpp

    ra7b97b9 r22f928f  
    3737//   -Wl,--wrap,malloc,--wrap,free,--wrap,realloc,--wrap,calloc,--wrap,memalign /path/to/memlog_s.o -lpthread -ldl 
    3838 
    39 FILE *log_file = NULL; 
     39FILE *log_file = 0; 
    4040static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; 
    4141 
     
    5858#endif 
    5959 
     60  // If we're running under a common batch system, add the job id to the output 
     61  // file names (add it as a prefix so that sorting the files will sort by job 
     62  // first). 
     63  char *job_id = 0; 
     64  const char *job_id_vars[] = 
     65    { "COBALT_JOBID", "PBS_JOBID", "SLURM_JOB_ID", "JOB_ID" }; 
     66  for (int i = 0; i < sizeof(job_id_vars)/sizeof(job_id_vars[0]); ++i) { 
     67    job_id = getenv(job_id_vars[i]); 
     68    if (job_id) 
     69      break; 
     70  } 
     71 
    6072  char log_name[PATH_MAX+1]; 
    61   snprintf(log_name, PATH_MAX+1, "%s.%d.memlog", u.nodename, id); 
     73  if (job_id) 
     74    snprintf(log_name, PATH_MAX+1, "%s.%s.%d.memlog", job_id, u.nodename, id); 
     75  else 
     76    snprintf(log_name, PATH_MAX+1, "%s.%d.memlog", u.nodename, id); 
    6277  log_file = fopen(log_name, "w"); 
    6378  if (!log_file) 
Note: See TracChangeset for help on using the changeset viewer.