|
|
@ -1,18 +1,22 @@ |
|
|
|
#include <iostream>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <cmath>
|
|
|
|
#include <omp.h>
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
void array_alloc(double **arr, long arrsize) |
|
|
|
void array_alloc(long **&arr, long arrsize) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
arr = new double* [arrsize]; |
|
|
|
arr[0] = new double [arrsize*arrsize]; |
|
|
|
arr = new long* [arrsize]; |
|
|
|
|
|
|
|
|
|
|
|
arr[0] = new long [arrsize*arrsize]; |
|
|
|
|
|
|
|
for(long i = 1; i < arrsize; i++) |
|
|
|
for(long i = 1; i < arrsize; ++i) |
|
|
|
arr[i] = arr[i-1] + arrsize; |
|
|
|
|
|
|
|
} |
|
|
|
catch (bad_alloc& ex) |
|
|
|
{ |
|
|
@ -21,7 +25,7 @@ void array_alloc(double **arr, long arrsize) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void array_destroy(double **arr) |
|
|
|
void array_destroy(long **arr) |
|
|
|
{ |
|
|
|
delete [] arr[0]; |
|
|
|
delete [] arr; |
|
|
@ -29,9 +33,10 @@ void array_destroy(double **arr) |
|
|
|
|
|
|
|
int main(int argc, char *argv[]) |
|
|
|
{ |
|
|
|
double **A=NULL;//, **B=NULL, **C=NULL;
|
|
|
|
long **A=NULL, **B=NULL, **C=NULL; |
|
|
|
long rozmiar=0; |
|
|
|
char *endptr; |
|
|
|
int threads_num=0; |
|
|
|
|
|
|
|
if (argc < 3) |
|
|
|
{ |
|
|
@ -52,10 +57,44 @@ int main(int argc, char *argv[]) |
|
|
|
cerr << "The number of matrix dimension must be positive" << endl; |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
|
|
|
|
threads_num = strtol(argv[1], &endptr, 10); |
|
|
|
|
|
|
|
if (*endptr) |
|
|
|
{ |
|
|
|
cerr << "Invalid number of threads format" << endl; |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
|
|
|
|
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); |
|
|
|
getchar(); |
|
|
|
array_alloc(B, rozmiar); |
|
|
|
array_alloc(C, rozmiar); |
|
|
|
|
|
|
|
//jeszcze czyszczenie pamięci
|
|
|
|
//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; // postarac sie to zoptymalizowac!
|
|
|
|
|
|
|
|
//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; // postarac sie to zoptymalizowac!
|
|
|
|
|
|
|
|
//mnozenie macierzy - TO DO
|
|
|
|
|
|
|
|
|
|
|
|
array_destroy(A); |
|
|
|
array_destroy(B); |
|
|
|
array_destroy(C); |
|
|
|
exit(0); |
|
|
|
} |