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

Nix flake #1093

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ jobs:
retention-days: 5
if-no-files-found: error

build_nix:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
submodules: true
- name: Install Nix
uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
experimental-features = nix-command flakes
- name: BuildVlasiatorNix
run: nix develop --impure --command bash -c " make -j 8 ;"

build_libraries_appleM1:
# Build libraries on macos with M1 hardware, to test both macOS and aarch64 compatibility
runs-on: macos-14
Expand Down
59 changes: 59 additions & 0 deletions MAKE/Makefile.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Generic Makefile used for nix builds

#======== Vectorization ==========
#Set vector backend type for vlasov solvers, sets precision and length.
#NOTE this has to have the same precision as the distribution function define (DISTRIBUTION_FP_PRECISION)
#Options:
# AVX: VEC4D_AGNER, VEC4F_AGNER, VEC8F_AGNER
# AVX512: VEC8D_AGNER, VEC16F_AGNER
# Fallback: VEC4D_FALLBACK, VEC4F_FALLBACK, VEC8F_FALLBACK

ifeq ($(DISTRIBUTION_FP_PRECISION),SPF)
#Single-precision
VECTORCLASS = VEC8F_AGNER
else
#Double-precision
VECTORCLASS = VEC4D_AGNER
endif


#======== Allocator =========
#Use TBB malloc

CMP = mpic++
LNK = mpic++

PAPI_FLAG =

FLAGS =
#CXXFLAGS = -I $(HOME)/include -L $(HOME)/lib -g -funroll-loops -std=c++20 -fopenmp -W -Wall -pedantic -Wno-unused -fabi-version=0 -mavx
CXXFLAGS += -g3 -ggdb -O3 -funroll-loops -std=c++20 -fopenmp -W -Wall -Wno-unused -fabi-version=0 -mfma -mavx2 -Wno-unknown-pragmas -Wno-sign-compare
testpackage: CXXFLAGS = -g -ggdb -O2 -fopenmp -funroll-loops -std=c++20 -fabi-version=0 -mno-avx -mno-fma -fno-unsafe-math-optimizations

MATHFLAGS = -ffast-math -fno-finite-math-only
testpackage: MATHFLAGS = -fno-unsafe-math-optimizations

LDFLAGS =
LIB_MPI = -lgomp -lpapi

#======== PAPI ==========
#Add PAPI_MEM define to use papi to report memory consumption?
CXXFLAGS += -DPAPI_MEM
testpackage: CXXFLAGS += -DPAPI_MEM

#======== Allocator =========
#Use jemalloc instead of system malloc to reduce memory fragmentation? https://github.com/jemalloc/jemalloc
#Configure jemalloc with --with-jemalloc-prefix=je_ when installing it
CXXFLAGS += -DUSE_JEMALLOC -DJEMALLOC_NO_DEMANGLE
testpackage: CXXFLAGS += -DUSE_JEMALLOC -DJEMALLOC_NO_DEMANGLE


# #======== Libraries ===========
LIB_BOOST=-lboost_program_options
LIB_ZOLTAN+=-lzoltan
LIB_VLSV+=-lvlsv
LIB_PAPI+=-lpapi
LIB_JEMALLOC+=-ljemalloc
LIB_PROFILE+= -lphiprof
INC_VECTORCLASS = -isystem ./submodules/vectorclass/ -isystem ./submodules/vectorclass-addon/vector3d/
INC_EIGEN = -isystem ./submodules/eigen/
220 changes: 220 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
{
description = "Vlasiator developement environment";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};

outputs = { self, nixpkgs, ... }@inputs:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
vlsvSrc = builtins.fetchGit {
url = "https://github.com/fmihpc/vlsv";
ref = "master";
};

phiprofSrc = builtins.fetchGit {
url = "https://github.com/fmihpc/phiprof";
ref = "master";
};

zoltanSrc = builtins.fetchGit {
url= "https://github.com/trilinos/Trilinos.git";
ref = "master";
};

papiSrc = builtins.fetchGit {
url = "https://github.com/icl-utk-edu/papi.git";
ref = "master";
};

