source: trunk/experimental/test/test_stream_counter.cpp @ 3801

Revision 3801, 5.7 KB checked in by elgoodm, 2 years ago (diff)

New method with meta programming.

Line 
1/*  _________________________________________________________________________
2 *
3 *  MTGL: The MultiThreaded Graph Library
4 *  Copyright (c) 2008 Sandia Corporation.
5 *  This software is distributed under the BSD License.
6 *  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
7 *  the U.S. Government retains certain rights in this software.
8 *  For more information, see the README file in the top MTGL directory.
9 *  _________________________________________________________________________
10 */
11
12/****************************************************************************/
13/*! \file test_stream_counter.cpp
14
15    \author Eric Goodman (elgoodm@sandia.gov)
16
17    \date 8/18/2011
18*/
19/****************************************************************************/
20
21#include <iostream>
22#include <string>
23#include <mtgl/stream_counter.hpp>
24
25
26#ifdef _OPENMP
27#include <omp.h>
28#endif
29
30using namespace mtgl;
31
32#define STREAMS_80 80
33#define STREAMS_100 100
34
35int main(int argc, char* argv[]) {
36
37#ifdef __MTA__
38
39  mt_timer timer;
40  unsigned long num_streams;
41  unsigned long stream_id;
42  unsigned long record_stream_count;
43
44  std::cout << "Testing stream_count.hpp." << std::endl
45            << "------------------------" << std::endl;
46
47
48  std::string explanation =
49  "The following makes two calls to stream_count with 80\n"
50  "streams as the target.  There is usually an overhead\n"
51  "associated with the first for loop so there might be\n"
52  "a difference from the first to the second.  However\n"
53  "stream_count() works by only requesting one stream\n"
54  "and then multiplying the result by the streams per\n"
55  "proc, so the overhead might not be as high as normal.\n"
56  "Note the overhead grows with larger proc counts.\n";
57
58  std::cout << explanation << std::endl;
59
60  std::cout << STREAMS_80 << " streams requested per proc." << std::endl;
61  timer.start();
62  num_streams = stream_count<STREAMS_80>();
63  record_time(timer, "Time for first initialization:\t");
64  std::cout << "Number of streams reported: " << num_streams << std::endl;
65  std::cout << "Estimated procs: "
66            << static_cast<double>(num_streams) / STREAMS_80 << std::endl;
67
68  timer.start();
69  num_streams = stream_count<STREAMS_80>();
70  record_time(timer, "Time for second initialization:\t");
71  std::cout << "Number of streams reported: " << num_streams << std::endl;
72  std::cout << "Estimated procs: "
73            << static_cast<double>(num_streams) / STREAMS_80 << std::endl;
74  std::cout << std::endl;
75
76  explanation =
77  "Doing the same thing but trying with 120 streams, the max\n"
78  "possible.  If we actually requested 120, we wouldn't get it,\n"
79  "but since stream_count only requests 1 stream and then\n"
80  "multiplies, we might actually get num_procs * 120.\n";
81
82  std::cout << explanation << std::endl;
83
84  std::cout << STREAMS_100 << " streams requested per proc." << std::endl;
85  timer.start();
86  num_streams = stream_count<STREAMS_100>();
87  record_time(timer, "Time for first initialization:\t");
88  std::cout << "Number of streams reported: " << num_streams << std::endl;
89  std::cout << "Estimated procs: "
90            << static_cast<double>(num_streams) / STREAMS_100 << std::endl;
91
92  timer.start();
93  num_streams = stream_count<STREAMS_100>();
94  record_time(timer, "Time for second initialization:\t");
95  std::cout << "Number of streams reported: " << num_streams << std::endl;
96  std::cout << "Estimated procs: "
97            << static_cast<double>(num_streams) / STREAMS_100 << std::endl;
98  std::cout << std::endl;
99
100
101
102
103  explanation =
104  "Now we try a for loop with a high number of streams, 100.\n"
105  "Again we try two different initializations.  The loops do nothing\n"
106  "except record the number of streams.\n";
107 
108  std::cout << explanation << std::endl;
109
110  timer.start();
111  #pragma mta use 100 streams
112  #pragma mta for all streams stream_id of num_streams
113  {
114    if (stream_id == 0) {
115      record_stream_count = num_streams;
116    }
117  }
118  record_time(timer, "Time for 1st initialization of 100 streams per proc:\t");
119  std::cout << "Number of streams reported: " << record_stream_count
120            << std::endl;
121  std::cout << "Estimated procs: "
122            << static_cast<double>(record_stream_count) / 100 << std::endl;
123
124  timer.start();
125  #pragma mta use 100 streams
126  #pragma mta for all streams stream_id of num_streams
127  {
128    if (stream_id == 0) {
129      record_stream_count = num_streams;
130    }
131  }
132  record_time(timer, "Time for 2nd initialization of 100 streams per proc:\t");
133  std::cout << "Number of streams reported: " << record_stream_count
134            << std::endl;
135  std::cout << "Estimated procs: "
136            << static_cast<double>(record_stream_count) / 100 << std::endl;
137
138  explanation =
139  "Going down to 60 to see if there is a penalty for\n"
140  "switching stream counts.\n";
141 
142  std::cout << explanation << std::endl;
143
144  timer.start();
145  #pragma mta use 60 streams
146  #pragma mta for all streams stream_id of num_streams
147  {
148    if (stream_id == 0) {
149      record_stream_count = num_streams;
150    }
151  }
152  record_time(timer, "Time for 1st initialization of 60 streams per proc:\t");
153  std::cout << "Number of streams reported: " << record_stream_count
154            << std::endl;
155  std::cout << "Estimated procs: "
156            << static_cast<double>(record_stream_count) / 60 << std::endl;
157
158  timer.start();
159  #pragma mta use 60 streams
160  #pragma mta for all streams stream_id of num_streams
161  {
162    if (stream_id == 0) {
163      record_stream_count = num_streams;
164    }
165  }
166  record_time(timer, "Time for 2nd initialization of 60 streams per proc:\t");
167  std::cout << "Number of streams reported: " << record_stream_count
168            << std::endl;
169  std::cout << "Estimated procs: "
170            << static_cast<double>(record_stream_count) / 60 << std::endl;
171
172
173#endif
174
175  return 0;
176}
Note: See TracBrowser for help on using the repository browser.