I need to revove a column from a large sparse matrix that is stored in CSR format, using MKL. I cannot find an MKL routine that does this directly. Can anyone tell me how it can be done? I'm using Fortran. Thx. Bob
Link Copied
Here is similar code for an unsymmetric, non-square matrix. The matrix is 7 X 8 and column-3 is deleted, giving a 7 X 7 matrix.
Here is an example where the input 8 X 8 matrix is symmetric and only the upper triangle is processed. The example shows the third column being deleted. The call to mkl_ddnscsr() is only for printing purposes, and is not needed for the column deletion.
[NOTE: The program listing is portrayed by the formatter as double spaced. That was not intended, and I request the Intel people to tell me how to avoid such unintended double spacing.]
[fortran] PROGRAM pardiso_sym
IMPLICIT NONE
C.. All other variables
INTEGER maxfct, mnum, mtype, phase, n, nrhs, error, msglvl
INTEGER iparm(64)
INTEGER ia(9),ian(9)
INTEGER ja(18)
REAL*8 a(18),ad(8,7)
REAL*8 b(8)
REAL*8 x(8)
INTEGER i, j,k,kn, idum,job(6), info, jdel
REAL*8 waltime1, waltime2, ddum
C.. Fill all arrays containing matrix data.
DATA n /8/, nrhs /1/, maxfct /1/, mnum /1/
DATA ia /1,5,8,10,12,15,17,18,19/
DATA ja
1 /1, 3, 6,7,
2 2,3, 5,
3 3, 8,
4 4, 7,
5 5,6,7,
6 6, 8,
7 7,
8 8/
DATA a
1 /7.d0, 1.d0, 2.d0,7.d0,
2 -4.d0,8.d0, 2.d0,
3 1.d0, 5.d0,
4 7.d0, 9.d0,
5 5.d0,1.d0,5.d0,
6 -1.d0, 5.d0,
7 11.d0,
8 5.d0/
c
c Drop column 3
c
data job/1,1,1,0,0,0/
c
jdel = 3 ! column to delete
kn = 0
ian(1)=1
do i=1,n
do k=ia(i),ia(i+1)-1 ! row i
if(ja(k).ne.jdel)then
kn=kn+1
if(ja(k).gt.jdel)then
ja(kn)=ja(k)-1
else
ja(kn)=ja(k)
endif
a(kn)=a(k)
endif
end do
ian(i+1)=kn+1
end do
c
do i=1,n
write(*,'(7(2x,I2,1x,F10.3))')(ja(j),a(j),j=ian(i),ian(i+1)-1)
end do
write(*,*)
call mkl_ddnscsr(job,n,n-1,ad,n,a,ja,ian,info)
write(*,*)'info = ',info
do i=1,n
write(*,'(7F10.3)')(ad(i,j),j=1,7)
end do
END[/fortran]
Here is an example that shows how to perform the column deletion that you sought. I show how to delete a column in a symmetric matrix represented by only its upper triangular part. Please note that the call to mkl_ddnscsr() is not needed for the column deletion, but to facilitate printing the modified matrix.
[Note to Forum Moderators: My first response (#2) was held up for approval for several hours. Then, after it was approved, I noticed that the inline code was formatted with double spacing, and added a couple of sentences to #2 to disclaim that I had inserted the extra blank lines. When I did the edits and clicked "SUBMIT", the whole of #2 evaporated, and the forum TOC showed the number of replies as 0. In response to this event, I posted #3. Subsequently, #2 appeared again. There is much duplication between the two: readers please note this!]
mecej4, Thx so much. It works great. Do you happen to have a version of this code that would work on an non-symmetric, sparse matrix. If you do, that would be very helpful too.
Here is similar code for an unsymmetric, non-square matrix. The matrix is 7 X 8 and column-3 is deleted, giving a 7 X 7 matrix.
meje4 - Thx again - It works great - I appreciate your help.
Thanks again for helping me with this. You have been very helpful.
For more complete information about compiler optimizations, see our Optimization Notice.