MACSio  0.9
Multi-purpose, Application-Centric, Scalable I/O Proxy App
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
tstlog.c
Go to the documentation of this file.
1 /*
2 Copyright (c) 2015, Lawrence Livermore National Security, LLC.
3 Produced at the Lawrence Livermore National Laboratory.
4 Written by Mark C. Miller
5 
6 LLNL-CODE-676051. All rights reserved.
7 
8 This file is part of MACSio
9 
10 Please also read the LICENSE file at the top of the source code directory or
11 folder hierarchy.
12 
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License (as published by the Free Software
15 Foundation) version 2, dated June 1991.
16 
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the terms and conditions of the GNU General
20 Public License for more details.
21 
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
24 Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26 
27 #include <errno.h>
28 #include <stdlib.h>
29 #include <strings.h>
30 
31 #include <macsio_log.h>
32 
33 #ifdef HAVE_MPI
34 #include <mpi.h>
35 #endif
36 
37 int main (int argc, char **argv)
38 {
39  int i;
40  int rank=0, size=1;
41  int num_cols = 128, num_rows = 20, extra_lines = 20;
42 
43  for (i = 0; i < argc; i++)
44  {
45  if (!strncasecmp(argv[i], "num_cols=", 9))
46  num_cols = strtol(argv[i]+9, 0, 10);
47  else if (!strncasecmp(argv[i], "num_rows=", 9))
48  num_rows = strtol(argv[i]+9, 0, 10);
49  else if (!strncasecmp(argv[i], "extra_lines=", 9))
50  extra_lines = strtol(argv[i]+9, 0, 10);
51  }
52 
53 #ifdef HAVE_MPI
54  MPI_Init(&argc, &argv);
55  MPI_Comm_size(MPI_COMM_WORLD, &size);
56  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
57 #endif
58 
59  MACSIO_LOG_DebugLevel = 2; /* should only see debug messages level 1 and 2 */
60  MACSIO_LOG_MainLog = MACSIO_LOG_LogInit(MPI_COMM_WORLD, "tstlog.log", num_cols, num_rows, extra_lines);
61  MACSIO_LOG_StdErr = MACSIO_LOG_LogInit(MPI_COMM_WORLD, 0, 0, 0, 0);
62 
63  if (rank == 1)
64  {
65  MACSIO_LOG_MSG(Dbg1, ("I am staring with processor 1"));
66  MACSIO_LOG_MSG(Dbg2, ("Test output of a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long line"));
67  }
68  else if (rank == 2)
69  {
70  MACSIO_LOG_MSG(Warn, ("Starting on proc 2"));
71  MACSIO_LOG_LogMsg(MACSIO_LOG_StdErr, "Logging a message to stderr for rank %d", rank);
72  }
73  else if (rank == 0)
74  {
75  errno = EOVERFLOW;
76  mpi_errno = MPI_ERR_COMM;
77  MACSIO_LOG_MSG(Err, ("I am here on proc 0"));
78  }
79  else
80  {
81  int i;
83  for (i = 0; i < 25; i++)
84  {
85  MACSIO_LOG_MSGV(sev, ("Outputing line %d for rank %d\n", i, rank));
86  }
87  }
88 
91 
92 #ifdef HAVE_MPI
93  MPI_Finalize();
94 #endif
95 
96  return 0;
97 
98 }
MACSIO_LOG_LogHandle_t * MACSIO_LOG_StdErr
Log handle for MACSIO's stderr output.
Definition: macsio_log.c:46
int mpi_errno
Error code returned by most recent MPI call.
Definition: macsio_log.c:43
MACSIO_LOG_LogHandle_t * MACSIO_LOG_LogInit(MPI_Comm comm, char const *path, int line_len, int lines_per_proc, int extra_lines_proc0)
Initialize a log.
Definition: macsio_log.c:113
enum _MACSIO_LOG_MsgSeverity_t MACSIO_LOG_MsgSeverity_t
void MACSIO_LOG_LogFinalize(MACSIO_LOG_LogHandle_t *log)
Finalize and close an open log Should be called collectively by all processors that created the log...
Definition: macsio_log.c:295
int MACSIO_LOG_DebugLevel
Definition: macsio_log.c:44
MACSIO_LOG_LogHandle_t * MACSIO_LOG_MainLog
Log handle for MACSIO's main log.
Definition: macsio_log.c:45
int main(int argc, char **argv)
Definition: tstlog.c:37
void MACSIO_LOG_LogMsg(MACSIO_LOG_LogHandle_t const *log, char const *fmt,...)
Issue a printf-style message to a log.
Definition: macsio_log.c:186
#define MACSIO_LOG_MSGV(VSEV, MSG)
Definition: macsio_log.h:141
#define MACSIO_LOG_MSG(SEV, MSG)
Convenience macro for logging a message to the main log.
Definition: macsio_log.h:133