Kashub's Code Barn - "asdf"

podświetlone jako sql (dodał(a) asdf @ 2021-06-15 13:04:28)

Twoja wyszukiwarka
Podświetl ten kod w:
Ostatnio dodane:
Losowe wpisy:
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();
    }
}
 
 
| Sklepy internetowe | | Opony całoroczne | | Opony zimowe | | karma dla psa - sklep | | Skracacz linków | | Blogi za darmo | | Przenieś bloga z onetu | | Gnieżdżewo | | Pionowe opisy |