Hello,
i want to use some scalapacks' functions. but i confuse to set initial data form in scalapack, so i asked it here.
i have understood the data layout like figure below, and made code, too.
test code what i coded (pdgeqrf) like below :
#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <time.h> #include <mpi.h> #include <mkl_blacs.h> #include <mkl_scalapack.h> #include <mkl_lapacke.h> #include <mkl_cblas.h> #include <errno.h> int main(int argc, char **argv) { int i,j; // test parameters (default) int m = 4000; int n = 4000; int mb = 8; int nb = 8; int nprows = 8; int npcols = 8; // temp values // parameter value change (optional) if(argc >=5){ m=atoi(argv[1]); n=atoi(argv[2]); nprows=atoi(argv[3]); npcols=atoi(argv[4]); } // time and validity double startTime; double endTime; double gap; double flops; //QR double * A; double * tau; double * work; int mpirank, mpisize; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &mpirank); MPI_Comm_size(MPI_COMM_WORLD, &mpisize); int myid, numproc, ctxt, myrow, mycol; MKL_INT descA[9]; MKL_INT zero = 0; MKL_INT one = 1; MKL_INT info = 0; Cblacs_pinfo(&myid, &numproc); if(numproc > 1 && myid != 0){ Cblacs_setup(&myid, &numproc); } Cblacs_get(-1, 0, &ctxt); Cblacs_gridinit(&ctxt, "R", nprows, npcols); blacs_gridinfo_(&ctxt, &nprows, &npcols, &myrow, &mycol); if(myrow == -1){ return 0; } /* * temp value for fortran */ char aform = 'N'; char diag = 'N'; MKL_INT lda = m; MKL_INT iarow = 0; MKL_INT iacol = 0; MKL_INT iseed = 10; MKL_INT iroff = 0; MKL_INT irnum = numroc_(&m, &mb, &myrow, &zero, &nprows); MKL_INT icoff = 0; MKL_INT icnum = numroc_(&n, &nb, &mycol, &zero, &npcols); MKL_INT lwork = -1; //descinit(desc, m, n, mb, nb, irsrc, icsrc, ictxt, LLD, info) descinit_(descA, &m, &n, &mb, &nb, &zero, &zero, &ctxt, &icnum, &info); A = (double*)malloc(sizeof(double)*irnum*icnum); tau = (double*)malloc(sizeof(double)*(m*n/2)); //array size should >= LOCc(ja+min(m,n)-1) work = (double*)malloc(sizeof(double)*m*n); //pdmatgen_(&ctxt, &aform, &diag, &m, &n, &mb, &nb, A, &m, &iarow, &iacol, &iseed, &iroff, &irnum, &icoff, &icnum, &myrow, &mycol, &nprows, &npcols); /* * generate matrix (by column major) * * matrix : A * size : irnum * icnum * seed : 10 */ for(j = 0; j < irnum; ++j) { for(i = 0; i < icnum; ++i) { A[i*irnum+j] = rand()%10; } } printf("QR valid test (MPI)\n"); // pdgeqrf routine MPI_Barrier(MPI_COMM_WORLD); startTime = MPI_Wtime(); pdgeqrf_(&m,&n,A,&one,&one,descA,tau,work,&lwork,&info); //info = dgeqrf(LAPACK_COL_MAJOR, m, n, A, m, tau, descA, mpirank); MPI_Barrier(MPI_COMM_WORLD); endTime = MPI_Wtime(); // flops gap = (double)( endTime - startTime ); flops = (2.0 * (double)n * (double)n * (double)(m-n/3) ) * 1.0e-9 / gap; printf("info\t%d, dgemm time (sec)\t%f, Gflops\t%f \n", info, gap, flops); Cblacs_gridexit(ctxt); Cblacs_exit(&zero); MPI_Finalize(); free(A); free(tau); free(work); return 0; }
i have compiled my code like this :
mpiicc scalapack_test2.c -lmkl_scalapack_lp64 -lmkl_blacs_intelmpi_lp64 -mkl
i've comfirmed the result value 0 correctly, but there is some weird things especially speed things.
in addition, i couldn't check this result is right or not. i'm not sure of initializing data set value exactly.
this is result texts what i confirmed.
// form : ./a.out m n nprow npcol [@localhost src]$ mpirun -n 4 ./a.out 6400 6400 2 2 QR valid test (MPI) QR valid test (MPI) QR valid test (MPI) QR valid test (MPI) info 0, dgemm time (sec) 0.001011, Gflops 345703.851960 info 0, dgemm time (sec) 0.001003, Gflops 348580.607742 info 0, dgemm time (sec) 0.001141, Gflops 306337.241154 info 0, dgemm time (sec) 0.001143, Gflops 305826.040084 [@localhost src]$ mpirun -n 1 ./a.out 6400 6400 1 1 QR valid test (MPI) info 0, dgemm time (sec) 0.000237, Gflops 1474979.915656
could you give me some advise what i miss understand or miss used? if you give me good example of this, i'm really thank for you.
Thread Topic:
Help Me