Changeset 3801


Ignore:
Timestamp:
04/20/12 23:04:26 (2 years ago)
Author:
elgoodm
Message:

New method with meta programming.

Location:
trunk/experimental
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/experimental/mtgl/stream_counter.hpp

    r3800 r3801  
    4242 
    4343#pragma mta no inline 
    44 template <unsigned long num> 
     44template <int num> 
    4545static unsigned long stream_count() { 
    4646  unsigned long stream_id = 0; 
     
    4848  unsigned long rvalue; 
    4949 
    50   #pragma mta use num streams 
     50  #pragma mta use 1 streams 
    5151  #pragma mta for all streams stream_id of num_streams 
    5252  { 
     
    5555    } 
    5656  } 
     57   
     58  rvalue = rvalue * num; 
     59 
     60  return rvalue; 
    5761} 
    5862 
  • trunk/experimental/test/test_stream_counter.cpp

    r3799 r3801  
    1111 
    1212/****************************************************************************/ 
    13 /*! \file test_bfs_hashing.cpp 
     13/*! \file test_stream_counter.cpp 
    1414 
    1515    \author Eric Goodman (elgoodm@sandia.gov) 
     
    2020 
    2121#include <iostream> 
     22#include <string> 
    2223#include <mtgl/stream_counter.hpp> 
     24 
    2325 
    2426#ifdef _OPENMP 
     
    2830using namespace mtgl; 
    2931 
     32#define STREAMS_80 80 
     33#define STREAMS_100 100 
     34 
    3035int main(int argc, char* argv[]) { 
    3136 
     
    3338 
    3439  mt_timer timer; 
     40  unsigned long num_streams; 
     41  unsigned long stream_id; 
     42  unsigned long record_stream_count; 
    3543 
    36   std::cout << "Testing stream_cout.hpp." << std::endl 
     44  std::cout << "Testing stream_count.hpp." << std::endl 
    3745            << "------------------------" << std::endl; 
    3846 
    39   std::cout << "Testing first initialization overhead" << std::endl; 
     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; 
    4061  timer.start(); 
    41   unsigned long num_streams = stream_count<80>; 
     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 
    42172 
    43173#endif 
Note: See TracChangeset for help on using the changeset viewer.