|
@ -2,6 +2,8 @@ |
|
|
#include <cstdlib>
|
|
|
#include <cstdlib>
|
|
|
#include <cmath>
|
|
|
#include <cmath>
|
|
|
#include "Ttiming.h"
|
|
|
#include "Ttiming.h"
|
|
|
|
|
|
#include <mpi.h>
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
using namespace std; |
|
|
using namespace std; |
|
|
|
|
|
|
|
@ -33,20 +35,22 @@ void array_destroy(long **arr) |
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) |
|
|
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; |
|
|
long rozmiar=0; |
|
|
char *endptr; |
|
|
char *endptr; |
|
|
int threads_num=0; |
|
|
|
|
|
TTiming tt; |
|
|
TTiming tt; |
|
|
long i, j;//,k;
|
|
|
long i, j;//,k;
|
|
|
|
|
|
MPI::Status status; |
|
|
|
|
|
|
|
|
if (argc < 3) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (argc < 2) |
|
|
{ |
|
|
{ |
|
|
cerr << "Usage: " << argv[0] << " <n> <size>" << endl; |
|
|
|
|
|
|
|
|
cerr << "Usage: " << argv[0] << " <size>" << endl; |
|
|
exit(1); |
|
|
exit(1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
rozmiar = strtol(argv[2], &endptr, 10); |
|
|
|
|
|
|
|
|
rozmiar = strtol(argv[1], &endptr, 10); |
|
|
|
|
|
|
|
|
if (*endptr) |
|
|
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; |
|
|
cerr << "The number of matrix dimension must be in range [1,2000]" << endl; |
|
|
exit(1); |
|
|
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
|
|
|
//alokacja macierzy
|
|
|
array_alloc(A, rozmiar); |
|
|
array_alloc(A, rozmiar); |
|
|
array_alloc(B, rozmiar); |
|
|
|
|
|
|
|
|
if (taskid == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
array_alloc(B, rozmiar); |
|
|
|
|
|
array_alloc(B_rot, rozmiar); |
|
|
|
|
|
} |
|
|
array_alloc(C, rozmiar); |
|
|
array_alloc(C, rozmiar); |
|
|
|
|
|
|
|
|
//wypelnienie macierzy A liczbami "losowymi"
|
|
|
|
|
|
for (long i=0; i<rozmiar; ++i) |
|
|
|
|
|
for (long j=0; j<rozmiar; ++j) |
|
|
|
|
|
A[i][j] = (long)(sin(i) * i * j) % 10; |
|
|
|
|
|
|
|
|
if (taskid == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
//wypelnienie macierzy A liczbami "losowymi"
|
|
|
|
|
|
for (long i=0; i<rozmiar; ++i) |
|
|
|
|
|
for (long j=0; j<rozmiar; ++j) |
|
|
|
|
|
A[i][j] = (long)(sin(i) * i * j) % 10; |
|
|
|
|
|
|
|
|
//wypelnienie macierzy B liczbami "losowymi"
|
|
|
|
|
|
for (long i=0; i<rozmiar; ++i) |
|
|
|
|
|
for (long j=0; j<rozmiar; ++j) |
|
|
|
|
|
B[i][j] = (long)(cos(j) *(i+j)) % 10; |
|
|
|
|
|
|
|
|
//wypelnienie macierzy B liczbami "losowymi"
|
|
|
|
|
|
for (long i=0; i<rozmiar; ++i) |
|
|
|
|
|
for (long j=0; j<rozmiar; ++j) |
|
|
|
|
|
B[i][j] = (long)(cos(j) *(i+j)) % 10; |
|
|
|
|
|
|
|
|
|
|
|
//dokonaj obracania macierzy
|
|
|
|
|
|
for (long i=0; i<rozmiar; ++i) |
|
|
|
|
|
for (long j=0; j<rozmiar; ++j) |
|
|
|
|
|
B_rot[i][j] = B[j][i]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//wysyłanie macierzy A do wszystkich
|
|
|
|
|
|
MPI::COMM_WORLD.Bcast(&A[0][0], rozmiar*rozmiar, MPI::LONG, 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
tt.Begin(); |
|
|
tt.Begin(); |
|
|
//#pragma omp parallel for default(shared)
|
|
|
|
|
|
//#pragma omp parallel for default(none) shared(A, B, C) firstprivate(rozmiar)private(i, j)
|
|
|
|
|
|
for (i=0; i<rozmiar; ++i) |
|
|
for (i=0; i<rozmiar; ++i) |
|
|
for (j=0; j<rozmiar; ++j) |
|
|
for (j=0; j<rozmiar; ++j) |
|
|
{ |
|
|
{ |
|
@ -107,9 +115,14 @@ int main(int argc, char *argv[]) |
|
|
|
|
|
|
|
|
cout << "Time: " << elapsed << " ms" << endl; |
|
|
cout << "Time: " << elapsed << " ms" << endl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
array_destroy(A); |
|
|
array_destroy(A); |
|
|
array_destroy(B); |
|
|
array_destroy(B); |
|
|
array_destroy(C); |
|
|
array_destroy(C); |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
cout << taskid << ": " << A[2][2] << endl; |
|
|
|
|
|
MPI::Finalize(); |
|
|
|
|
|
|
|
|
exit(0); |
|
|
exit(0); |
|
|
} |
|
|
} |