How the C language in Linux system calls functions in ScaLAPACK

Source: Internet
Author: User

In parallel computing, it is often necessary to call the functions in the SCALAPCK (parallelized lapack) function library to program, here is a brief introduction to the C language how to call the matrix vector multiplication in the SCALAPCK function.

Note: The functions in ScaLAPACK are written in Fortran, and the matrices are stored in columns.

ScaLAPACK links need to be Blas, so make sure Blas, Gfortran is installed on this machine.

The following is an example of matrix vector multiplication (for a simple calculation, the number of processes set in the program is 4):

#include <stdio.h>#include<string.h>#include<stdlib.h>#include"mpi.h"#defineAA (i,j) aa[(i) *m+ (j)]
intMainintargcChar**argv) { intI, J, K;/************ MPI ***************************/ intMyrank_mpi, Nprocs_mpi; Mpi_init (&AMP;ARGC, &argv); Mpi_comm_rank (Mpi_comm_world,&Myrank_mpi); Mpi_comm_size (Mpi_comm_world,&nprocs_mpi);/************ Blacs ***************************/ intIctxt, Nprow, Npcol, Myrow, MYCOL,NB; intinfo,itemp; intzero=0, one=1; Nprow=2; Npcol=2; NB=1; Cblacs_pinfo (&myrank_mpi, &Nprocs_mpi); Cblacs_get (-1,0, &ictxt); Cblacs_gridinit (&ictxt,"Row", Nprow, Npcol); Cblacs_gridinfo (Ictxt,&nprow, &npcol, &myrow, &MyCol); intM =4; intdesca[9],descx[9],descy[9]; intMA = Numroc_ (&m, &AMP;NB, &myrow, &zero, &Nprow); intNA = Numroc_ (&m, &AMP;NB, &mycol, &zero, &Npcol); intNX = Numroc_ (&m, &AMP;NB, &myrow, &zero, &Nprow); intmy = Numroc_ (&m, &AMP;NB, &myrow, &zero, &Nprow); Descinit_ (Desca,&m, &m, &AMP;NB, &AMP;NB, &zero, &zero, &ictxt, &ma, &info); Descinit_ (Descx,&m, &one, &AMP;NB, &one, &zero, &zero, &ictxt, &nx, &info); Descinit_ (Descy,&m, &one, &AMP;NB, &one, &zero, &zero, &ictxt, &my, &info); Double*x = (Double*)malloc(nx*sizeof(Double)); Double*y = (Double*)calloc(My,sizeof(Double)); Double*a = (Double*)malloc(ma*na*sizeof(Double)); intSat,sut; for(i=0; i<ma;i++) for(j=0; j<na;j++) A[j*ma+i]=1.0; for(i=0; i<nx;i++) X[i]=1.0; DoubleAlpha =1.0;DoubleBeta =0.0; Pdgemv_ ("N", &m, &m, &alpha, A, &one, &one, Desca, X, &one, &one,descx, &one, &beta, y, &ONE, &one, Descy, &One ); for(i=0; i<my;i++) printf ("rank=%d,%f \ n", Myrank_mpi,y[i]); Mpi_finalize (); return 0;}

Compile the build executable file:

Mpicc-o PDGEMV pdgemv.c-l/opt/scalapack/scalapck-2.0. 2/-lscalapack-lblas-lgfortran

Run:

4 ./pdgemv

How the C language in Linux system calls functions in ScaLAPACK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.