C=A*BのCプログラムNO.1

    2003/08/28 日立製作所 & 早稲田大学 後 保範 ( Ushiro Yasunori )
--------------------------------------------------------------

1. 概要

 実密行列を係数とする行列乗算C=A*Bを計算する。非連続アクセスをする悪い例である。
他との比較のために掲載しているので、本例のプログラムは作成しない事。
FORTRANのプログラム(連続アクセス版)をそのままCに移植するとこのようになる。
行列A,B,CのサイズはそれぞれNxL,LxM,NxMである。

2. プログラム

#include <stdio.h>
#include <math.h>
#define ND  1000
extern 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 JKI-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,   2003/08/28                     C
//        ( Hitachi Ltd. and Waseda University )                   C
//=================================================================C
{ int     i, j, k ;
  double  BW ;
//   Clear C
  for (j=0; j<M; j++) {
    for (i=0; i<N; i++) {
      C[i][j] = 0.0 ; }
   }
//   C=C+A*B
  for (j=0; j<M; j++) {
    for (k=0; k<L; k++) {
      BW = B[k][j] ;
      for (i=0; i<N; i++) {
        C[i][j] = C[i][j] + A[i][k]*BW ; }
   }  }
 }