Skip to content

Commit

Permalink
complete initial nimble support
Browse files Browse the repository at this point in the history
  • Loading branch information
jxy committed Jun 1, 2017
1 parent 02e30c4 commit 5ee5f58
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 33 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*~
*~
/bin/
nimcache/
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,22 @@ Then run it
```
./bin/testStagProp
```

### Using nimble (new)

Copy the file `qex.nimble` to your build directory, and edit the file.

Run `nimble tasks` for available tasks, and `nimble help` for help building your executables.

```
To build nim files:
nimble make [debug] [FlagsToNim] [Name=Definition] Target [MoreTargets]
`debug' will make debug build.
`Target' can be any file name, optionally with partial directory names.
The produced executables will be under `bin/'.
Examples:
nimble make debug test0
nimble make example/testStagProp
```
118 changes: 90 additions & 28 deletions qex.nimble
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
######################################################################
# Configurations
# Comment starts with `#'
# Extra quotes may be required for nimble doesn't quote properly.
const
# Extra quotes may be required for nimble doesn't quote properly.
primmeDir {.strdefine.} = "$HOME/pkg/src/primme"
#primmeDir {.strdefine.} = "$HOME/pkgs/src/primme"
qexDir {.strdefine.} = "."
qmpDir {.strdefine.} = "$HOME/pkg/qmp"
qioDir {.strdefine.} = "$HOME/pkg/qio"
#qmpDir {.strdefine.} = "$HOME/lqcd/install/qmp"
#qioDir {.strdefine.} = "$HOME/lqcd/install/qio"
qudaDir {.strdefine.} = "$HOME/lqcdM/build/quda"
cudaLibDir {.strdefine.} = "/usr/local/cuda/lib64"
lapackLib {.strdefine.} = "'-Wl,-framework -Wl,Accelerate'"
#lapackLib {.strdefine.} = "'$HOME/pkg/lib/libopenblas.a -fopenmp -lm -lgfortran'"
qexDir = "../qex" # Path to qex source directory
extraSrcDir = @["."] # Extra paths to search for build targets.
#primmeDir = "$HOME/pkg/src/primme"
primmeDir = "$HOME/pkgs/src/primme"
#qmpDir = "$HOME/pkg/qmp"
#qioDir = "$HOME/pkg/qio"
qmpDir = "$HOME/lqcd/install/qmp"
qioDir = "$HOME/lqcd/install/qio"
qudaDir = "$HOME/lqcdM/build/quda"
cudaLibDir = "/usr/local/cuda/lib64"
#lapackLib = "'-Wl,-framework -Wl,Accelerate'"
lapackLib = "'$HOME/pkg/lib/libopenblas.a -fopenmp -lm -lgfortran'"
ccType = "gcc"
cc = "mpicc"
cflagsAlways = "'-Wall -std=gnu99 -march=native -ldl -Wa,-q'"
Expand All @@ -25,25 +28,25 @@ const
verbosity = 1
simd = "SSE AVX"
vlen = "8"
# End of configurations
######################################################################

import ospaths, sequtils, strutils

# Package

version = "0.0.0"
author = "James C. Osborn"
description = "Quantum EXpressions lattice field theory framework"
license = "MIT"
srcDir = "src"
srcDir = qexDir/"src"

# Dependencies

requires "nim >= 0.16.0"
when declared(primmeDir):
requires "primme >= 0.0.0"

const paths = @["src", "tests"]

import ospaths, sequtils, strutils

type NamePath = tuple[n,p:string]
proc targets(p:string):seq[NamePath] =
p.listFiles.filterIt(it.splitFile.ext==".nim").mapIt((it.splitFile.name,it))
Expand All @@ -52,8 +55,23 @@ proc recTargets(p:string):seq[NamePath] = p.targets & p.listDirs.recTargets
proc recTargets(ps:seq[string]):seq[NamePath] =
result = @[]
for p in ps: result &= p.recTargets
let cmd = getCommand()
echo cmd
proc findTarget(ts:seq[NamePath], t:string):NamePath =
var i = 0
let tp = t.splitPath
if tp.head.len == 0:
let n = t.splitFile.name
while i < ts.len:
if ts[i].n == n: break
inc i
else:
while i < ts.len:
if t.endsWith(".nim") and ts[i].p.endsWith(t): break
if ts[i].p.endsWith(t&".nim"): break
inc i
if i < ts.len: return ts[i]
else:
echo "Error: cannot find target: `", t, "'"
quit QuitFailure

