NAG Library Manual, Mark 27.2
Interfaces:  FL   CL   CPP   AD 

NAG AD Library Introduction
Example description
/* F06YA_P0W_F C++ Header Example Program.
 *
 * Copyright 2021 Numerical Algorithms Group.
 * Mark 27.2, 2021.
 */

#include <iostream>
#include <math.h>
#include <nag.h>
#include <nagad.h>
#include <nagx04.h>
#include <stdio.h>
#include <string>
using namespace std;

int main(void)
{
  int     exit_status = 0;
  void *  ad_handle   = 0;
  Integer ifail       = 0;

  cout << "F06YA_P0W_F C++ Header Example Program Results\n\n";
  // Skip heading in data file
  string mystr;
  getline(cin, mystr);

  // Read problem size and number of right-hand-sides
  Integer m, n, k;
  cin >> m >> n >> k;
  double alpha, beta;
  cin >> alpha >> beta;

  // Allocate arrays containing A and its factorized form, B
  // and the solution X.
  double *a = 0, *b = 0, *c = 0;
  a = new double[k * m];
  b = new double[n * k];
  c = new double[m * n];

  // Read the matrix A
  double dd;
  for (int i = 0; i < k; ++i)
    {
      for (int j = 0; j < m; ++j)
        {
          cin >> dd;
          Integer l = i + j * k;
          a[l]      = dd;
        }
    }
  for (int i = 0; i < n; ++i)
    {
      for (int j = 0; j < k; ++j)
        {
          cin >> dd;
          Integer l = i + j * n;
          b[l]      = dd;
        }
    }
  for (int i = 0; i < m * n; ++i)
    {
      c[i] = 1.0;
    }

  //  C = beta*C + alpha*A^T*B^T
  ifail = 0;
  nag::ad::f06ya(ad_handle, "T", "T", m, n, k, alpha, a, k, b, n, beta, c, m,
                 ifail);

  cout << endl;
  NagError fail;
  INIT_FAIL(fail);
  x04cac(Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, m, n, c, m,
         "  Matrix C after update", 0, &fail);

  delete[] a;
  delete[] b;
  delete[] c;

  return exit_status;
}