2 つのベクトルの daxpy 操作を実行して結果を出力すると思われるこのコードがありますが、実行すると 3 つの 4 が返されます (3 つの 6 が返されると思われます)。
私は、daxpy について重要な何かを見逃しているように感じますが、それが何であるかはわかりません。
コードは次のとおりです。
#include <iostream>
using namespace std;
extern "C"
{
double daxpy_(double *A, double *B, int *n, double *a);
//The daxpy fortran function shown above multiplies a first matrix 'A' by a constant 'a'
//and adds the result to a second matrix 'B.' Both matrices are of size 'n.'
}
void daxpy(double *A, double *B, int n, double a);
//The function above is declared in order to utilize c-notation to perform the fortran
//daxpy function which takes a first matrix 'A' and multiplies the matrix by a costant 'a'
//and then adds the result to a second matrix 'B.'
int main(int argc, char *argv[])
{
double A[3], B[3];
int n=3;
double a=1.0;
for (int i=0;i<3;i++)
{
A[i]=2;
B[i]=4;
}
daxpy(A, B, n, a);
for (int i=0;i<3;i++)
{
cout << B[i] << endl;
}
}
void daxpy(double *A, double *B, int n, double a)
{
for (int i=0;i<n;i++)
{
B[i]=daxpy_(A, B, &n, &a);
}
}