Lab 1 Parallel
Lab 1 Parallel
Parallel Lab 1
#include <stdio.h>
#include <cuda.h>
#include <stdlib.h>
#include <time.h>
int main() {
int M, N;
printf("Enter matrix dimensions M (rows) and N (columns): ");
scanf("%d %d", &M, &N);
cudaEventRecord(stop);
cudaEventSynchronize(stop);
float gpuTime = 0;
cudaEventElapsedTime(&gpuTime, start, stop);
return 0;
}Explanation of Code
Sample Output
sql
Copy code
Enter matrix dimensions M (rows) and N (columns): 1000 500
Matrix (1000x500) and Vector (size 500) successfully generated.
Validation: GPU and CPU results match!
GPU computation time: X.XX milliseconds
CPU computation time: Y.YY milliseconds
Discussion
The GPU is generally faster than the CPU due to parallel computation, particularly as matrix
dimensions increase. The grid and block configuration ensures that each GPU thread handles
one element of the output vector, maximizing parallelism and reducing computation time.
…