MUMPS_dke_yp

PURPOSE ^

SYNOPSIS ^

function [X,flag,text] = MUMPS_dke_yp(MUMPSparam,A,B,display_mode,dkepath)

DESCRIPTION ^

Link with the parallel matrix solver package MUMPS written in FORTRAN. This is a modified package wich is able to 
read binary files written by MatLab, which needs to be compiled first. 
Tested on LINUX clusters (parallel or sequential)

Solve the linear system of equation AX=B

 INPUTS:

   - MUMPSparam: Structure for controling MUMPS program. 
    - A: Matrix [n,n]
   - B: Vector for solving the linear system of equations AX=B [n,1]  
   - display_mode: display some results [1,1]
   - dkepath: paths structure

 OUTPUTS:

   - X: Solution of the linear system of equation [n,1]
   - flag: execution flag (see the MUMPS documentation) [1,1]
   - text: execution documentation (see the HYPRE documentation)

by Yves Peysson (CEA-DRFC, yves.peysson@cea.fr) and Joan Decker (CEA-DRFC, joan.decker@cea.fr) 

Write matrix A and vector B in MUMPS_in binary file

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [X,flag,text] = MUMPS_dke_yp(MUMPSparam,A,B,display_mode,dkepath)
0002 %
0003 %Link with the parallel matrix solver package MUMPS written in FORTRAN. This is a modified package wich is able to
0004 %read binary files written by MatLab, which needs to be compiled first.
0005 %Tested on LINUX clusters (parallel or sequential)
0006 %
0007 %Solve the linear system of equation AX=B
0008 %
0009 % INPUTS:
0010 %
0011 %   - MUMPSparam: Structure for controling MUMPS program.
0012 %    - A: Matrix [n,n]
0013 %   - B: Vector for solving the linear system of equations AX=B [n,1]
0014 %   - display_mode: display some results [1,1]
0015 %   - dkepath: paths structure
0016 %
0017 % OUTPUTS:
0018 %
0019 %   - X: Solution of the linear system of equation [n,1]
0020 %   - flag: execution flag (see the MUMPS documentation) [1,1]
0021 %   - text: execution documentation (see the HYPRE documentation)
0022 %
0023 %by Yves Peysson (CEA-DRFC, yves.peysson@cea.fr) and Joan Decker (CEA-DRFC, joan.decker@cea.fr)
0024 %
0025 %Write matrix A and vector B in MUMPS_in binary file
0026 %
0027 if nargin < 5,error('Wrong number of input arguments in MUMPS_dke_yp !');end
0028 %
0029 N = size(A,2);
0030 [AI,AJ,AV] = find(A);
0031 NA = length(AI);%number of non-zero elements
0032 %
0033 flag = 0;text = '';
0034 %
0035 initial_dir = cd;
0036 if ~exist(dkepath.temppath);
0037     mkdir(dkepath.temppath);%Create calculation directory
0038 end
0039 cd(dkepath.temppath);%Move to calculation directory
0040 %
0041 % Write one file per variable for MatLab <-> FORTRAN in the scratch directory
0042 %
0043 delete MUMPS_*
0044 fid = fopen('MUMPS_N_in.bin','wb');fwrite(fid,N,'double');if (fclose(fid)~=0), error('Impossible to write input file for MUMPS N in the scratch directory');end
0045 fid = fopen('MUMPS_NA_in.bin','wb');fwrite(fid,NA,'double');if (fclose(fid)~=0), error('Impossible to write input file for MUMPS NZ in the scratch directory');end
0046 fid = fopen('MUMPS_AI_in.bin','wb');fwrite(fid,AI,'double');if (fclose(fid)~=0), error('Impossible to write input file for MUMPS AI in the scratch directory');end
0047 fid = fopen('MUMPS_AJ_in.bin','wb');fwrite(fid,AJ,'double');if (fclose(fid)~=0), error('Impossible to write input file for MUMPS AJ in the scratch directory');end
0048 fid = fopen('MUMPS_AV_in.bin','wb');fwrite(fid,AV,'double');if (fclose(fid)~=0), error('Impossible to write input file for MUMPS AV in the scratch directory');end
0049 fid = fopen('MUMPS_B_in.bin','wb');fwrite(fid,B,'double');if (fclose(fid)~=0), error('Impossible to write input file for MUMPS B in the scratch directory');end
0050 %
0051 % Computer management
0052 %
0053 nproc = nproc_dke_yp(display_mode,MUMPSparam,dkepath);
0054 %
0055 if nproc > 1,%Parallel processing is invoked
0056     if isfield(dkepath.MUMPS,'par'),
0057         if display_mode >= 1,info_dke_yp(2,'Matrix inversion by MUMPS solver - parallel processing -');end
0058         [flag,text] = unix([dkepath.MUMPS.mpipath,'mpirun -np ',int2str(nproc),' -machinefile .machines ',dkepath.MUMPS.par,'/mumpsdke']);
0059     elseif isfield(dkepath.MUMPS,'seq'),
0060         if display_mode >= 1,info_dke_yp(2,'Matrix inversion by PETSc solver - sequential processing enforced, no parallel processing package on this machine ! -');end
0061         [flag,text] = unix([dkepath.MUMPS.seq,'/mumpsdke']);
0062     else
0063         error('MUMPS package not correctly named for LUKE: <pakage name+version>_P_<compiler name> or  <pakage name+version>_S_<compiler name>');
0064     end
0065 elseif nproc == 1,%Sequential processing is invoked
0066     if isfield(dkepath.MUMPS,'seq'),
0067         if display_mode >= 1,info_dke_yp(2,'Matrix inversion by MUMPS solver - sequential processing -');end
0068         [flag,text] = unix([dkepath.MUMPS.seq,'/mumpsdke']);
0069     elseif isfield(dkepath.MUMPS,'par'),
0070         if display_mode >= 1,info_dke_yp(2,'Matrix inversion by MUMPS solver - parallel processing enforced, no sequential processing package on this machine !  -');end
0071         [flag,text] = unix([dkepath.MUMPS.mpipath,'mpirun -np ',int2str(nproc),' -machinefile .machines ',dkepath.MUMPS.par,'/mumpsdke']);
0072     else
0073         info_dke_yp(7,'MUMPS package not correctly named for LUKE: <pakage name+version>_P_<compiler name> or  <pakage name+version>_S_<compiler name>',1,'red');error('');
0074     end
0075 end
0076 %
0077 % Read one file per variable for MatLab <-> MUMPS FORTRAN
0078 %
0079 if flag == 0,
0080    fid=fopen('MUMPS_X_out.bin','rb');X=fread(fid,N,'double');fclose(fid);%solution of the system of equation
0081    X = X(:);
0082 else
0083    info_dke_yp(7,['Error in MUMPS calculation. Flag =',int2str(flag),', Log = ',text],1,'red');error('');
0084 end
0085 %
0086 delete('*.bin');%delete all bin files
0087 cd(initial_dir);%return to the initial working directory
0088 
0089   
0090   
0091

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.