template set(k:string, v:untyped) =
when compiles(type(v)):
Expand All @@ -69,9 +87,8 @@ template set(k:string, v:untyped) =
template `~`(k,v:untyped) = astToStr(k).set v
template `!`(k,v:untyped) = (ccType&"."&astToStr(k)).set v
template def(v:untyped) = define ~ (astToStr(v)&"="&v)
template define(v:untyped) = define ~ v

path ~ src
path ~ srcDir
cc ~ ccType
exe ! cc
linkerexe ! ld
Expand All @@ -91,18 +108,43 @@ verbosity ~ verbosity
nimcache ~ nimcache
warning[SmallLshouldNotBeUsed] ~ off

for s in simd.split(" "): define ~ s

when declared(primmeDir):
def primmeDir
def lapackLib

task make, "compile and link":
task make, "compile, link, and put executables in `bin'":
const c = paramCount()
when c > 2:
for i in 2..c:
exec("nimble make "&paramStr(i))
var debug = false
var
ts = newseq[string]()
args = newseq[string]()
defs = newseq[string]()
for i in 1..c:
let pi = paramStr i
if pi[0] == '-': args.add pi
elif ts.len == 0 and pi == "make": continue
elif pi == "debug": debug = true
elif '=' in pi: defs.add pi
else: ts.add pi
if ts.len == 0:
exec(paramStr(0)&" help")
elif ts.len > 1:
for i in 0..<ts.len:
exec(paramStr(0)&" make "&args.join(" ")&" "&ts[i]&" "&defs.join(" "))
else:
for s in simd.split(" "): define s
when declared(debug):
let (name,target) = (extraSrcDir&qexDir).recTargets.findTarget ts[0]
for d in defs: define ~ d
for a in args:
var i = 0
while a[i] == '-': inc i
var j = i
while a[j] != ':': inc j
a[i..<j].switch a[j+1..<a.len]
if not dirExists("bin"): mkDir"bin"
"out".set("bin/"&name)
if debug:
echo "debug build"
else:
define ~ release
Expand All @@ -118,4 +160,24 @@ task make, "compile and link":
line_dir ~ off
dead_code_elim ~ on
opt ~ speed
setCommand("c",paramStr(2))
setCommand "c", target

task targets, "List available targets":
let ts = (extraSrcDir&qexDir).recTargets
for t in ts: echo t.n,spaces(32-t.n.len),"\t",t.p

task help, "print out usage information":
echo "----------------------------------------------------------------------"
echo "To build nim files:"
echo " nimble make [debug] [FlagsToNim] [Name=Definition] Target [MoreTargets]"
echo ""
echo "`debug' will make debug build."
echo "`Target' can be any file name, optionally with partial directory names."
echo "The produced executables will be under `bin/'."
echo ""
echo "Examples:"
echo " nimble make debug test0"
echo " nimble make example/testStagProp"

task clean, "remove temporary build files":
rmDir "nimcache"
8 changes: 4 additions & 4 deletions src/eigens/lapack.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const hdr = currentSourcePath()[0..^11] & "lapack.h"
const llapack {.strdefine.} = "-llapack"
#const llapack {.strdefine.} = "/usr/lib/lapack/liblapack.a -lblas -lgfortran"
#const llapack {.strdefine.} = "-L/usr/lib/lapack -llapack"
{.passL: llapack.}
const lapackLib {.strdefine.} = "-llapack"
#const lapackLib {.strdefine.} = "/usr/lib/lapack/liblapack.a -lblas -lgfortran"
#const lapackLib {.strdefine.} = "-L/usr/lib/lapack -llapack"
{.passL: lapackLib.}
{.pragma: lapack, header: hdr.}

type
Expand Down

0 comments on commit 5ee5f58

Please sign in to comment.