Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.69 KB | None | 0 0
  1. import std.getopt;
  2. import std.stdio;
  3.  
  4. immutable int n = 1000;
  5.  
  6. void main(string[] args){
  7.   auto  A = new double[n*n];
  8.   double[]  B = new double[n*n];
  9.   double[]  C = new double[n*n];
  10.    
  11.   matrix!(typeof(A)).ini(A, n);
  12.   matrix!(typeof(A)).ini(B, n);
  13.   matrix!(typeof(A)).MatMul(A,B,C, n);
  14. }
  15.  
  16.  
  17. template matrix(T){
  18.   void ini(T mtx, int n){
  19.     for(int i = 0; i < n; i++) {
  20.       for(int j = 0; j< n; j++) {
  21.     mtx[i + n*j] = i*j + 0.6*j +3.4;
  22.       }
  23.     }
  24.   }
  25.  
  26.  
  27.   void MatMul(T A, T B, T C, int n){
  28.    
  29.  
  30.     for(int k = 0; k < n; k++) {
  31.       for(int i = 0; i < n; i++) {
  32.     for(int j = 0; j < n; j++) {
  33.       C[i + n*k] += A[i + n*j] * B[j + n*k];
  34.     }
  35.       }
  36.     }
  37.   }
  38.  
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement