diff --git a/DergunPiotr-WaskoDominik/zad2/macierz_mpi.cpp b/DergunPiotr-WaskoDominik/zad2/macierz_mpi.cpp index a4fec79..417e4d4 100644 --- a/DergunPiotr-WaskoDominik/zad2/macierz_mpi.cpp +++ b/DergunPiotr-WaskoDominik/zad2/macierz_mpi.cpp @@ -2,6 +2,8 @@ #include #include #include "Ttiming.h" +#include +#include using namespace std; @@ -33,20 +35,22 @@ void array_destroy(long **arr) int main(int argc, char *argv[]) { - long **A=NULL, **B=NULL, **C=NULL; + long **A=NULL, **B=NULL, **C=NULL, **B_rot=NULL; long rozmiar=0; char *endptr; - int threads_num=0; TTiming tt; long i, j;//,k; + MPI::Status status; - if (argc < 3) + + + if (argc < 2) { - cerr << "Usage: " << argv[0] << " " << endl; + cerr << "Usage: " << argv[0] << " " << endl; exit(1); } - rozmiar = strtol(argv[2], &endptr, 10); + rozmiar = strtol(argv[1], &endptr, 10); if (*endptr) { @@ -59,42 +63,46 @@ int main(int argc, char *argv[]) cerr << "The number of matrix dimension must be in range [1,2000]" << endl; exit(1); } - - threads_num = strtol(argv[1], &endptr, 10); - - if (*endptr) - { - cerr << "Invalid number of threads format" << endl; - exit(1); - } + + MPI::Init(argc, argv); + + int taskid = MPI::COMM_WORLD.Get_rank(); + int ntasks = MPI::COMM_WORLD.Get_size(); + printf("ntasks= %d : taskid= %d : Hello World!\n",ntasks,taskid); - if (threads_num <= 0) - { - cerr << "The number of threads must be positive" << endl; - exit(1); - } - - //ustawienie odpowiedniej ilosci watkow - //omp_set_num_threads(threads_num); - //alokacja macierzy array_alloc(A, rozmiar); - array_alloc(B, rozmiar); + if (taskid == 0) + { + array_alloc(B, rozmiar); + array_alloc(B_rot, rozmiar); + } array_alloc(C, rozmiar); - //wypelnienie macierzy A liczbami "losowymi" - for (long i=0; i