-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cpp
More file actions
105 lines (78 loc) · 2.15 KB
/
Copy pathUtils.cpp
File metadata and controls
105 lines (78 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/************************************************************************
* Copyright © 2020 The Multiphysics Modeling and Computation (M2C) Lab
* <kevin.wgy@gmail.com> <kevinw3@vt.edu>
************************************************************************/
#include <iostream>
#include <Utils.h>
#include <time.h>
#include <cstring>
using std::cout;
using std::endl;
//--------------------------------------------------
// MPI Rank 0 will print to stdout
void print(const char format[],...)
{
int rank = 0;
if(!rank) {
va_list Argp;
va_start(Argp, format);
vprintf(format, Argp);
va_end(Argp);
}
return;
}
//--------------------------------------------------
// MPI Rank 0 will print to stdout in red color
void print_error(const char format[],...)
{
int rank = 0;
if(!rank) {
char format_colored[strlen(format)+40] = "";
strcat(format_colored, "\033[0;31m");
strcat(format_colored, format);
strcat(format_colored, "\033[0m");
va_list Argp;
va_start(Argp, format);
vprintf(format_colored, Argp);
va_end(Argp);
}
return;
}
//--------------------------------------------------
// MPI Rank 0 will print to a file
void print(FILE* fd, const char format[],...)
{
int rank = 0;
if(!rank) {
va_list Argp;
va_start(Argp, format);
vfprintf(fd, format, Argp);
va_end(Argp);
}
return;
}
//--------------------------------------------------
// Get current date/time, format is YYYY-MM-DD.HH:mm:ss
const string getCurrentDateTime()
{
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
// Visit http://en.cppreference.com/w/cpp/chrono/c/strftime
// for more information about date/time format
strftime(buf, sizeof(buf), "%Y-%m-%d.%X ", &tstruct);
if(strlen(tzname[1]) != 0)
strcat(buf, tzname[1]); //daylight saving time
else
strcat(buf, tzname[0]); //standard time
return buf;
}
//--------------------------------------------------
// Terminate program properly
void exit_mpi()
{
exit(-1);
}
//--------------------------------------------------
//--------------------------------------------------