Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F104803915
assignment4.cu
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Mar 12, 13:06
Size
1 KB
Mime Type
text/x-c
Expires
Fri, Mar 14, 13:06 (1 d, 18 h)
Engine
blob
Format
Raw Data
Handle
24862292
Attached To
R10834 Project_multiproc
assignment4.cu
View Options
/*
============================================================================
Filename : assignment4.c
Author : Arash Pourhabibi
============================================================================
*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sys/time.h>
#include <cuda_runtime.h>
using namespace std;
#include "utility.h"
void array_process(double *input, double *output, int length, int iterations);
void GPU_array_process(double *input, double *output, int length, int iterations);
int main (int argc, const char *argv[]) {
int length, iterations;
double time;
if (argc != 3) {
cout<<"Invalid input!"<<endl<<"Usage: ./assignment4 <length> <iterations>"<<endl;
return 1;
} else {
length = atoi(argv[1]);
iterations = atoi(argv[2]);
if(length%2!=0)
{
cout<<"Invalid input!"<<endl<<"Array length must be even"<<endl;
return 1;
}
}
//Allocate arrays
double *input = new double[length*length];
double *output = new double[length*length];
//Reset Device
cudaDeviceReset();
//Initialize the arrays
init(input, length);
init(output, length);
//Start timer
set_clock();
/*Use either the CPU or the GPU functions*/
//CPU Baseline
//Uncomment the block to use the baseline
/*array_process(input, output, length, iterations);
if(iterations%2==0)
{
double *temp;
temp = input;
input = output;
output = temp;
}*/
//GPU function
GPU_array_process(input, output, length, iterations);
//Stop timer
time = elapsed_time();
//Report time required for n iterations
cout<<"Running the algorithm on "<<length<<" by "<<length<<" array for "<<iterations<<" iteration takes "<<setprecision(4)<<time<<"s"<<endl;
//Save array in filelength
save(output, length);
//Free allocated memory
delete[] input;
delete[] output;
return 0;
}
Event Timeline
Log In to Comment