Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F94001360
assignment4_cpu.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
Tue, Dec 3, 03:59
Size
1 KB
Mime Type
text/x-c
Expires
Thu, Dec 5, 03:59 (1 d, 4 h)
Engine
blob
Format
Raw Data
Handle
22700623
Attached To
R10834 Project_multiproc
assignment4_cpu.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