From 516768a97a11eeed195032423c69168dac278031 Mon Sep 17 00:00:00 2001 From: PioDer Date: Mon, 31 Oct 2016 17:40:31 +0100 Subject: [PATCH] =?UTF-8?q?dalsza=20zabawa=20z=20podzia=C5=82ami=20wektor?= =?UTF-8?q?=C3=B3w=20itd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DergunPiotr-WaskoDominik/zad2/macierz_mpi.cpp | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/DergunPiotr-WaskoDominik/zad2/macierz_mpi.cpp b/DergunPiotr-WaskoDominik/zad2/macierz_mpi.cpp index 417e4d4..f66c0b7 100644 --- a/DergunPiotr-WaskoDominik/zad2/macierz_mpi.cpp +++ b/DergunPiotr-WaskoDominik/zad2/macierz_mpi.cpp @@ -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