//================================================================C // Speed Test Program of C=A*B for 2-Type C // MULT1: Serial access (IKJ Type) ; High speed type C // MULT2: Stride access (JKI Type) ; Low speed type C //----------------------------------------------------------------C // Written by Yasunori Ushiro , 2011/04/05 C // ( JAMSTEC ES Adviser & Waseda University ) C //================================================================C #include #include #include // Global Define #define ND 2048 double A[ND][ND], B[ND][ND], C[ND][ND]; //================================================================C void MULT1(int N, int M, int L) //================================================================C // Real-Dense Matrix Multiplication C // C = A*B with sirial access (IKJ-Type) C //----------------------------------------------------------------C // A,B,C Global define Matrix C // N I*4, In, Matrix Size of A(Column), C(Column) C // M I*4, In, Matrix Size of B(Row), C(Row) C // L I*4, In, Matrix Size of A(Row), B(Column) C //----------------------------------------------------------------C // Written by Yasunori Ushiro , 2011/04/05 C // ( JAMSTEC ES Adviser & Waseda University ) C //================================================================C { int i, j, k ; double AW ; // Clear C for (i=0; i ND) { N = ND ; } printf("Matrix Multiplication (C=A*B) size=%d\n",N) ; M = N ; L = N ; // Loop for two Type of C=A*B // Set A,B SETAB(N); // IKJ-Type(Serial access) Multiplication T1 = clock(); MULT1(N, M, L); T2 = clock(); CPU = (double)(T2 - T1)/CLOCKS_PER_SEC; FLOP = 0.0; if(CPU > 0.0) { FLOP = 2.0*N*N*N*1.0e-6/CPU; } printf("Serial access; CPU time(s)=%7.2f, MFLOPS=%7.1f \n",CPU,FLOP); // JKI-Type(Stride access) Multiplication T1 = clock(); MULT2(N, M, L); T2 = clock(); CPU = (double)(T2 - T1)/CLOCKS_PER_SEC; FLOP = 0.0; if(CPU > 0.0) { FLOP = 2.0*N*N*N*1.0e-6/CPU; } printf("Stride access; CPU time(s)=%7.2f, MFLOPS=%6.1f \n",CPU,FLOP); return 0; }