Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCA: Generate DO statement inside existing IF statement if possible #494

Open
clementval opened this issue Dec 21, 2018 · 0 comments
Open

Comments

@clementval
Copy link
Collaborator

In the code snippet below, the condition should be outside of the kernel to have a more efficient code. In such case, it is easy to detect that the condition is independent from the computation of the kernel and can wrap the kernel instead of being part of it.

Original code

PURE ELEMENTAL SUBROUTINE calc_smth(ll, smth)
  LOGICAL, INTENT(IN) :: ll
  !$claw model-data
  REAL, INTENT(INOUT) :: smth
  !$claw end model-data

  !$claw sca

  IF(ll) THEN
    smth = 0.1
  END IF
END SUBROUTINE calc_smth

Transformation code

SUBROUTINE calc_smth ( ll , smth , nproma )
  INTEGER , INTENT(IN) :: nproma

  LOGICAL , INTENT(IN) :: ll
  REAL , INTENT(INOUT) :: smth ( 1 : nproma )
  INTEGER :: proma

  !$acc data present(smth)
  !$acc parallel
  !$acc loop gang vector
  DO proma = 1 , nproma , 1
   IF ( ll ) THEN
    smth ( proma ) = 0.1
   END IF
  END DO
  !$acc end parallel
  !$acc end data
END SUBROUTINE calc_smth

Expected code

SUBROUTINE calc_smth ( ll , smth , nproma )
  INTEGER , INTENT(IN) :: nproma

  LOGICAL , INTENT(IN) :: ll
  REAL , INTENT(INOUT) :: smth ( 1 : nproma )
  INTEGER :: proma


  IF ( ll ) THEN
    !$acc data present(smth)
    !$acc parallel
    !$acc loop gang vector
    DO proma = 1 , nproma , 1
      smth ( proma ) = 0.1
    END DO
    !$acc end parallel
    !$acc end data
  END IF

END SUBROUTINE calc_smth

Execution of clawfc

clawfc --target=gpu --directive=acc -o transformed_code_acc.f90 mo_column.f90

Related issues (if any)

None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant