magma with MKL in same project will make int to __int64

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)

magma with MKL in same project will make int to __int64

Postby alarm » Wed Mar 08, 2017 10:08 am

Hi All:

I am trying to put MKL pardiso and magma matrix solver in the same project.
When I create a project only with magma it working fine.
After I put MKL pardiso and magma in to same project and trying to copy my csr matrix to "magma_d_matrix" struct
The program always crash in "magma_d_solver" function.
I do some trouble shutting, I see the different,
When project working with MKL pardiso and magma,
the struct attribute like magma_d_matrix.num_rows should be int but it has be changed to "__int64".
I think that is the cause why my program crash.

My question is, can I avoid this issue by doing some config ? or magma just cannot working with MKL in the same project?

fallowing is my source code
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "mkl_pardiso.h"
#include "mkl_types.h"

#include "magma_v2.h"
#include "magmasparse.h"
#include "testings.h"


int main(void)
{
   /* Matrix data. */
   MKL_INT n = 8;
   MKL_INT ia[9] = { 0, 4, 7, 9, 11, 14, 16, 17, 18 };
   MKL_INT ja[18] =
   { 0, 2, 5, 6,
   1, 2, 4,
   2, 7,
   3, 6,
   4, 5, 6,
   5, 7,
   6,
   7
   };
   double a[18] =
   { 7.0, 1.0, 2.0, 7.0,
   -4.0, 8.0, 2.0,
   1.0, 5.0,
   7.0, 9.0,
   5.0, 1.0, 5.0,
   -1.0, 5.0,
   11.0,
   5.0
   };
   MKL_INT mtype = -2;       /* Real symmetric matrix */
   /* RHS and solution vectors. */
   double b[8], x[8];
   MKL_INT nrhs = 1;     /* Number of right hand sides. */
   /* Internal solver memory pointer pt, */
   /* 32-bit: int pt[64]; 64-bit: long int pt[64] */
   /* or void *pt[64] should be OK on both architectures */
   void *pt[64];
   /* Pardiso control parameters. */
   MKL_INT iparm[64];
   MKL_INT maxfct, mnum, phase, error, msglvl;
   /* Auxiliary variables. */
   MKL_INT i;
   double ddum;          /* Double dummy */
   MKL_INT idum;         /* Integer dummy. */
   /* -------------------------------------*/
   /* .. Setup Pardiso control parameters. */
   /* -------------------------------------*/
   for (i = 0; i < 64; i++)
   {
      iparm[i] = 0;
   }
   iparm[0] = 1;         /* No solver default */
   iparm[1] = 2;         /* Fill-in reordering from METIS */
   iparm[3] = 0;         /* No iterative-direct algorithm */
   iparm[4] = 0;         /* No user fill-in reducing permutation */
   iparm[5] = 0;         /* Write solution into x */
   iparm[7] = 2;         /* Max numbers of iterative refinement steps */
   iparm[9] = 13;        /* Perturb the pivot elements with 1E-13 */
   iparm[10] = 1;        /* Use nonsymmetric permutation and scaling MPS */
   iparm[12] = 0;        /* Maximum weighted matching algorithm is switched-off (default for symmetric). Try iparm[12] = 1 in case of inappropriate accuracy */
   iparm[13] = 0;        /* Output: Number of perturbed pivots */
   iparm[17] = -1;       /* Output: Number of nonzeros in the factor LU */
   iparm[18] = -1;       /* Output: Mflops for LU factorization */
   iparm[19] = 0;        /* Output: Numbers of CG Iterations */
   iparm[34] = 1;        /* PARDISO use C-style indexing for ia and ja arrays */
   maxfct = 1;           /* Maximum number of numerical factorizations. */
   mnum = 1;         /* Which factorization to use. */
   msglvl = 1;           /* Print statistical information in file */
   error = 0;            /* Initialize error flag */
   /* ----------------------------------------------------------------*/
   /* .. Initialize the internal solver memory pointer. This is only  */
   /*   necessary for the FIRST call of the PARDISO solver.           */
   /* ----------------------------------------------------------------*/
   for (i = 0; i < 64; i++)
   {
      pt[i] = 0;
   }

   magma_int_t info = 0;
   TESTING_CHECK(magma_init());
   magma_print_environment();

   magma_dopts zopts;
   magma_queue_t queue;
   magma_queue_create(0, &queue);

   magma_d_matrix A = { Magma_CSR };


   //zopts.solver_par.solver = Magma_GMRES;
   //zopts.solver_par.solver = Magma_CG;
   //zopts.solver_par.solver = Magma_PIDRMERGE;
   zopts.solver_par.solver = Magma_BICGSTAB;
   zopts.solver_par.restart = 8;
   zopts.solver_par.maxiter = 1000;
   zopts.solver_par.rtol = 1e-10;
   zopts.solver_par.maxiter = 1000;
   zopts.precond_par.solver = Magma_ILU;
   //zopts.precond_par.solver = Magma_JACOBI;
   zopts.precond_par.levels = 0;
   zopts.precond_par.trisolver = Magma_CUSOLVE;

   int nn = 8;
   int iaa[9] = { 0, 4, 7, 9, 11, 14, 16, 17, 18 };//zero base
   int jaa[18] = { 0, 2, 5, 6, 1, 2, 4, 2, 7, 3, 6, 4, 5, 6, 5, 7, 6, 7 };//zero base
   //int ia[9] = { 1, 5, 8, 10, 12, 15, 17, 18, 19 };
   //int ja[18] = { 1, 3, 6, 7,    2, 3, 5,    3, 8,    4, 7,    5, 6, 7,    6, 8,    7,    8};
   double aa[18] = { 7.0, 1.0, 2.0, 7.0, -4.0, 8.0, 2.0, 1.0, 5.0, 7.0, 9.0, 5.0, 1.0, 5.0, -1.0, 5.0, 11.0, 5.0 };

   double h_b[8] = { 1, 1, 1, 1, 1, 1, 1, 1 }, h_x[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };


   TESTING_CHECK(magma_dsolverinfo_init(&zopts.solver_par, &zopts.precond_par, queue));
   magma_dcsrset(nn, nn, &iaa[0], &jaa[0], aa, &A, queue);

   /* --------------------------------------------------------------------*/
   /* .. Reordering and Symbolic Factorization. This step also allocates  */
   /*    all memory that is necessary for the factorization.              */
   /* --------------------------------------------------------------------*/
   phase = 11;
   PARDISO(pt, &maxfct, &mnum, &mtype, &phase,
      &n, a, ia, ja, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, &error);
   if (error != 0)
   {
      printf("\nERROR during symbolic factorization: %d", error);
      exit(1);
   }
   printf("\nReordering completed ... ");
   printf("\nNumber of nonzeros in factors = %d", iparm[17]);
   printf("\nNumber of factorization MFLOPS = %d", iparm[18]);
   /* ----------------------------*/
   /* .. Numerical factorization. */
   /* ----------------------------*/
   phase = 22;
   PARDISO(pt, &maxfct, &mnum, &mtype, &phase,
      &n, a, ia, ja, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, &error);
   if (error != 0)
   {
      printf("\nERROR during numerical factorization: %d", error);
      exit(2);
   }
   printf("\nFactorization completed ... ");
   /* -----------------------------------------------*/
   /* .. Back substitution and iterative refinement. */
   /* -----------------------------------------------*/
   phase = 33;
   iparm[7] = 2;         /* Max numbers of iterative refinement steps. */
   /* Set right hand side to one. */
   for (i = 0; i < n; i++)
   {
      b[i] = 1;
   }
   PARDISO(pt, &maxfct, &mnum, &mtype, &phase,
      &n, a, ia, ja, &idum, &nrhs, iparm, &msglvl, b, x, &error);
   if (error != 0)
   {
      printf("\nERROR during solution: %d", error);
      exit(3);
   }
   printf("\nSolve completed ... ");
   printf("\nThe solution of the system is: ");
   for (i = 0; i < n; i++)
   {
      printf("\n x [%d] = % f", i, x[i]);
   }
   printf("\n");
   /* --------------------------------------*/
   /* .. Termination and release of memory. */
   /* --------------------------------------*/
   phase = -1;           /* Release internal memory. */
   PARDISO(pt, &maxfct, &mnum, &mtype, &phase,
      &n, &ddum, ia, ja, &idum, &nrhs,
      iparm, &msglvl, &ddum, &ddum, &error);
   return 0;
}



