QDP++
qdp_util.cc
Go to the documentation of this file.
1//
6
7#include <cstdarg>
8#include <unistd.h>
9
10#include "qdp.h"
11
12
13// QCDOC Hack. QCDOC doesn't have gethostname(char *hostname, size_t size)
14// Must provide a suitable stub
15#ifndef HAVE_GETHOSTNAME
16
17#include "qdp_strnlen.h"
18
19int gethostname(char *hostname, size_t size)
20{
21 char *my_host_name="node";
22
23 // My Host Size returns either the length of my_host_name
24 // or the size of the supplied array - 1 char
25 // (this means that if size -1 is passed it wastes 1 char
26 size_t my_host_size=strnlen(my_host_name, size-1);
27
28 strncpy(hostname, my_host_name, my_host_size);
29
30 // Null terminate. This should be ok, because my_host_size is at most
31 // size-1;
32 hostname[my_host_size]='\0';
33 return 0;
34}
35#endif
36
37namespace QDP {
38
42int
43QDP_info (const char* format, ...)
44{
45 va_list argp;
46 char info[128], hostname[256];
47 char buffer[1024];
48
49 /* get machine host name */
50 gethostname (hostname, sizeof (hostname) - 1);
51 int rank = Layout::nodeNumber();
52 int size = Layout::numNodes();
53 sprintf (info, "QDP m%d,n%d@%s info: ",
54 rank, size, hostname);
55
56 va_start (argp, format);
57 int status = vsprintf (buffer, format, argp);
58 va_end (argp);
59
60 fprintf (stdout, "%s %s\n", info, buffer);
61 return status;
62}
63
64
68int
69QDP_error (const char* format, ...)
70{
71 va_list argp;
72 char info[128], hostname[256];
73 char buffer[1024];
74
75 /* get machine host name */
76 gethostname (hostname, sizeof (hostname) - 1);
77 int rank = Layout::nodeNumber();
78 int size = Layout::numNodes();
79 sprintf (info, "QDP m%d,n%d@%s error: ", rank, size, hostname);
80
81 va_start (argp, format);
82 int status = vsprintf (buffer, format, argp);
83 va_end (argp);
84
85 fprintf (stderr, "%s %s\n", info, buffer);
86 return status;
87}
88
92void
93QDP_error_exit (const char* format, ...)
94{
95 va_list argp;
96 char info[128], hostname[256];
97 char buffer[1024];
98
99 /* get machine host name */
100 gethostname (hostname, sizeof (hostname) - 1);
101 int rank = Layout::nodeNumber();
102 int size = Layout::numNodes();
103 sprintf (info, "QDP m%d,n%d@%s fatal error: ", rank, size, hostname);
104
105 va_start (argp, format);
106 vsprintf (buffer, format, argp);
107 va_end (argp);
108
109 fprintf (stderr, "%s %s\n", info, buffer);
110
111 QDP_abort(1); // Abort knows how to shutdown the machine
112}
113
117void
118QDP_verbose (bool verbose)
119{
120 // Currently a NOP
121}
122
123
124//-----------------------------------------------------------------------------
126
127multi1d<int>
129{
130 multi1d<int> d(ll.size());
131
132 // Enter the first element as unique to prime the search
133 int ipos = 0;
134 int num = 0;
135 int prev_node;
136
137 d[num++] = prev_node = ll[ipos++];
138
139 // Find the unique source nodes
140 while (ipos < ll.size())
141 {
142 int this_node = ll[ipos++];
143
144 if (this_node != prev_node)
145 {
146 // Has this node occured before?
147 bool found = false;
148 for(int i=0; i < num; ++i)
149 if (d[i] == this_node)
150 {
151 found = true;
152 break;
153 }
154
155 // If this is the first time this value has occurred, enter it
156 if (! found)
157 d[num++] = this_node;
158 }
159
160 prev_node = this_node;
161 }
162
163 // Copy into a compact size array
164 multi1d<int> dd(num);
165 for(int i=0; i < num; ++i)
166 dd[i] = d[i];
167
168 return dd;
169}
170
171
172} // namespace QDP;
Container for a multi-dimensional 1D array.
Definition qdp_multi.h:25
int size() const
Size of array.
Definition qdp_multi.h:60
int nodeNumber()
Returns the node number of this node.
int numNodes()
Returns the number of nodes.
Yet another random number generator.
void QDP_error_exit(const char *format,...)
Simple error display and abort routine.
Definition qdp_util.cc:93
int QDP_error(const char *format,...)
Simple error display routine.
Definition qdp_util.cc:69
void QDP_verbose(bool verbose)
Definition qdp_util.cc:118
multi1d< int > uniquify_list(const multi1d< int > &ll)
Unique-ify a list.
Definition qdp_util.cc:128
void QDP_abort(int status)
Panic button.
int QDP_info(const char *format,...)
Simple information display routine.
Definition qdp_util.cc:43
Primary include file for QDP.
int gethostname(char *, size_t)
Definition qdp_util.cc:19
size_t strnlen(const char *s, size_t maxlen)
int gethostname(char *hostname, size_t size)
Definition qdp_util.cc:19