//////////////////////////////////////////////////////////////////////////////////////////////////// // // CDAC Tech Workshop, hyPACK-2013 // Oct 15-18, 2013 // // File : xeon-phi-tbb-mat-mat-mul-native.cpp // // Author : K V SRINATH // // Input : Matrix size , no of threads // // Output : Time Elapsed for matrix multiplication using intel tbb library. // // Created : May,2013 // // Email : srinathkv@cdac.in hpcfte@cdac.in // //////////////////////////////////////////////////////////////////////////////////////////////////// #include #include #include #include "tbb/task_scheduler_init.h" #include "tbb/blocked_range2d.h" #include "tbb/parallel_for.h" #include "tbb/tick_count.h" //#define DATA_TYPE float #define DATA_TYPE double using namespace std; using namespace tbb; class matrixMult { private: DATA_TYPE **pa; DATA_TYPE **pb; DATA_TYPE **pr; int size; public: void operator()( const blocked_range2d& r ) const { DATA_TYPE **a= pa; DATA_TYPE **b= pb; DATA_TYPE **r1= pr; for( size_t i=r.rows().begin(); i!=r.rows().end(); ++i ) { for( size_t j=r.cols().begin(); j!=r.cols().end(); ++j ) { DATA_TYPE sum = (DATA_TYPE)0.0; for( size_t k=0; k void fill_matrix(T **matx,int size) { for(size_t i=0;i void print_matrix(T **matx,int size) { for(size_t i=0;i \n"; exit(1); } size=atoi(argv[1]); nThreads=atoi(argv[2]); //Dynamic memory allocation Matrix_A=(DATA_TYPE **)malloc(size*sizeof(DATA_TYPE *)); if(Matrix_A==NULL) { cout<<"malloc error\n"; exit(1); } for(size_t i=0;i(0,size,0,size),matrixMult(Matrix_A,Matrix_B,Matrix_R,size),ap); tick_count t1 = tick_count::now(); double timeOverhead=(t1-t0).seconds(); //printf("Parallel Time Elapsed %g seconds\n",(t1-t0).seconds()); //cout<<"MFLOPS="<<(((double)size*size*size*2/((t1-t0).seconds()))/1000000)<