xref: /phasta/svLS/SPARMUL.f (revision 712d3df0b59ebebaaeaea358162c8d2c043c6e08)
1*1e99f302SBen Matthews!     This software is Copyright (c) 2012-2015 The Regents of the
2*1e99f302SBen Matthews!     University of California. All Rights Reserved.
3*1e99f302SBen Matthews!
4*1e99f302SBen Matthews!     Permission to copy and modify this software and its documentation
5*1e99f302SBen Matthews!     for educational, research and non-profit purposes, without fee,
6*1e99f302SBen Matthews!     and without a written agreement is hereby granted, provided that
7*1e99f302SBen Matthews!     the above copyright notice, this paragraph and the following three
8*1e99f302SBen Matthews!     paragraphs appear in all copies.
9*1e99f302SBen Matthews!
10*1e99f302SBen Matthews!     Permission to make commercial use of this software may be obtained
11*1e99f302SBen Matthews!     by contacting:
12*1e99f302SBen Matthews!
13*1e99f302SBen Matthews!     Technology Transfer Office
14*1e99f302SBen Matthews!     9500 Gilman Drive, Mail Code 0910
15*1e99f302SBen Matthews!     University of California
16*1e99f302SBen Matthews!     La Jolla, CA 92093-0910
17*1e99f302SBen Matthews!     (858) 534-5815
18*1e99f302SBen Matthews!     invent@ucsd.edu
19*1e99f302SBen Matthews!
20*1e99f302SBen Matthews!     This software program and documentation are copyrighted by The
21*1e99f302SBen Matthews!     Regents of the University of California. The software program and
22*1e99f302SBen Matthews!     documentation are supplied "as is", without any accompanying
23*1e99f302SBen Matthews!     services from The Regents. The Regents does not warrant that the
24*1e99f302SBen Matthews!     operation of the program will be uninterrupted or error-free. The
25*1e99f302SBen Matthews!     end-user understands that the program was developed for research
26*1e99f302SBen Matthews!     purposes and is advised not to rely exclusively on the program for
27*1e99f302SBen Matthews!     any reason.
28*1e99f302SBen Matthews!
29*1e99f302SBen Matthews!     IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
30*1e99f302SBen Matthews!     PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
31*1e99f302SBen Matthews!     DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS
32*1e99f302SBen Matthews!     SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
33*1e99f302SBen Matthews!     CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34*1e99f302SBen Matthews!     THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
35*1e99f302SBen Matthews!     WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36*1e99f302SBen Matthews!     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
37*1e99f302SBen Matthews!     SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
38*1e99f302SBen Matthews!     UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE
39*1e99f302SBen Matthews!     MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
40*1e99f302SBen Matthews
41*1e99f302SBen Matthews      SUBROUTINE SPARMULVV(dof, nNo, nnz, commu, cS, rowPtr, colPtr,
42*1e99f302SBen Matthews     2   K, U, KU)
43*1e99f302SBen Matthews
44*1e99f302SBen Matthews      INCLUDE "svLS_STD.h"
45*1e99f302SBen Matthews
46*1e99f302SBen Matthews      INTEGER, INTENT(IN) :: dof, nNo, nnz
47*1e99f302SBen Matthews      TYPE(svLS_commuType), INTENT(IN) :: commu
48*1e99f302SBen Matthews      TYPE(svLS_cSType), INTENT(IN) :: cS(commu%nTasks)
49*1e99f302SBen Matthews      INTEGER, INTENT(IN) :: rowPtr(2,nNo), colPtr(nnz)
50*1e99f302SBen Matthews      REAL*8, INTENT(IN) :: K(dof*dof,nnz), U(dof,nNo)
51*1e99f302SBen Matthews      REAL*8, INTENT(OUT) :: KU(dof,nNo)
52*1e99f302SBen Matthews
53*1e99f302SBen Matthews      INTEGER i, j, l, col, s, e
54*1e99f302SBen Matthews
55*1e99f302SBen Matthews      KU = 0D0
56*1e99f302SBen Matthews      SELECT CASE (dof)
57*1e99f302SBen Matthews      CASE (1)
58*1e99f302SBen Matthews         DO i=1, nNo
59*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
60*1e99f302SBen Matthews               KU(1,i) = KU(1,i) + K(1,j)*U(1,colPtr(j))
61*1e99f302SBen Matthews            END DO
62*1e99f302SBen Matthews         END DO
63*1e99f302SBen Matthews      CASE(2)
64*1e99f302SBen Matthews         DO i=1, nNo
65*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
66*1e99f302SBen Matthews               col = colPtr(j)
67*1e99f302SBen Matthews               KU(1,i) = KU(1,i) + K(1,j)*U(1,col) + K(2,j)*U(2,col)
68*1e99f302SBen Matthews               KU(2,i) = KU(2,i) + K(3,j)*U(1,col) + K(4,j)*U(2,col)
69*1e99f302SBen Matthews            END DO
70*1e99f302SBen Matthews         END DO
71*1e99f302SBen Matthews      CASE(3)
72*1e99f302SBen Matthews         DO i=1, nNo
73*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
74*1e99f302SBen Matthews               col = colPtr(j)
75*1e99f302SBen Matthews               KU(1,i) = KU(1,i) + K(1,j)*U(1,col) + K(2,j)*U(2,col)
76*1e99f302SBen Matthews     2                           + K(3,j)*U(3,col)
77*1e99f302SBen Matthews               KU(2,i) = KU(2,i) + K(4,j)*U(1,col) + K(5,j)*U(2,col)
78*1e99f302SBen Matthews     2                           + K(6,j)*U(3,col)
79*1e99f302SBen Matthews               KU(3,i) = KU(3,i) + K(7,j)*U(1,col) + K(8,j)*U(2,col)
80*1e99f302SBen Matthews     2                           + K(9,j)*U(3,col)
81*1e99f302SBen Matthews            END DO
82*1e99f302SBen Matthews         END DO
83*1e99f302SBen Matthews      CASE(4)
84*1e99f302SBen Matthews         DO i=1, nNo
85*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
86*1e99f302SBen Matthews               col = colPtr(j)
87*1e99f302SBen Matthews               KU(1,i) = KU(1,i) + K(1 ,j)*U(1,col) + K(2 ,j)*U(2,col)
88*1e99f302SBen Matthews     2                           + K(3 ,j)*U(3,col) + K(4 ,j)*U(4,col)
89*1e99f302SBen Matthews               KU(2,i) = KU(2,i) + K(5 ,j)*U(1,col) + K(6 ,j)*U(2,col)
90*1e99f302SBen Matthews     2                           + K(7 ,j)*U(3,col) + K(8 ,j)*U(4,col)
91*1e99f302SBen Matthews               KU(3,i) = KU(3,i) + K(9 ,j)*U(1,col) + K(10,j)*U(2,col)
92*1e99f302SBen Matthews     2                           + K(11,j)*U(3,col) + K(12,j)*U(4,col)
93*1e99f302SBen Matthews               KU(4,i) = KU(4,i) + K(13,j)*U(1,col) + K(14,j)*U(2,col)
94*1e99f302SBen Matthews     2                           + K(15,j)*U(3,col) + K(16,j)*U(4,col)
95*1e99f302SBen Matthews            END DO
96*1e99f302SBen Matthews         END DO
97*1e99f302SBen Matthews      CASE DEFAULT
98*1e99f302SBen Matthews         DO i=1, nNo
99*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
100*1e99f302SBen Matthews               col = colPtr(j)
101*1e99f302SBen Matthews               DO l=1, dof
102*1e99f302SBen Matthews                  e = l*dof
103*1e99f302SBen Matthews                  s = e - dof + 1
104*1e99f302SBen Matthews                  KU(l,i) = KU(l,i) + SUM(K(s:e,j)*U(:,col))
105*1e99f302SBen Matthews               END DO
106*1e99f302SBen Matthews            END DO
107*1e99f302SBen Matthews         END DO
108*1e99f302SBen Matthews      END SELECT
109*1e99f302SBen Matthews
110*1e99f302SBen Matthews      CALL COMMUV(dof, nNo, commu, cS, KU)
111*1e99f302SBen Matthews
112*1e99f302SBen Matthews      RETURN
113*1e99f302SBen Matthews      END SUBROUTINE SPARMULVV
114*1e99f302SBen Matthews
115*1e99f302SBen Matthews!====================================================================
116*1e99f302SBen Matthews
117*1e99f302SBen Matthews      SUBROUTINE SPARMULVS(dof, nNo, nnz, commu, cS, rowPtr, colPtr,
118*1e99f302SBen Matthews     2   K, U, KU)
119*1e99f302SBen Matthews
120*1e99f302SBen Matthews      INCLUDE "svLS_STD.h"
121*1e99f302SBen Matthews
122*1e99f302SBen Matthews      INTEGER, INTENT(IN) :: dof, nNo, nnz
123*1e99f302SBen Matthews      TYPE(svLS_commuType), INTENT(IN) :: commu
124*1e99f302SBen Matthews      TYPE(svLS_cSType), INTENT(IN) :: cS(commu%nTasks)
125*1e99f302SBen Matthews      INTEGER, INTENT(IN) :: rowPtr(2,nNo), colPtr(nnz)
126*1e99f302SBen Matthews      REAL*8, INTENT(IN) :: K(dof,nnz), U(dof,nNo)
127*1e99f302SBen Matthews      REAL*8, INTENT(OUT) :: KU(nNo)
128*1e99f302SBen Matthews
129*1e99f302SBen Matthews      INTEGER i, j, col
130*1e99f302SBen Matthews
131*1e99f302SBen Matthews      KU = 0D0
132*1e99f302SBen Matthews      SELECT CASE (dof)
133*1e99f302SBen Matthews      CASE (1)
134*1e99f302SBen Matthews         DO i=1, nNo
135*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
136*1e99f302SBen Matthews               KU(i) = KU(i) + K(1,j)*U(1,colPtr(j))
137*1e99f302SBen Matthews            END DO
138*1e99f302SBen Matthews         END DO
139*1e99f302SBen Matthews      CASE(2)
140*1e99f302SBen Matthews         DO i=1, nNo
141*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
142*1e99f302SBen Matthews               col = colPtr(j)
143*1e99f302SBen Matthews               KU(i) = KU(i) + K(1,j)*U(1,col) + K(2,j)*U(2,col)
144*1e99f302SBen Matthews            END DO
145*1e99f302SBen Matthews         END DO
146*1e99f302SBen Matthews      CASE(3)
147*1e99f302SBen Matthews         DO i=1, nNo
148*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
149*1e99f302SBen Matthews               col = colPtr(j)
150*1e99f302SBen Matthews               KU(i) = KU(i) + K(1,j)*U(1,col) + K(2,j)*U(2,col)
151*1e99f302SBen Matthews     2                       + K(3,j)*U(3,col)
152*1e99f302SBen Matthews            END DO
153*1e99f302SBen Matthews         END DO
154*1e99f302SBen Matthews      CASE(4)
155*1e99f302SBen Matthews         DO i=1, nNo
156*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
157*1e99f302SBen Matthews               col = colPtr(j)
158*1e99f302SBen Matthews               KU(i) = KU(i) + K(1,j)*U(1,col) + K(2,j)*U(2,col)
159*1e99f302SBen Matthews     2                       + K(3,j)*U(3,col) + K(4,j)*U(4,col)
160*1e99f302SBen Matthews            END DO
161*1e99f302SBen Matthews         END DO
162*1e99f302SBen Matthews      CASE DEFAULT
163*1e99f302SBen Matthews         DO i=1, nNo
164*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
165*1e99f302SBen Matthews               KU(i) = KU(i) + SUM(K(:,j)*U(:,colPtr(j)))
166*1e99f302SBen Matthews            END DO
167*1e99f302SBen Matthews         END DO
168*1e99f302SBen Matthews      END SELECT
169*1e99f302SBen Matthews
170*1e99f302SBen Matthews      CALL COMMUS(nNo, commu, cS, KU)
171*1e99f302SBen Matthews
172*1e99f302SBen Matthews      RETURN
173*1e99f302SBen Matthews      END SUBROUTINE SPARMULVS
174*1e99f302SBen Matthews
175*1e99f302SBen Matthews!====================================================================
176*1e99f302SBen Matthews
177*1e99f302SBen Matthews      SUBROUTINE SPARMULSV(dof, nNo, nnz, commu, cS, rowPtr, colPtr,
178*1e99f302SBen Matthews     2   K, U, KU)
179*1e99f302SBen Matthews
180*1e99f302SBen Matthews      INCLUDE "svLS_STD.h"
181*1e99f302SBen Matthews
182*1e99f302SBen Matthews      INTEGER, INTENT(IN) :: dof, nNo, nnz
183*1e99f302SBen Matthews      TYPE(svLS_commuType), INTENT(IN) :: commu
184*1e99f302SBen Matthews      TYPE(svLS_cSType), INTENT(IN) :: cS(commu%nTasks)
185*1e99f302SBen Matthews      INTEGER, INTENT(IN) :: rowPtr(2,nNo), colPtr(nnz)
186*1e99f302SBen Matthews      REAL*8, INTENT(IN) :: K(dof,nnz), U(nNo)
187*1e99f302SBen Matthews      REAL*8, INTENT(OUT) :: KU(dof,nNo)
188*1e99f302SBen Matthews
189*1e99f302SBen Matthews      INTEGER i, j, col
190*1e99f302SBen Matthews
191*1e99f302SBen Matthews      KU = 0D0
192*1e99f302SBen Matthews      SELECT CASE (dof)
193*1e99f302SBen Matthews      CASE (1)
194*1e99f302SBen Matthews         DO i=1, nNo
195*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
196*1e99f302SBen Matthews               KU(1,i) = KU(1,i) + K(1,j)*U(colPtr(j))
197*1e99f302SBen Matthews            END DO
198*1e99f302SBen Matthews         END DO
199*1e99f302SBen Matthews      CASE(2)
200*1e99f302SBen Matthews         DO i=1, nNo
201*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
202*1e99f302SBen Matthews               col = colPtr(j)
203*1e99f302SBen Matthews               KU(1,i) = KU(1,i) + K(1,j)*U(col)
204*1e99f302SBen Matthews               KU(2,i) = KU(2,i) + K(2,j)*U(col)
205*1e99f302SBen Matthews            END DO
206*1e99f302SBen Matthews         END DO
207*1e99f302SBen Matthews      CASE(3)
208*1e99f302SBen Matthews         DO i=1, nNo
209*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
210*1e99f302SBen Matthews               col = colPtr(j)
211*1e99f302SBen Matthews               KU(1,i) = KU(1,i) + K(1,j)*U(col)
212*1e99f302SBen Matthews               KU(2,i) = KU(2,i) + K(2,j)*U(col)
213*1e99f302SBen Matthews               KU(3,i) = KU(3,i) + K(3,j)*U(col)
214*1e99f302SBen Matthews            END DO
215*1e99f302SBen Matthews         END DO
216*1e99f302SBen Matthews      CASE(4)
217*1e99f302SBen Matthews         DO i=1, nNo
218*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
219*1e99f302SBen Matthews               col = colPtr(j)
220*1e99f302SBen Matthews               KU(1,i) = KU(1,i) + K(1,j)*U(col)
221*1e99f302SBen Matthews               KU(2,i) = KU(2,i) + K(2,j)*U(col)
222*1e99f302SBen Matthews               KU(3,i) = KU(3,i) + K(3,j)*U(col)
223*1e99f302SBen Matthews               KU(4,i) = KU(4,i) + K(4,j)*U(col)
224*1e99f302SBen Matthews            END DO
225*1e99f302SBen Matthews         END DO
226*1e99f302SBen Matthews      CASE DEFAULT
227*1e99f302SBen Matthews         DO i=1, nNo
228*1e99f302SBen Matthews            DO j=rowPtr(1,i), rowPtr(2,i)
229*1e99f302SBen Matthews               KU(:,i) = KU(:,i) + K(:,j)*U(colPtr(j))
230*1e99f302SBen Matthews            END DO
231*1e99f302SBen Matthews         END DO
232*1e99f302SBen Matthews      END SELECT
233*1e99f302SBen Matthews
234*1e99f302SBen Matthews      CALL COMMUV(dof, nNo, commu, cS, KU)
235*1e99f302SBen Matthews
236*1e99f302SBen Matthews      RETURN
237*1e99f302SBen Matthews      END SUBROUTINE SPARMULSV
238*1e99f302SBen Matthews
239*1e99f302SBen Matthews!====================================================================
240*1e99f302SBen Matthews
241*1e99f302SBen Matthews      SUBROUTINE SPARMULSS(nNo, nnz, commu, cS, rowPtr, colPtr,
242*1e99f302SBen Matthews     2   K, U, KU)
243*1e99f302SBen Matthews
244*1e99f302SBen Matthews      INCLUDE "svLS_STD.h"
245*1e99f302SBen Matthews
246*1e99f302SBen Matthews      INTEGER, INTENT(IN) :: nNo, nnz
247*1e99f302SBen Matthews      TYPE(svLS_commuType), INTENT(IN) :: commu
248*1e99f302SBen Matthews      TYPE(svLS_cSType), INTENT(IN) :: cS(commu%nTasks)
249*1e99f302SBen Matthews      INTEGER, INTENT(IN) :: rowPtr(2,nNo), colPtr(nnz)
250*1e99f302SBen Matthews      REAL*8, INTENT(IN) :: K(nnz), U(nNo)
251*1e99f302SBen Matthews      REAL*8, INTENT(OUT) :: KU(nNo)
252*1e99f302SBen Matthews
253*1e99f302SBen Matthews      INTEGER i, j
254*1e99f302SBen Matthews
255*1e99f302SBen Matthews      KU = 0D0
256*1e99f302SBen Matthews      DO i=1, nNo
257*1e99f302SBen Matthews         DO j=rowPtr(1,i), rowPtr(2,i)
258*1e99f302SBen Matthews            KU(i) = KU(i) + K(j)*U(colPtr(j))
259*1e99f302SBen Matthews         END DO
260*1e99f302SBen Matthews      END DO
261*1e99f302SBen Matthews
262*1e99f302SBen Matthews      CALL COMMUS(nNo, commu, cS, KU)
263*1e99f302SBen Matthews
264*1e99f302SBen Matthews      RETURN
265*1e99f302SBen Matthews      END SUBROUTINE SPARMULSS
266*1e99f302SBen Matthews
267