pipeline {
  agent none
  options {
    disableConcurrentBuilds()
    buildDiscarder(logRotator(numToKeepStr: '8', daysToKeepStr: '20'))
  }
  stages {
    stage('ITensorGPU test') {
      parallel {
        stage('julia-1.6') {
	  options {
            timeout(time: 45, unit: 'MINUTES')
          }
          agent {
            dockerfile {
              label 'gpu&&v100'
              filename 'Dockerfile'
              dir 'jenkins'
              additionalBuildArgs  '--build-arg JULIA=1.6'
              args '--gpus "device=0"'
            }
          }
          environment {
            HOME = pwd(tmp:true)
            OMP_NUM_THREADS = 4
            JULIA_NUM_THREADS = 4
          }
          steps {
            sh '''
              julia -e 'using Pkg; Pkg.add(name="NDTensors", version="0.1"); Pkg.develop(path="./ITensorGPU"); Pkg.develop(path="."); Pkg.instantiate(); Pkg.test("ITensorGPU");' 
              '''
            sh '''
              julia --project=NDTensors -e 'using Pkg; Pkg.develop(path=".");Pkg.test(; test_args=["cuda"])'
            '''
          }
        }
        stage('julia-1.8') {
	  options {
            timeout(time: 45, unit: 'MINUTES')
          }
          agent {
            dockerfile {
              label 'gpu&&v100'
              filename 'Dockerfile'
              dir 'jenkins'
              additionalBuildArgs  '--build-arg JULIA=1.8'
              args '--gpus "device=1"'
            }
          }
          environment {
            HOME = pwd(tmp:true)
            OMP_NUM_THREADS = 4
            JULIA_NUM_THREADS = 4
          }
          steps {
            sh '''
              julia -e 'using Pkg; Pkg.add(name="NDTensors", version="0.1"); Pkg.develop(path="./ITensorGPU"); Pkg.develop(path="."); Pkg.instantiate(); Pkg.test("ITensorGPU");' 
            '''
            sh '''
              julia --project=NDTensors -e 'using Pkg; Pkg.develop(path=".");Pkg.test(; test_args=["cuda"])'
            '''
          }
        }
      }
    }
  }
}
