Changes

Jump to: navigation, search

DPS915/M-N-M

249 bytes added, 18:56, 7 March 2013
Assignment 2
# include <ctime>
 
#include<iomanip>
 
#include<cstdlib>
# include <cuda_runtime.h>
 
//#include <times.h>
using namespace std;
  inline clock_t getMilliSecs() {  return clock() / (CLOCKS_PER_SEC / 1000);  }    __global__ void primegen(bool prime, int number2,int x,int *primes_d)
{
bool prime = true;
//struct tms start_time, stop_time;
int number2;
number2 =(int) floor (sqrt (x));
clock_t start = getMilliSecs();
//Array to hold generated primes on host
cudaError_t error ;
 
int start_s=clock();
//Kernal goes here
primegen<<<1,1>>>(prime,number2,(int)x,primes_d);
int stop_s = clock();
// extract error code from the kernel's execution
//display the primes
for(int i=0; i<(int)x ; i++){
if(primes_h[i]>=2 && primes_h[i]<=(int)x){
}
cout << "Elapsed time: " << (getMilliSecs() - start) << "ms" << endl;  // cout<< "time: "<< (stop_s-start_s)/double(CLOCKS_PER_SEC)<<endl;
//free allocated memory
 
delete [] primes_h;

Navigation menu