hotspotex.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*********************
  2. Hotspot Expand
  3. by Sam Kauffman - Univeristy of Virginia
  4. Generate larger input files for Hotspot by expanding smaller versions
  5. */
  6. #include "64_128.h"
  7. //#include "64_256.h"
  8. //#include "1024_2048.h"
  9. //#include "1024_4096.h"
  10. //#include "1024_8192.h"
  11. //#include "1024_16384.h"
  12. #include <iostream>
  13. #include <fstream>
  14. #include <cstdlib>
  15. #define OUT_SIZE IN_SIZE*MULTIPLIER
  16. using namespace std;
  17. void expand( char * infName, char * outfName )
  18. {
  19. const int x = MULTIPLIER;
  20. double val;
  21. fstream fs;
  22. double ** outMatr;
  23. // allocate 2d array of doubles
  24. outMatr = (double **) malloc( OUT_SIZE * sizeof( double * ) );
  25. for ( int i = 0; i < OUT_SIZE; i++ )
  26. outMatr[i] = (double *) malloc(OUT_SIZE * sizeof( double ) );
  27. // copy values into larger array
  28. fs.open( infName, ios::in );
  29. if ( !fs )
  30. cerr << "Failed to open input file.\n";
  31. for ( int row = 0; row < IN_SIZE; row++ )
  32. for ( int col = 0; col < IN_SIZE; col++ )
  33. {
  34. fs >> val;
  35. for ( int rowOff = 0; rowOff < x; rowOff++ )
  36. for ( int colOff = 0; colOff < x; colOff++ )
  37. outMatr[x * row + rowOff][x * col + colOff] = val;
  38. }
  39. fs.close();
  40. fs.open( outfName, ios::out );
  41. if ( !fs )
  42. cerr << "Failed to open output file.\n";
  43. fs.precision( 6 );
  44. fs.setf( ios::fixed );
  45. for ( int row = 0; row < OUT_SIZE; row++ )
  46. for ( int col = 0; col < OUT_SIZE; col++ )
  47. fs << outMatr[row][col] << "\n";
  48. fs.close();
  49. for ( int i = 0; i < OUT_SIZE; i++ )
  50. free( outMatr[i] );
  51. free( outMatr );
  52. }
  53. int main( int argc, char* argv[] )
  54. {
  55. expand( TEMP_IN, TEMP_OUT );
  56. expand( POWER_IN, POWER_OUT );
  57. cout << "Data written to files " << TEMP_OUT << " and " << POWER_OUT << ".\n";
  58. }