|
|
@ -37,15 +37,9 @@ void vect_alloc(long *&arr, long arrsize) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void array_destroy(long **arr) |
|
|
|
{ |
|
|
|
delete [] arr[0]; |
|
|
|
delete [] arr; |
|
|
|
} |
|
|
|
|
|
|
|
int main(int argc, char *argv[]) |
|
|
|
{ |
|
|
|
long **A=NULL, **B=NULL, **C=NULL, *B_rot=NULL, *vect=NULL, *vect_c=NULL, *C_rot=NULL; |
|
|
|
long **A=NULL, **B=NULL, *B_rot=NULL, *vect=NULL, *vect_c=NULL, *C_rot=NULL; |
|
|
|
long rozmiar=0, porcja_new=0, buff_max=0; |
|
|
|
char *endptr; |
|
|
|
TTiming tt; |
|
|
@ -102,7 +96,6 @@ int main(int argc, char *argv[]) |
|
|
|
if (taskid == 0) |
|
|
|
vect_alloc(C_rot, ntasks*buff_max); |
|
|
|
|
|
|
|
array_alloc(C, rozmiar); |
|
|
|
vect_alloc(vect, porcja); |
|
|
|
vect_alloc(vect_c, buff_max); |
|
|
|
if (taskid == 0) |
|
|
@ -110,14 +103,14 @@ int main(int argc, char *argv[]) |
|
|
|
// wypełnienie macierzy A liczbami "losowymi"
|
|
|
|
for (long i=0; i<rozmiar; ++i) |
|
|
|
for (long j=0; j<rozmiar; ++j) |
|
|
|
A[i][j] = 3*i+j+1; //test
|
|
|
|
//A[i][j] = (long)(sin(i) * i * j) % 10;
|
|
|
|
//A[i][j] = 3*i+j+1; //test
|
|
|
|
A[i][j] = (long)(sin(i) * i * j) % 10; |
|
|
|
|
|
|
|
// wypełnienie macierzy B liczbami "losowymi"
|
|
|
|
for (long i=0; i<rozmiar; ++i) |
|
|
|
for (long j=0; j<rozmiar; ++j) |
|
|
|
B[i][j] = j; //test
|
|
|
|
//B[i][j] = (long)(cos(j) *(i+j)) % 10;
|
|
|
|
//B[i][j] = j; //test
|
|
|
|
B[i][j] = (long)(cos(j) *(i+j)) % 10; |
|
|
|
|
|
|
|
// dokonaj obracania macierzy
|
|
|
|
for (long i=0; i<rozmiar; ++i) |
|
|
@ -127,17 +120,11 @@ int main(int argc, char *argv[]) |
|
|
|
|
|
|
|
//wysyłanie macierzy A do wszystkich
|
|
|
|
MPI::COMM_WORLD.Bcast(&A[0][0], rozmiar*rozmiar, MPI::LONG, 0); |
|
|
|
if (taskid == 0 && false) |
|
|
|
{ |
|
|
|
cout << endl << "WEKTOR DANYCH: " << endl; |
|
|
|
for (i=0; i<rozmiar*rozmiar; ++i) |
|
|
|
cout << B_rot[i] << " "; |
|
|
|
cout << endl; |
|
|
|
} |
|
|
|
|
|
|
|
MPI::COMM_WORLD.Barrier(); |
|
|
|
|
|
|
|
//dla wszystkich lub "rozmiar" procesów należy zadać porcję do obliczenia
|
|
|
|
MPI::COMM_WORLD.Scatter(&B_rot[0], porcja, MPI::LONG, &vect[0], porcja, MPI::LONG,0);// (rozmiar>=ntasks) ? 0 : ntasks-rozmiar);
|
|
|
|
MPI::COMM_WORLD.Scatter(&B_rot[0], porcja, MPI::LONG, &vect[0], porcja, MPI::LONG, 0); |
|
|
|
|
|
|
|
//
|
|
|
|
// część licząca ---------------------------------------------------------------------------------
|
|
|
@ -178,23 +165,6 @@ int main(int argc, char *argv[]) |
|
|
|
|
|
|
|
// zwróć wszystko do programu głównego
|
|
|
|
MPI::COMM_WORLD.Gather(&vect_c[0], buff_max, MPI::LONG, &C_rot[0], buff_max, MPI::LONG, 0); |
|
|
|
|
|
|
|
if (taskid == 0 && false) |
|
|
|
{ |
|
|
|
for (i=0; i<rozmiar*rozmiar; ++i) |
|
|
|
{ |
|
|
|
cout << C_rot[i] << " "; |
|
|
|
} |
|
|
|
|
|
|
|
cout << endl; |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
array_destroy(A); |
|
|
|
array_destroy(B); |
|
|
|
array_destroy(C); |
|
|
|
*/ |
|
|
|
|
|
|
|
MPI::Finalize(); |
|
|
|
|
|
|
|