fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <mpi.h>
  4. int main(int argc, char ** argv){
  5. int rank, size;
  6. int *result;
  7. int el_a, el_b, el_result;
  8. MPI_Init(&argc, &argv);
  9. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  10. MPI_Comm_size(MPI_COMM_WORLD, &size);
  11. result=calloc(size, sizeof(int));
  12. int *vector_a, *vector_b;
  13. vector_a = calloc(size, sizeof(int));
  14. vector_b = calloc(size, sizeof(int));
  15. if(rank==0){
  16. printf("Podaj parametry pierwszego wektora: \n");
  17. for(int i=0; i<size; i++){
  18. scanf("%d", &vector_a[i]);
  19. }
  20. printf("Podaj parametry drugiego wektora: \n");
  21. for(int i=0; i<size; i++){
  22. scanf("%d", &vector_b[i]);
  23. }
  24. }
  25. MPI_Barrier(MPI_COMM_WORLD);
  26. MPI_Scatter(vector_a, 1, MPI_INT, &el_a, 1, MPI_INT, 0, MPI_COMM_WORLD);
  27. MPI_Scatter(vector_b, 1, MPI_INT, &el_b, 1, MPI_INT, 0, MPI_COMM_WORLD);
  28. el_result=el_a*el_b;
  29. MPI_Gather(&el_result, 1, MPI_INT, result, 1, MPI_INT, 0, MPI_COMM_WORLD);
  30. if(rank==0){
  31. printf("Wektor wynkowy to:\n[");
  32. for(int i=0; i<size; i++){
  33. printf(" %d", result[i]);
  34. if(i!=size-1){
  35. printf(", ");
  36. }
  37. }
  38. printf(" ]\n");
  39. }
  40. MPI_Finalize();
  41. return 0;
  42. }
Success #stdin #stdout #stderr 0.25s 39112KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted