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 COMMUV(dof, nNo, commu, cS, R) 42*1e99f302SBen Matthews 43*1e99f302SBen Matthews INCLUDE "svLS_STD.h" 44*1e99f302SBen Matthews 45*1e99f302SBen Matthews INTEGER, INTENT(IN) :: dof, nNo 46*1e99f302SBen Matthews TYPE(svLS_commuType), INTENT(IN) :: commu 47*1e99f302SBen Matthews TYPE(svLS_cSType), INTENT(IN) :: cS(commu%nTasks) 48*1e99f302SBen Matthews REAL*8, INTENT(INOUT) :: R(dof,nNo) 49*1e99f302SBen Matthews 50*1e99f302SBen Matthews INTEGER i, j, k, s, e, ierr, nTasks, tF, stat(MPI_STATUS_SIZE) 51*1e99f302SBen Matthews INTEGER comm 52*1e99f302SBen Matthews REAL*8, ALLOCATABLE :: rTmp(:,:) 53*1e99f302SBen Matthews 54*1e99f302SBen Matthews IF (commu%nTasks .EQ. 1) RETURN 55*1e99f302SBen Matthews 56*1e99f302SBen Matthews nTasks = commu%nTasks 57*1e99f302SBen Matthews tF = commu%tF 58*1e99f302SBen Matthews comm = commu%comm 59*1e99f302SBen Matthews 60*1e99f302SBen Matthews IF (tF .NE. 1) THEN 61*1e99f302SBen Matthews i = tF - 1 62*1e99f302SBen Matthews i = cS(i)%ptr + cS(i)%n - 1 63*1e99f302SBen Matthews ALLOCATE(rTmp(dof,i)) 64*1e99f302SBen Matthews END IF 65*1e99f302SBen Matthews 66*1e99f302SBen Matthews DO i=1, nTasks 67*1e99f302SBen Matthews IF (cS(i)%tag .NE. 0) THEN 68*1e99f302SBen Matthews s = cS(i)%ptr 69*1e99f302SBen Matthews e = s + cS(i)%n - 1 70*1e99f302SBen Matthews IF (i .LT. tF) THEN 71*1e99f302SBen Matthews CALL MPI_IRECV(rTmp(:,s:e), cS(i)%n*dof, mpreal, i-1, 72*1e99f302SBen Matthews 2 cS(i)%tag, comm, cS(i)%req, ierr) 73*1e99f302SBen Matthews ELSE 74*1e99f302SBen Matthews CALL MPI_ISEND(R(:,s:e), cS(i)%n*dof, mpreal, i-1, 75*1e99f302SBen Matthews 2 cS(i)%tag, comm, cS(i)%req, ierr) 76*1e99f302SBen Matthews END IF 77*1e99f302SBen Matthews END IF 78*1e99f302SBen Matthews END DO 79*1e99f302SBen Matthews 80*1e99f302SBen Matthews k = 1 81*1e99f302SBen Matthews DO i=1, tF - 1 82*1e99f302SBen Matthews IF (cS(i)%tag .NE. 0) THEN 83*1e99f302SBen Matthews CALL MPI_WAIT(cS(i)%req, stat, ierr) 84*1e99f302SBen Matthews DO j=1, cS(i)%nBl 85*1e99f302SBen Matthews s = cS(i)%blPtr(j) 86*1e99f302SBen Matthews e = s + cS(i)%blN(j) - 1 87*1e99f302SBen Matthews R(:,s:e) = R(:,s:e) + rTmp(:,k:k+e-s) 88*1e99f302SBen Matthews k = k + cS(i)%blN(j) 89*1e99f302SBen Matthews END DO 90*1e99f302SBen Matthews END IF 91*1e99f302SBen Matthews END DO 92*1e99f302SBen Matthews 93*1e99f302SBen Matthews k = 1 94*1e99f302SBen Matthews DO i=1, tF - 1 95*1e99f302SBen Matthews DO j=1, cS(i)%nBl 96*1e99f302SBen Matthews s = cS(i)%blPtr(j) 97*1e99f302SBen Matthews e = s + cS(i)%blN(j) - 1 98*1e99f302SBen Matthews rTmp(:,k:k+e-s) = R(:,s:e) 99*1e99f302SBen Matthews k = k + cS(i)%blN(j) 100*1e99f302SBen Matthews END DO 101*1e99f302SBen Matthews END DO 102*1e99f302SBen Matthews 103*1e99f302SBen Matthews DO i=1, nTasks 104*1e99f302SBen Matthews IF (cS(i)%tag .NE. 0) THEN 105*1e99f302SBen Matthews s = cS(i)%ptr 106*1e99f302SBen Matthews e = s + cS(i)%n - 1 107*1e99f302SBen Matthews IF (i .GT. tF) THEN 108*1e99f302SBen Matthews CALL MPI_WAIT(cS(i)%req, stat, ierr) 109*1e99f302SBen Matthews CALL MPI_IRECV(R(:,s:e), cS(i)%n*dof, mpreal, i-1, 110*1e99f302SBen Matthews 2 cS(i)%tag, comm, cS(i)%req, ierr) 111*1e99f302SBen Matthews ELSE 112*1e99f302SBen Matthews CALL MPI_ISEND(rTmp(:,s:e), cS(i)%n*dof, mpreal, i-1, 113*1e99f302SBen Matthews 2 cS(i)%tag, comm, cS(i)%req, ierr) 114*1e99f302SBen Matthews END IF 115*1e99f302SBen Matthews END IF 116*1e99f302SBen Matthews END DO 117*1e99f302SBen Matthews 118*1e99f302SBen Matthews DO i=1, nTasks 119*1e99f302SBen Matthews IF (cS(i)%tag .NE. 0) THEN 120*1e99f302SBen Matthews CALL MPI_WAIT(cS(i)%req, stat, ierr) 121*1e99f302SBen Matthews END IF 122*1e99f302SBen Matthews END DO 123*1e99f302SBen Matthews 124*1e99f302SBen Matthews RETURN 125*1e99f302SBen Matthews END SUBROUTINE COMMUV 126*1e99f302SBen Matthews 127*1e99f302SBen Matthews!==================================================================== 128*1e99f302SBen Matthews 129*1e99f302SBen Matthews SUBROUTINE COMMUS(nNo, commu, cS, R) 130*1e99f302SBen Matthews 131*1e99f302SBen Matthews INCLUDE "svLS_STD.h" 132*1e99f302SBen Matthews 133*1e99f302SBen Matthews INTEGER, INTENT(IN) :: nNo 134*1e99f302SBen Matthews TYPE(svLS_commuType), INTENT(IN) :: commu 135*1e99f302SBen Matthews TYPE(svLS_cSType), INTENT(IN) :: cS(commu%nTasks) 136*1e99f302SBen Matthews REAL*8, INTENT(INOUT) :: R(nNo) 137*1e99f302SBen Matthews 138*1e99f302SBen Matthews INTEGER i, j, k, s, e, ierr, nTasks, tF, stat(MPI_STATUS_SIZE) 139*1e99f302SBen Matthews INTEGER comm 140*1e99f302SBen Matthews REAL*8, ALLOCATABLE :: rTmp(:) 141*1e99f302SBen Matthews 142*1e99f302SBen Matthews IF (commu%nTasks .EQ. 1) RETURN 143*1e99f302SBen Matthews 144*1e99f302SBen Matthews nTasks = commu%nTasks 145*1e99f302SBen Matthews tF = commu%tF 146*1e99f302SBen Matthews comm = commu%comm 147*1e99f302SBen Matthews 148*1e99f302SBen Matthews IF (tF .NE. 1) THEN 149*1e99f302SBen Matthews i = tF - 1 150*1e99f302SBen Matthews i = cS(i)%ptr + cS(i)%n - 1 151*1e99f302SBen Matthews ALLOCATE(rTmp(i)) 152*1e99f302SBen Matthews END IF 153*1e99f302SBen Matthews 154*1e99f302SBen Matthews DO i=1, nTasks 155*1e99f302SBen Matthews IF (cS(i)%tag .NE. 0) THEN 156*1e99f302SBen Matthews s = cS(i)%ptr 157*1e99f302SBen Matthews e = s + cS(i)%n - 1 158*1e99f302SBen Matthews IF (i .LT. tF) THEN 159*1e99f302SBen Matthews CALL MPI_IRECV(rTmp(s:e), cS(i)%n, mpreal, i-1, 160*1e99f302SBen Matthews 2 cS(i)%tag, comm, cS(i)%req, ierr) 161*1e99f302SBen Matthews ELSE 162*1e99f302SBen Matthews CALL MPI_ISEND(R(s:e), cS(i)%n, mpreal, i-1, 163*1e99f302SBen Matthews 2 cS(i)%tag, comm, cS(i)%req, ierr) 164*1e99f302SBen Matthews END IF 165*1e99f302SBen Matthews END IF 166*1e99f302SBen Matthews END DO 167*1e99f302SBen Matthews 168*1e99f302SBen Matthews k = 1 169*1e99f302SBen Matthews DO i=1, tF - 1 170*1e99f302SBen Matthews IF (cS(i)%tag .NE. 0) THEN 171*1e99f302SBen Matthews CALL MPI_WAIT(cS(i)%req, stat, ierr) 172*1e99f302SBen Matthews DO j=1, cS(i)%nBl 173*1e99f302SBen Matthews s = cS(i)%blPtr(j) 174*1e99f302SBen Matthews e = s + cS(i)%blN(j) - 1 175*1e99f302SBen Matthews R(s:e) = R(s:e) + rTmp(k:k+e-s) 176*1e99f302SBen Matthews k = k + cS(i)%blN(j) 177*1e99f302SBen Matthews END DO 178*1e99f302SBen Matthews END IF 179*1e99f302SBen Matthews END DO 180*1e99f302SBen Matthews 181*1e99f302SBen Matthews k = 1 182*1e99f302SBen Matthews DO i=1, tF - 1 183*1e99f302SBen Matthews DO j=1, cS(i)%nBl 184*1e99f302SBen Matthews s = cS(i)%blPtr(j) 185*1e99f302SBen Matthews e = s + cS(i)%blN(j) - 1 186*1e99f302SBen Matthews rTmp(k:k+e-s) = R(s:e) 187*1e99f302SBen Matthews k = k + cS(i)%blN(j) 188*1e99f302SBen Matthews END DO 189*1e99f302SBen Matthews END DO 190*1e99f302SBen Matthews 191*1e99f302SBen Matthews DO i=1, nTasks 192*1e99f302SBen Matthews IF (cS(i)%tag .NE. 0) THEN 193*1e99f302SBen Matthews s = cS(i)%ptr 194*1e99f302SBen Matthews e = s + cS(i)%n - 1 195*1e99f302SBen Matthews IF (i .GT. tF) THEN 196*1e99f302SBen Matthews CALL MPI_WAIT(cS(i)%req, stat, ierr) 197*1e99f302SBen Matthews CALL MPI_IRECV(R(s:e), cS(i)%n, mpreal, i-1, 198*1e99f302SBen Matthews 2 cS(i)%tag, comm, cS(i)%req, ierr) 199*1e99f302SBen Matthews ELSE 200*1e99f302SBen Matthews CALL MPI_ISEND(rTmp(s:e), cS(i)%n, mpreal, i-1, 201*1e99f302SBen Matthews 2 cS(i)%tag, comm, cS(i)%req, ierr) 202*1e99f302SBen Matthews END IF 203*1e99f302SBen Matthews END IF 204*1e99f302SBen Matthews END DO 205*1e99f302SBen Matthews 206*1e99f302SBen Matthews DO i=1, nTasks 207*1e99f302SBen Matthews IF (cS(i)%tag .NE. 0) THEN 208*1e99f302SBen Matthews CALL MPI_WAIT(cS(i)%req, stat, ierr) 209*1e99f302SBen Matthews END IF 210*1e99f302SBen Matthews END DO 211*1e99f302SBen Matthews 212*1e99f302SBen Matthews RETURN 213*1e99f302SBen Matthews END SUBROUTINE COMMUS 214*1e99f302SBen Matthews 215