1 /*$Id: ploginfo.c,v 1.22 2001/03/23 23:20:50 balay Exp $*/
2 /*
3       DSDPLogInfo() is contained in a different file from the other profiling to
4    allow it to be replaced at link time by an alternative routine.
5 */
6 #include <stdarg.h>
7 #include <sys/types.h>
8 #include <stdlib.h>
9 /*#include <malloc.h> */ /* Commented out since it is obsolete and causes compilation problems on OS X.*/
10 #include "dsdpsys.h"
11 #include "dsdpbasictypes.h"
12 
13 #define DSDP_NULL 0
14 #define DSDP_MAX_PATH_LEN 200
15 
16 /*!
17 \file dsdploginfo.c
18 \brief Print the progress of the DSDP solver.
19 */
20 
21 typedef void* DSDPObject;
22 /*
23 extern FILE *dsdp_history;
24 */
25 static FILE *dsdp_history=0;
26 /*
27   The next three variables determine which, if any, DSDPLogInfo() calls are used.
28   If DSDPLogPrintInfo is zero, no info messages are printed.
29   If DSDPLogPrintInfoNull is zero, no info messages associated with a null object are printed.
30 
31   If DSDPLogInfoFlags[OBJECT_COOKIE - DSDP_COOKIE] is zero, no messages related
32   to that object are printed. OBJECT_COOKIE is, for example, MAT_COOKIE.
33 */
34 static int DSDPLogPrintInfo     = 0;
35 static int DSDPLogPrintInfoNull = 0;
36 static FILE      *DSDPLogInfoFile      = DSDP_NULL;
37 static int rank=0;
38 
DSDPSetRank(int rrank)39 void DSDPSetRank(int rrank){
40   rank=rrank;
41   return;
42 }
43 
44 #undef __FUNCT__
45 #define __FUNCT__ "DSDPLogInfoAllow"
46 /*@C
47     DSDPLogInfoAllow - Causes DSDPLogInfo() messages to be printed to standard output.
48 
49     Not Collective, each processor may call this seperately, but printing is only
50     turned on if the lowest processor number associated with the DSDPObject associated
51     with the call to DSDPLogInfo() has called this routine.
52 
53     Input Parameter:
54 +   flag - DSDP_TRUE or DSDP_FALSE
55 -   filename - optional name of file to write output to (defaults to stdout)
56 
57     Options Database Key:
58 .   -log_info [optional filename] - Activates DSDPLogInfoAllow()
59 
60     Level: advanced
61 
62    Concepts: debugging^detailed runtime information
63    Concepts: dumping detailed runtime information
64 
65 .seealso: DSDPLogInfo()
66 @*/
DSDPLogInfoAllow(int flag,char * filename)67 int DSDPLogInfoAllow(int flag, char *filename)
68 {
69   char fname[DSDP_MAX_PATH_LEN], tname[5];
70   int  prank=0;
71   char*  ierr;
72 
73   DSDPFunctionBegin;
74   if (flag && filename) {
75     sprintf(tname, ".%d", prank);
76     ierr = strcat(fname, tname);
77   } else if (flag) {
78     DSDPLogInfoFile = stdout;
79   }
80   DSDPLogPrintInfo     = flag;
81   DSDPLogPrintInfoNull = flag;
82   DSDPFunctionReturn(0);
83 }
84 
85 #undef __FUNCT__
86 #define __FUNCT__ "DSDPLogInfo"
87 /*@C
88     DSDPLogInfo - Logs informative data, which is printed to standard output
89     or a file when the option -log_info <file> is specified.
90 
91     Collective over DSDPObject argument
92 
93     Input Parameter:
94 +   vobj - object most closely associated with the logging statement
95 -   message - logging message, using standard "printf" format
96 
97     Options Database Key:
98 $    -log_info : activates printing of DSDPLogInfo() messages
99 
100     Level: intermediate
101 
102     Example of Usage:
103 $
104 $     double alpha
105 $     DSDPLogInfo(0,"Matrix uses parameter alpha=%g\n",alpha);
106 $
107 
108    Concepts: runtime information
109 
110 .seealso: DSDPLogInfoAllow()
111 @*/
DSDPLogFInfo(void * vobj,int outlevel,const char message[],...)112 void  DSDPLogFInfo(void *vobj, int outlevel, const char message[], ...)
113 {
114   va_list     Argp;
115   int         urank;
116   size_t      len;
117   char        string[8*1024];
118 
119   DSDPFunctionBegin;
120   DSDPLogInfoFile = stdout;
121   if (DSDPLogPrintInfo < outlevel) return;
122   if ((DSDPLogPrintInfoNull < outlevel) && !vobj) return;
123 
124   urank = 0;
125   if (rank>0) return;
126 
127   va_start(Argp, message);
128   sprintf(string, "[%d][%2d] DSDP: ", rank,outlevel);
129   len = strlen(string);
130 #if defined(DSDP_HAVE_VPRINTF_CHAR)
131   vsprintf(string+len, message, (char *) Argp);
132 #else
133   vsprintf(string+len, message, Argp);
134 #endif
135   fprintf(DSDPLogInfoFile, "%s", string);
136   fflush(DSDPLogInfoFile);
137   if (dsdp_history) {
138 #if defined(DSDP_HAVE_VPRINTF_CHAR)
139     vfprintf(dsdp_history, message, (char *) Argp);
140 #else
141     vfprintf(dsdp_history, message, Argp);
142 #endif
143   }
144   va_end(Argp);
145   return;
146   /*  DSDPFunctionReturn(0); */
147 }
148