// file: /data/courses/ece_1111/lectures/current/lecture_05/example.cc // // local include files // #include "example.h" // function: main // // This is a simple program that prints to the terminal. // int main(int argc, const char** argv) { // decode the command line arguments // long nrows = atoi(argv[1]); long ncols = atoi(argv[2]); long niter = atoi(argv[3]); long mode = atoi(argv[4]); // testing memory // /* float x[nrows][nrows][nrows][nrows][nrows][nrows]; memset(x, 6*9*sizeof(float), 0); x[0][0][0][0][1][0] = 27.0; x[0][0][0][nrows][2][0] = 27.0; float* y = &x[0][0][0][0][0][0]; for (long i = 0; i < 10; i++) { fprintf(stdout, "memory location: %u, value = %f\n", y, *y++); } */ // echo the command line arguments // fprintf(stdout, "program name: %s\n", argv[0]); fprintf(stdout, "number of rows = %d\n", nrows); fprintf(stdout, "number of cols = %d\n", ncols); fprintf(stdout, "initialization modes = %d\n", mode); fprintf(stdout, "niter = %d\n", niter); // declare local variables // float* a = new float[nrows * ncols]; float* b = new float[ncols * nrows]; float* c = new float[nrows * nrows]; // initialize a matrix // fprintf(stdout, "... initializing...\n"); if (minit(a, nrows, ncols, mode) == false) { fprintf(stdout, "%s: error initializing matrices\n", argv[0]); } if (minit(b, ncols, nrows, mode) == false) { fprintf(stdout, "%s: error initializing matrices\n", argv[0]); } // print the input matrices // fprintf(stdout, "... printing input matrices...\n"); if (mprint(a, nrows, ncols, (char*)"a:") == false) { fprintf(stdout, "%s: error printing matrices\n", argv[0]); } if (mprint(b, ncols, nrows, (char*)"b:") == false) { fprintf(stdout, "%s: error printing matrices\n", argv[0]); } // multiply both matrices // for (long i = 0; i < niter; i++) { if (i % NITER == 0) { fprintf(stdout, "iteration no. %d\n", i); } if (mmult(c, a, b, nrows, ncols) == false) { fprintf(stdout, "%s: error multiplying matrices\n", argv[0]); } } // print the input matrices // fprintf(stdout, "... printing output matrices...\n"); if (mprint(c, nrows, ncols, (char*)"c:") == false) { fprintf(stdout, "%s: error printing matrices\n", argv[0]); } // exit gracefully // return(0); }