CoMD
A Mini-app for Co-Design of Classical Molecular Dynamics.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
yamlOutput.c
Go to the documentation of this file.
1 /// \file
2 /// Write simulation information in YAML format.
3 ///
4 /// Information regarding platform, run parameters, performance, etc.,
5 /// are written to a file whose name is generated from the CoMDVariant
6 /// and the time of the run. This provides a simple mechanism to track
7 /// and compare performance etc.
8 ///
9 /// There are much more sophisticated libraries and routines available
10 /// to handle YAML, but this simple implemenation handles everything we
11 /// really need.
12 
13 #include "yamlOutput.h"
14 
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <time.h>
18 
19 #include "CoMD_info.h"
20 #include "mytype.h"
21 #include "parallel.h"
22 
23 FILE* yamlFile = NULL;
24 
25 static const char* CoMDVersion = "1.1";
26 static const char* CoMDVariant = CoMD_VARIANT;
27 
28 static void getTimeString(char* timestring)
29 {
30  time_t rawtime;
31  struct tm* timeinfo;
32  time(&rawtime);
33  timeinfo = localtime(&rawtime);
34 
35  sprintf(timestring,
36  "%4d-%02i-%02d, %02d:%02d:%02d",
37  timeinfo->tm_year+1900,
38  timeinfo->tm_mon+1,
39  timeinfo->tm_mday,
40  timeinfo->tm_hour,
41  timeinfo->tm_min,
42  timeinfo->tm_sec);
43 }
44 
45 void yamlBegin(void)
46 {
47  if (! printRank())
48  return;
49 
50  char filename[64];
51  time_t rawtime;
52  time (&rawtime);
53  struct tm* ptm = localtime(&rawtime);
54  char sdate[25];
55  //use tm_mon+1 because tm_mon is 0 .. 11 instead of 1 .. 12
56  sprintf (sdate,"%04d:%02d:%02d-%02d:%02d:%02d",
57  ptm->tm_year + 1900, ptm->tm_mon+1,
58  ptm->tm_mday, ptm->tm_hour, ptm->tm_min,ptm->tm_sec);
59  sprintf(filename, "%s.%s.yaml", CoMDVariant, sdate);
60  yamlFile = fopen(filename, "w");
61 }
62 
63 void yamlAppInfo(FILE* file)
64 {
65  if (! printRank())
66  return;
67  printSeparator(file);
68  fprintf(file,"Mini-Application Name : %s\n", CoMDVariant);
69  fprintf(file,"Mini-Application Version : %s\n", CoMDVersion);
70  fprintf(file,"Platform:\n");
71  fprintf(file," hostname: %s\n", CoMD_HOSTNAME);
72  fprintf(file," kernel name: %s\n", CoMD_KERNEL_NAME);
73  fprintf(file," kernel release: %s\n", CoMD_KERNEL_RELEASE);
74  fprintf(file," processor: %s\n", CoMD_PROCESSOR);
75  fprintf(file,"Build:\n");
76  fprintf(file," CC: %s\n", CoMD_COMPILER);
77  fprintf(file," compiler version: %s\n", CoMD_COMPILER_VERSION);
78  fprintf(file," CFLAGS: %s\n", CoMD_CFLAGS);
79  fprintf(file," LDFLAGS: %s\n", CoMD_LDFLAGS);
80  fprintf(file," using MPI: %s\n", builtWithMpi() ? "true":"false");
81  fprintf(file," Threading: none\n");
82  fprintf(file," Double Precision: %s\n", (sizeof(real_t)==sizeof(double)?"true":"false"));
83  char timestring[32];
84  getTimeString(timestring);
85  fprintf(file,"Run Date/Time: %s\n", timestring);
86  fprintf(file, "\n");
87  fflush(file);
88 }
89 
90 void yamlEnd(void)
91 {
92  if (! printRank())
93  return;
94 
95  fclose(yamlFile);
96 }
97 
98 void printSeparator(FILE* file)
99 {
100  //fprintf(file,"=========================================================================\n");
101  fprintf(file,"\n");
102 }
103