text: #include<mkl/mkl.h>
  #include<assert.h>
  #include<stdlib.h>
  #include<string.h>
  
  /* Code for matrix function evaluation. */
  void dexp_mono_m7(double *A, const size_t n, double *output) {
      size_t max_memalloc = 3;
      size_t max_memslots = 4;
  
      /* Declarations and initializations. */
      double coeff1, coeff2;
      const double ZERO = 0.0;
      const double ONE = 1.0;
      size_t j;
  
      /* Memory management. */
      double *master_mem = malloc(n*n*max_memalloc*sizeof(*master_mem));
      double *memslots[max_memslots]; /* As many slots as nodes */
      memslots[0] = A; /* Overwrite A */
      /* The other slots are pointers to allocated memory. */
      for (j=0; j<max_memalloc; j++)
          memslots[j+1] = master_mem+j*n*n;
      /* Computation order: T2k2 B2 T2k3 B3 T2k4 B4 T2k5 B5 T2k6 B6 T2k7 B7 B8 T2k8 T2k10 */
  
      /* Computing T2k2 with operation: lincomb */
      coeff1 = 1.0;
      coeff2 = 1.0;
      memcpy(memslots[1], memslots[0], n*n*sizeof(*master_mem));
      cblas_dscal(n*n, coeff2, memslots[1], 1);
      cblas_daxpby(n, coeff1, &ONE, 0,
               ONE, memslots[1], n+1);
  
      /* Computing B2 with operation: mult */
      cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
              ONE, memslots[0], n, memslots[0], n,
              ZERO, memslots[2], n);
  
      /* Computing T2k3 with operation: lincomb */
      coeff1 = 1.0;
      coeff2 = 0.5;
      /* Smart lincomb recycle T2k2 */
      cblas_daxpby(n*n, coeff2, memslots[2], 1,
               coeff1, memslots[1], 1);
  
      /* Computing B3 with operation: mult */
      cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
              ONE, memslots[2], n, memslots[0], n,
              ZERO, memslots[3], n);
      /* Deallocating B2 in slot 3 */
  
      /* Computing T2k4 with operation: lincomb */
      coeff1 = 1.0;
      coeff2 = 0.16666666666666666;
      /* Smart lincomb recycle T2k3 */
      cblas_daxpby(n*n, coeff2, memslots[3], 1,
               coeff1, memslots[1], 1);
  
      /* Computing B4 with operation: mult */
      cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
              ONE, memslots[3], n, memslots[0], n,
              ZERO, memslots[2], n);
      /* Deallocating B3 in slot 4 */
  
      /* Computing T2k5 with operation: lincomb */
      coeff1 = 1.0;
      coeff2 = 0.041666666666666664;
      /* Smart lincomb recycle T2k4 */
      cblas_daxpby(n*n, coeff2, memslots[2], 1,
               coeff1, memslots[1], 1);
  
      /* Computing B5 with operation: mult */
      cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
              ONE, memslots[2], n, memslots[0], n,
              ZERO, memslots[3], n);
      /* Deallocating B4 in slot 3 */
  
      /* Computing T2k6 with operation: lincomb */
      coeff1 = 1.0;
      coeff2 = 0.008333333333333333;
      /* Smart lincomb recycle T2k5 */
      cblas_daxpby(n*n, coeff2, memslots[3], 1,
               coeff1, memslots[1], 1);
  
      /* Computing B6 with operation: mult */
      cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
              ONE, memslots[3], n, memslots[0], n,
              ZERO, memslots[2], n);
      /* Deallocating B5 in slot 4 */
  
      /* Computing T2k7 with operation: lincomb */
      coeff1 = 1.0;
      coeff2 = 0.001388888888888889;
      /* Smart lincomb recycle T2k6 */
      cblas_daxpby(n*n, coeff2, memslots[2], 1,
               coeff1, memslots[1], 1);
  
      /* Computing B7 with operation: mult */
      cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
              ONE, memslots[2], n, memslots[0], n,
              ZERO, memslots[3], n);
      /* Deallocating B6 in slot 3 */
  
      /* Computing B8 with operation: mult */
      cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n,
              ONE, memslots[3], n, memslots[0], n,
              ZERO, memslots[2], n);
      /* Deallocating A in slot 1 */
  
      /* Computing T2k8 with operation: lincomb */
      coeff1 = 1.0;
      coeff2 = 0.0001984126984126984;
      /* Smart lincomb recycle T2k7 */
      cblas_daxpby(n*n, coeff2, memslots[3], 1,
               coeff1, memslots[1], 1);
      /* Deallocating B7 in slot 4 */
  
      /* Computing T2k10 with operation: lincomb */
      coeff1 = 1.0;
      coeff2 = 2.48015873015873e-5;
      /* Smart lincomb recycle T2k8 */
      cblas_daxpby(n*n, coeff2, memslots[2], 1,
               coeff1, memslots[1], 1);
      /* Deallocating B8 in slot 3 */
  
      /* Prepare output. */
      memcpy(output, memslots[1], n*n*sizeof(*output));
      free(master_mem);
  }
  
  