1
edit
Changes
Carlos
,→Team Carlos
= Team Carlos =
== Team Members ==
# [mailto:cjconejomolero@myseneca.ca?subject=gpu610 Carlos Conejo]
== Progress ==
=== Assignment 1 ===
For my assignment 1, I profiled a Summarized Area Table code.
Here is the code:
// sat.cpp
/*
---- Profiling Results for the summarizedAreaTable() function ------
Word Problem Seconds
250 1.50
500 25.87
750 173.99
1000 658.34
--------------------------------------------------------------------
*/
#include <iostream>
#include <cstdlib>
using namespace std;
/* Creates the Matrice */
void createMatrice(float** a, int size){
for(int i = 0; i < size; i++)
a[i] = new float[size];
}
/* Initializes the matrice to any random number between 1 and 9 */
void initializeMatrice(float** a, int size){
float f = 1.0 / RAND_MAX;
for(int i = 0; i < size; i++)
for(int j = 0; j < size; j++)
a[i][j] = rand() * f;
}
/* Creates the summarized area table */
void summarizedAreaTable(float** a, float** b, int size){
int k = 0;
float sum = 0.0;
for(int i = size-1; i >= 0; i--){
for(int j = 0; j < size; j++){
for(int k = i; k < size; k++){
for(int m = 0; m <= j; m++){
sum += a[k][m];
}
}
b[i][j] = sum;
sum = 0.0;
}
}
}
int main(int argc, char* argv[]){
if(argc == 2){ // only one argument (program name + one argument) allowed
int size = atoi(argv[1]);
float **a = new float*[size];
float **b = new float*[size];
createMatrice(a,size); // creates the matrice a
createMatrice(b,size); // creates the matrice b
initializeMatrice(a,size); // initializes the matrices
summarizedAreaTable(a,b,size); // Does the SAT on a and stores it on b
cout << "Finished" << endl;
return 0;
}
else if(argc < 2)
cout << "Please provide a size" << endl; // when no arguments are supplied
else
cout << "Only one size is allowed" << endl; // when more than one argument(the program name + one or more arguments) is supplied
}
/* To print the results
cout << "a is: " << endl;
for(int i = 0; i < size; i++){
for(int j = 0; j < size; j++)
cout << a[i][j] << " ";
cout << endl;
}
*/