import std.stdio; import std.string; import std.uni; import std.algorithm; import std.random; import core.thread; void print_tab(int m, int n, real[][] tab) { for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { write(tab[i][j], " "); } write("\n"); } } real get_random() { auto rng = new Random(unpredictableSeed); return uniform(0, 10, rng); } real sum_array(real[] arr) { real sum = 0; for(int i = 0; i < arr.length; i++) { sum += arr[i] * arr[i]; } return sum; } void main(string[] args) { /* int m = args[1]; */ /* int n = args[2]; */ int m = 3; int n = 4; real[][] tab; tab.length = m; Thread[] threads; // generujemy losowe numery for(int i = 0; i < m; i++) { tab[i].length = n; for(int j = 0; j < n; j++) { tab[i][j] = get_random(); } } // wyswietlamy tablice dla testu print_tab(m, n, tab); // watki for(size_t i; i < m; i++) { Thread tr = new Thread({ real suma = sum_array(tab[i]); writeln(suma); /* real suma = 0; */ /* writeln(suma); */ }); threads ~= tr; } foreach(thread; threads) { thread.start(); } }