Open main menu

CDOT Wiki β

Changes

GPU610/TeamKCM

437 bytes added, 20:45, 1 December 2014
Assignment 3
===== Assignment 2 Source Code =====
<syntaxhighlight lang="cpp">
void solve(){
while int j=0; int d; cudaDeviceProp prop; cudaGetDevice(&d); cudaGetDeviceProperties(j<tTotal/dt&prop, d){; solutionNew unsigned ntpb = prop.maxThreadsDim[0]; unsigned ntpg =10ntpb * prop.maxGridSize[0]; solutionNew[ if (xGridNum > ntpg) { xGridNum]=120ntpg; std::cout << "n reduced to " << xGridNum << std::endl; }
cudaMemcpy( double* d_x, x, (xGridNum + 1) * sizeof(float), cudaMemcpyHostToDevice); cudaMemcpy( double* d_solutionLast, solutionLast, xGridNum * sizeof(double), cudaMemcpyHostToDevice); cudaMemcpy( double* d_solutionNew, solutionNew, xGridNum * sizeof(double), cudaMemcpyHostToDevice);
cudaMalloc((void**)&d_x, (xGridNum + 1) * sizeof(float)); cudaMalloc((void**)&d_solutionLast, xGridNum * sizeof(double)); cudaMalloc((void**)&d_solutionNew, xGridNum * sizeof(double));
kernel< while(j<<(xGridNum + ntpb - 1) tTotal/ ntpb, ntpb>>>(d_solutionNew, d_solutionLast, d_x, xGridNum, dt, dx, K, j){ solutionNew[0]=10; j++ solutionNew[xGridNum]=120;
cudaMemcpy(d_x, x, d_x, (xGridNum + 1) * sizeof(float), cudaMemcpyDeviceToHostcudaMemcpyHostToDevice); cudaMemcpy(d_solutionLast, solutionLast, d_solutionLast, xGridNum * sizeof(double), cudaMemcpyDeviceToHostcudaMemcpyHostToDevice); cudaMemcpy(d_solutionNew, solutionNew, d_solutionNew, xGridNum * sizeof(double), cudaMemcpyDeviceToHostcudaMemcpyHostToDevice);
solutionLast=solutionNew; }
kernel<<<(xGridNum + ntpb - 1) / ntpb, ntpb>>>(d_solutionNew, d_solutionLast, d_x, xGridNum, dt, dx, K, j); j++;  cudaMemcpy(x, d_x, (xGridNum + 1) * sizeof(float), cudaMemcpyDeviceToHost); cudaMemcpy(solutionLast, d_solutionLast, xGridNum * sizeof(double), cudaMemcpyDeviceToHost); cudaMemcpy(solutionNew, d_solutionNew, xGridNum * sizeof(double), cudaMemcpyDeviceToHost);  solutionLast=solutionNew; }  for(j = 0; j <= xGridNum; j++){ std::cout << solutionLast[j] << endl; }  cudaFree(d_x); cudaFree(d_solutionLast); cudaFree(d_solutionNew);}
</syntaxhighlight>