JDFTx  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Util.h File Reference

Miscellaneous utilities. More...

#include <core/MPIUtil.h>
#include <map>
#include <array>
#include <cstring>
#include <cstdio>
#include <cstdint>
#include <sys/time.h>
#include <sys/wait.h>
#include <unistd.h>
#include <execinfo.h>
#include <sys/stat.h>
#include <inttypes.h>

Classes

struct  InitParams
 Parameters used for common initialization functions. More...
 
class  StopWatch
 
class  EnumStringMap< Enum >
 A template to ease option parsing (maps enums <–> strings) More...
 

Macros

#define TIME(title, fp, code)
 Elapsed time in seconds (from start of program) More...
 
#define assert(expr)   (void)((expr) ? 0 : assertStackTraceExit(#expr, __func__, __FILE__, __LINE__))
 A custom assertion with stack trace (NOTE: enabled in release modes as well)
 
#define logPrintf(...)   fprintf(globalLog, __VA_ARGS__)
 printf() for log files
 
#define logFlush()   fflush(globalLog)
 fflush() for log files
 
#define die(...)
 Quit with an error message (formatted using printf()). Must be called from all processes. More...
 
#define die_alone(...)
 Version of die that should only be used when it is impossible to guarantee synchronized calls from all processes. More...
 
#define PRIdPTR   "zd"
 

Functions

void printVersionBanner (const InitParams *ip=0)
 Print package name, version, revision etc. to log.
 
void initSystem (int argc, char **argv, const InitParams *ip=0)
 Init MPI (if not already done), print banner, set up threads (play nice with job schedulers), GPU and signal handlers.
 
void initSystemCmdline (int argc, char **argv, InitParams &ip)
 initSystem along with commandline options
 
void finalizeSystem (bool successful=true)
 Clean-up corresponding to initSystem(), final messages (depending on successful) and clean-up MPI.
 
double clock_us ()
 
double clock_sec ()
 Elapsed time in microseconds (from start of program)
 
void printStack (bool detailedStackScript=false)
 Print a minimal stack trace and optionally write a script that, when run, will print a more detailed stacktrace.
 
void stackTraceExit (int code)
 Exit on error with stack trace.
 
int assertStackTraceExit (const char *expr, const char *function, const char *file, long line)
 
void logSuspend ()
 temporarily disable all log output (until logResume())
 
void logResume ()
 re-enable logging after a logSuspend() call
 
void Citations::add (string reason, string paper)
 
void Citations::print (FILE *fp=globalLog)
 Print the list of citations (with reasons) to the specified stream.
 
off_t fileSize (const char *filename)
 Get the size of a file.
 
void convertToLE (void *ptr, size_t size, size_t nmemb)
 Convert data from operating endianness to little-endian.
 
void convertFromLE (void *ptr, size_t size, size_t nmemb)
 Convert data from little-endian to operating endianness.
 
size_t freadLE (void *ptr, size_t size, size_t nmemb, FILE *fp)
 Read from a little-endian binary file, regardless of operating endianness.
 
size_t fwriteLE (const void *ptr, size_t size, size_t nmemb, FILE *fp)
 Write to a little-endian binary file, regardless of operating endianness.
 
uint16_t positiveRemainder (int16_t x, uint16_t y)
 For any x and y>0, compute z = x % y such that 0 <= z < y.
 
bool fftSuitable (int N)
 Check if an integer is suitable for Fast Fourier Transforms (small prime factors only)
 

Variables

string inputBasename
 Basename of input file or "stdin" that can be used as a default run-name.
 
bool killFlag
 Flag set by signal handlers - all compute loops should quit cleanly when this is set.
 
MPIUtilmpiWorld
 MPI across all processes.
 
MPIUtilmpiGroup
 MPI within current group of processes.
 
MPIUtilmpiGroupHead
 MPI across equal ranks in each group.
 
bool mpiDebugLog
 If true, all processes output to seperate debug log files, otherwise only head process outputs (set before calling initSystem())
 
size_t mempoolSize
 If non-zero, size of memory pool managed internally by JDFTx.
 
FILE * globalLog
 
FILE * nullLog
 pointer to /dev/null
 

Detailed Description

Miscellaneous utilities.