fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <omp.h>
  4.  
  5. #define N 1000
  6.  
  7. void initialize_random_matrix(int mat[N][N]) {
  8. for (int i = 0; i < N; i++) {
  9. for (int j = 0; j < N; j++) {
  10. mat[i][j] = rand() % 100; // Generate random values between 0 and 99
  11. }
  12. }
  13. }
  14.  
  15. void matrix_multiply(int A[N][N], int B[N][N], int C[N][N]) {
  16. #pragma omp parallel for
  17. for (int i = 0; i < N; i++) {
  18. for (int j = 0; j < N; j++) {
  19. int sum = 0;
  20. #pragma omp parallel for reduction(+:sum)
  21. for (int k = 0; k < N; k++) {
  22. sum += A[i][k] * B[k][j];
  23. }
  24. C[i][j] = sum;
  25. }
  26. }
  27. }
  28.  
  29. int main() {
  30. int A[N][N], B[N][N], C[N][N];
  31.  
  32. // Initialize matrices A and B with 21 and 32
  33. initialize_random_matrix(A);
  34. initialize_random_matrix(B);
  35.  
  36. // Perform matrix multiplication
  37. matrix_multiply(A, B, C);
  38.  
  39. // Print the result (optional)
  40. // ...
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout #stderr 0.27s 40872KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "void initialize_random_matrix"
Execution halted