|
|
@ -27,6 +27,20 @@ void array_alloc(long **&arr, long arrsize) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void vect_alloc(long *&arr, long arrsize) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
arr = new long [arrsize]; |
|
|
|
|
|
|
|
} |
|
|
|
catch (bad_alloc& ex) |
|
|
|
{ |
|
|
|
cerr << "Could not allocate memory for vector" << endl; |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void array_destroy(long **arr) |
|
|
|
{ |
|
|
|
delete [] arr[0]; |
|
|
@ -35,7 +49,7 @@ void array_destroy(long **arr) |
|
|
|
|
|
|
|
int main(int argc, char *argv[]) |
|
|
|
{ |
|
|
|
long **A=NULL, **B=NULL, **C=NULL, **B_rot=NULL; |
|
|
|
long **A=NULL, **B=NULL, **C=NULL, *B_rot=NULL, *vect=NULL; |
|
|
|
long rozmiar=0; |
|
|
|
char *endptr; |
|
|
|
TTiming tt; |
|
|
@ -75,10 +89,10 @@ int main(int argc, char *argv[]) |
|
|
|
if (taskid == 0) |
|
|
|
{ |
|
|
|
array_alloc(B, rozmiar); |
|
|
|
array_alloc(B_rot, rozmiar); |
|
|
|
vect_alloc(B_rot, rozmiar*rozmiar); |
|
|
|
} |
|
|
|
array_alloc(C, rozmiar); |
|
|
|
|
|
|
|
vect_alloc(vect, rozmiar); |
|
|
|
if (taskid == 0) |
|
|
|
{ |
|
|
|
//wypelnienie macierzy A liczbami "losowymi"
|
|
|
@ -94,13 +108,15 @@ int main(int argc, char *argv[]) |
|
|
|
//dokonaj obracania macierzy
|
|
|
|
for (long i=0; i<rozmiar; ++i) |
|
|
|
for (long j=0; j<rozmiar; ++j) |
|
|
|
B_rot[i][j] = B[j][i]; |
|
|
|
B_rot[i*rozmiar+j] = B[j][i]; |
|
|
|
} |
|
|
|
|
|
|
|
//wysyłanie macierzy A do wszystkich
|
|
|
|
MPI::COMM_WORLD.Bcast(&A[0][0], rozmiar*rozmiar, MPI::LONG, 0); |
|
|
|
|
|
|
|
MPI::COMM_WORLD.Scatter(&B_rot[0], rozmiar, MPI::LONG, &vect[0], rozmiar, MPI::LONG, 0); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
tt.Begin(); |
|
|
|
for (i=0; i<rozmiar; ++i) |
|
|
@ -121,7 +137,7 @@ int main(int argc, char *argv[]) |
|
|
|
array_destroy(C); |
|
|
|
*/ |
|
|
|
|
|
|
|
cout << taskid << ": " << A[2][2] << endl; |
|
|
|
cout << taskid << ": " << vect[2] << endl; |
|
|
|
MPI::Finalize(); |
|
|
|
|
|
|
|
exit(0); |