Matrix Library
A simple Matrix operation library to perform Matrix Multiplication and find the transpose of a Matrix.
configure_lib.cpp File Reference

A Cpp configuration file to find the best leaf size for Stressan's Algorithm and generate a "configure.txt" file. This file evaluates the execution time of the MATOPS::BigMatrix<Data1>::matmul() function as function of different LEAF_SIZE values. This flag is always run with the SET_LEAF_SIZE flag. This flag enables the matrix.h file to run in configuration mode. Thus enabling configure_lib.cpp to vary LEAF_SIZE variable of matrx.h and find the most optimal LEAF_SIZE value. For a given LEAF_SIZE value this program calls MATOPS::BigMatrix<Data1>::matmul() N_epoch (>2) no. of times and finds out the average execution time of MATOPS::BigMatrix<Data1>::matmul() for that particular LEAF_SIZE. Use the following command to run the configure_lib.cpp file. More...

Functions

int main (int argc, char **argv)
 

Detailed Description

A Cpp configuration file to find the best leaf size for Stressan's Algorithm and generate a "configure.txt" file. This file evaluates the execution time of the MATOPS::BigMatrix<Data1>::matmul() function as function of different LEAF_SIZE values. This flag is always run with the SET_LEAF_SIZE flag. This flag enables the matrix.h file to run in configuration mode. Thus enabling configure_lib.cpp to vary LEAF_SIZE variable of matrx.h and find the most optimal LEAF_SIZE value. For a given LEAF_SIZE value this program calls MATOPS::BigMatrix<Data1>::matmul() N_epoch (>2) no. of times and finds out the average execution time of MATOPS::BigMatrix<Data1>::matmul() for that particular LEAF_SIZE. Use the following command to run the configure_lib.cpp file.

$ g++ configure_lib.cpp -o configure_lib -DSET_LEAF_SIZE && ./configure_lib <N_epoch>

The program begins with LEAF_SIZE = 8, calls MATOPS::BigMatrix<Data1>::matmul() N_epoch times and calculates the average execution time of matmul over all the calls and stores it in a varaible min_time. It continues doing the same for LEAF_SIZE=16, 32,64 ..... as min_time keeps reducing. As soon as the value of min_time starts increasing we break out of the inifinite while loop and store the LEAF_SIZE value that gave the least min_time in a configure.txt file. This file is later used by matmul to multiply big matrices.

Author
Shiladitya Biswas
Version
0.1
Date
2021-01-29

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
38  {
39 
40  cout<<"------------ Program to find out optimal LEAF_SIZE ---------------\n";
41 
42  std::ofstream file;
43  file.open("configure.txt"); // Open configure.txt file
44 
45  int N_epoch=atoi(argv[1]);
46  BigMatrix<int> MatObj;
47 
48  cout<<"Configuring ......\n";
49 
50  double min_time= DBL_MAX;
51  int final_leaf_size=0;
52  int l_size=8;
53  // While loop to keep checking and tracking the best LEAF SIZE for the Library. Once we find the LEAF_SIZE that gives
54  // has the best/ lowest execution time we break out of the while loop and store the LEAF_SIZE value in a configure.txt file.
55  while(1)
56  {
57  cout<<"Testing Library with LEAF_SIZE: "<<l_size<<'\n';
58  MatObj.set_LEAF_SIZE(l_size); // set the LEAF_SIZE value in the matrix.h file.
59  double temp_time=0;
60  for(int n=0;n<N_epoch;n++) // Run the multiplication process for N_epoch of times for a fixed LEAF_SIZE value.
61  {
62  // Determine the Time taken to do the multiplication operation
63  auto start = std::chrono::steady_clock::now();
64  MatObj.matmul("Configure_Data/large_A.csv","Configure_Data/large_B.csv","Configure_Data/Ans.csv");
65  auto end = std::chrono::steady_clock::now();
66  std::chrono::duration<double> elapsed_seconds = end-start;
67  temp_time+=elapsed_seconds.count();
68 
69  }
70  temp_time/=N_epoch; // Find the average time taken over the N_epoch steps
71 
72  if(temp_time<min_time) // Find the LEAF_SIZE for which the least time is taken.
73  {
74  min_time=temp_time;
75  final_leaf_size=l_size;
76  }
77  else
78  {
79  break;
80  }
81  l_size=2*l_size; // Double the leaf_size after every iteration
82  }
83  // cout<<final_leaf_size;
84 
85  file<<final_leaf_size<<'\n'; // Store the Optimal LEAF_SIZE value in a txt file
86  cout<<"configure.txt File Generated \n";
87  file.close();
88  // cout<<"Best Leaf size = "<<final_leaf_size<<'\n';
89 
90  return 0;
91 }
This is the Class for handling Large Matrices. It takes in large Matrices stored as comma-separated v...
Definition: matrix.h:330
void set_LEAF_SIZE(int leaf_size)
This Function sets the LEAF_SIZE i.e. the array size at which we shift from Strassan&#39;s Algo to normal...
Definition: matrix.h:685
void matmul(std::string file_1, std::string file_2, std::string path, bool print=false)
This is the BigMatrix multiplication Function that multiplies two matrices A and B stored in A...
Definition: matrix.h:731