vlsvPkg = pkgs.stdenv.mkDerivation {
pname = "vlsv";
version = "latest";

src = vlsvSrc;

nativeBuildInputs = [ pkgs.makeWrapper ];
buildInputs = [ pkgs.gcc pkgs.openmpi ];

buildPhase = ''
make -j 4
'';

installPhase = ''
mkdir -p $out/lib
mkdir -p $out/include
cp -r ./* $out/lib/
cp -r ./* $out/include/
'';
};

phiprofPkg = pkgs.stdenv.mkDerivation {
pname = "phiprof";
version = "latest";

src = phiprofSrc;

nativeBuildInputs = [ pkgs.makeWrapper ];
buildInputs = [ pkgs.gcc pkgs.openmpi ];

buildPhase = ''
cd src/
make -j 4
'';

installPhase = ''
cd ..
mkdir -p $out/lib $out/include
cp lib/* $out/lib/
cp include/* $out/include/
'';
};

zoltanPkg = pkgs.stdenv.mkDerivation {
pname = "zoltan";
version = "latest";

src = zoltanSrc;

nativeBuildInputs = [ pkgs.cmake];
buildInputs = [ pkgs.gcc pkgs.openmpi pkgs.perl ];


configurePhase = ''
mkdir zoltan_build
cd zoltan_build
cmake .. -DCMAKE_INSTALL_PREFIX:FILEPATH=$out -DTrilinos_ENABLE_Zoltan:BOOL=ON -DZoltan_ENABLE_ULLONG_IDS:Bool=ON -DTrilinos_ENABLE_ALL_PACKAGES:BOOL=OFF -DTPL_ENABLE_MPI:BOOL=ON
'';

buildPhase = ''
make -j 8
'';

installPhase = ''
make install
'';
};

# Fetch and build jemalloc
jemallocPkg = pkgs.stdenv.mkDerivation {
pname = "jemalloc";
version = "5.3.0";

src = pkgs.fetchurl {
url = "https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2";
sha256 = "sha256-LbgtHnEZ3z5xt2QCGbbf6EeJvAU3mDw7esT3GJrs/qo="; # Update this hash if necessary
};

nativeBuildInputs = [ pkgs.gnumake pkgs.autoconf pkgs.automake pkgs.libtool ];
buildInputs = [ pkgs.gcc ];

configurePhase = ''
tar xf $src
cd jemalloc-5.3.0
./configure --prefix=$out --with-jemalloc-prefix=je_
'';

buildPhase = ''
# cd jemalloc-5.3.0
make -j 8
'';

installPhase = ''
# cd jemalloc-5.3.0
make install
'';
};

papiPkg = pkgs.stdenv.mkDerivation {
pname = "papi";
version = "latest";

src = papiSrc;

nativeBuildInputs = [ pkgs.gnumake pkgs.autoconf pkgs.automake pkgs.libtool ];
buildInputs = [ pkgs.gcc ];

configurePhase = ''
cd src
./configure --prefix=$out
'';

buildPhase = ''
make -j 8
'';

installPhase = ''
make install
'';
};



boostPkg = pkgs.stdenv.mkDerivation {
pname = "boost";
version = "1.72.0";

src = pkgs.fetchurl {
url = "http://freefr.dl.sourceforge.net/project/boost/boost/1.72.0/boost_1_72_0.tar.bz2";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update that to 1.87 or so please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

righto

sha256 = "sha256-WcmydLxFHPkam6HdLH/cr11gsbOqg/LJ+hQ0F8xmByI="; # Update this hash if necessary
};

nativeBuildInputs = [ pkgs.gnumake pkgs.perl pkgs.bash ];
buildInputs = [ pkgs.gcc pkgs.openmpi ];

configurePhase = ''
tar xf $src
cd boost_1_72_0
./bootstrap.sh --with-libraries=program_options
echo "using mpi ;" >> ./tools/build/src/user-config.jam
'';

buildPhase = ''
./b2
'';

installPhase = ''
./b2 --prefix=$out install
'';
};



in
{
devShells.x86_64-linux.default = pkgs.mkShell {
name = "dev-shell";
buildInputs = [
pkgs.git
pkgs.gcc
pkgs.openmpi
vlsvPkg
phiprofPkg
zoltanPkg
jemallocPkg
papiPkg
boostPkg
];
shellHook = ''
export LIB_VLSV=-L${vlsvPkg}/lib
export INC_VLSV=-I${vlsvPkg}/include
export LIB_PROFILE=-L${phiprofPkg}/lib/
export INC_PROFILE=-I${phiprofPkg}/include/
export LIB_ZOLTAN=-L${zoltanPkg}/lib
export INC_ZOLTAN=-I${zoltanPkg}/include
export LIB_JEMALLOC=-L${jemallocPkg}/lib
export INC_JEMALLOC=-I${jemallocPkg}/include
export LIB_PAPI=-L${papiPkg}/lib
export INC_PAPI=-I${papiPkg}/include
export LIB_BOOST=-L${boostPkg}/lib
export INC_BOOST=-I${boostPkg}/include
export VLASIATOR_ARCH=nix
echo "Vlasiator enviroment ready! Use make -j <cores> to build a fresh vlasiator binary!"
'';

};
};
}


1 change: 0 additions & 1 deletion generate_version.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
#
# This file is part of Vlasiator.
# Copyright 2010-2016 Finnish Meteorological Institute
#
Expand Down
Loading