Changes

Jump to: navigation, search

DPS915/M-N-M

262 bytes added, 12:18, 7 March 2013
Assignment 2
# include <cmath> // This library enable the use of sqrt.
# include <iostream>
# include <cuda_runtime.h>
using namespace std;
// This function will determine the primenumbers up to num.
void primenum(long double x){
//Array to hold generated primes on host int *primes_h = new int[x]; //Device array to hold the primes on the device int *primes_d = new int[x]; //allocate device mem cudaMalloc((void**)&primes_d, x * sizeof(int)); cudaMemset(&primes_d,sizeof(int),x * sizeof(int); //Kernal goes here //error checking //copy the array holding primes from device to host cudaMemcpy(primes_h, primes_d, x * sizeof(int), cudaMemcpyDeviceToHost); //display the primes for(int i=0; i<x ; i++){ cout<<primes_h[i]<<endl; } //free allocated memory delete [] primes_h; cudaFree(primes_d); getchar();
}
 
</pre>
=== Assignment 3 ===
1
edit

Navigation menu