I am link fallowing library
Code: Select all
mkl_scalapack_ilp64_dll.lib
mkl_cdft_core_dll.lib
mkl_intel_ilp64_dll.lib
mkl_intel_thread_dll.lib
mkl_core_dll.lib
mkl_blacs_ilp64_dll.lib
libiomp5md.lib
C:\work\magma\OpenBLAS-v0.2.19-Win64-int32\lib\libopenblas.dll.a
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\cudart.lib
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\cublas.lib
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\cublas_device.lib
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\cusparse.lib
C:\work\magma\build\lib\Debug\magma.lib
C:\work\magma\build\lib\Debug\magma_sparse.lib
C:\work\magma\build\lib\Debug\lapacktest.lib
C:\work\magma\build\lib\Debug\tester.lib
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\cudart_static.lib




Have a good day.
AlarmChang.
Attachments
magma__int64.jpg
magma__int64.jpg (314.26 KiB) Viewed 445 times
alarm
 
Posts: 4
Joined: Wed Mar 01, 2017 9:12 pm

Re: magma with MKL in same project will make int to __int64

Postby mgates3 » Wed Mar 08, 2017 10:34 am

How did you compile MAGMA? Using an example make.inc file, or using CMake? What settings did you use?

It looks like you are using the ilp64 interface (i.e., int64, long64, pointer64), which is why magma_int_t is int64. This should work if everything is set correctly when MAGMA and your sources are compiled.

Alternatively, you could use the lp64 (int32, long64, pointer64) interface, e.g., compiling MAGMA with make.inc.mkl-icc and linking with mkl_*_lp64 libraries.

-mark
mgates3
 
Posts: 738
Joined: Fri Jan 06, 2012 2:13 pm

Re: magma with MKL in same project will make int to __int64

Postby alarm » Mon Mar 13, 2017 8:11 am

Hi thanks your reply.

I figure it out.
The project that using pardiso is specificy using 64bit int,
and MKL link 64bit libary and compiler options with /DMKL_ILP64 -I"%MKLROOT%"\include

I change them to:
link library : mkl_scalapack_lp64_dll.lib mkl_cdft_core_dll.lib mkl_intel_lp64_dll.lib mkl_intel_thread_dll.lib mkl_core_dll.lib mkl_blacs_lp64_dll.lib impi.lib libiomp5md.lib

compile option: -I"%MKLROOT%"\include

that fix my issue, thanks your help.


Have a good day.
AlarmChang.
alarm
 
Posts: 4
Joined: Wed Mar 01, 2017 9:12 pm


Return to User discussion

Who is online

Users browsing this forum: Google [Bot] and 2 guests