Skip to content

Commit

Permalink
Add a tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang committed Sep 21, 2024
1 parent 8c6307a commit 113d2d9
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/workflows/clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,22 @@ jobs:
cd ../GPU
make -j4 USE_CPU=TRUE COMP=clang
./main.llvm.ex
Tutorials:
name: Clang libamrexpr
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Dependencies
run: |
.github/workflows/dependencies/dependencies_clang.sh
- name: Build libamrexpr
run: |
./configure --comp llvm
make -j4
make install
- name: Run
run: |
cd Tutorials/libamrexpr
make -j4 CXX=clang++
./a.out
19 changes: 19 additions & 0 deletions .github/workflows/gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,22 @@ jobs:
cd ../GPU
make -j4 USE_CPU=TRUE
./main.gnu.ex
Tutorials:
name: Clang libamrexpr
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Dependencies
run: |
.github/workflows/dependencies/dependencies_gcc.sh
- name: Build libamrexpr
run: |
./configure --comp gnu
make -j4
make install
- name: Run
run: |
cd Tutorials/libamrexpr
make -j4 CXX=g++
./a.out
25 changes: 25 additions & 0 deletions .github/workflows/intel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,28 @@ jobs:
cd ../GPU
make -j4 USE_CPU=TRUE COMP=intel
./main.intel.ex
Tutorials:
name: Clang libamrexpr
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Dependencies
run: |
.github/workflows/dependencies/dependencies_dpcpp.sh
- name: Build libamrexpr
run: |
set +e
source /opt/intel/oneapi/setvars.sh
set -e
./configure --comp intel
make -j4
make install
- name: Run
run: |
set +e
source /opt/intel/oneapi/setvars.sh
set -e
cd Tutorials/libamrexpr
make -j4 CXX=icpx
./a.out
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ the constants set by `setConstant` and the variables registered by

## Installation

There two ways to install amrexpr.
There two ways to install `amrexpr`. A simple example demonstrating the use
of `libamrexpr` is available at `amrexpr/Tutorials/libamrexpr`.

### Option 1: Using GNU Make

Expand Down
17 changes: 17 additions & 0 deletions Tutorials/libamrexpr/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
AMREXPR_ROOT = ../../tmp_install_dir

CXX = g++
CXXFLAGS = -std=c++17 -O3 -g1 -I$(AMREXPR_ROOT)/include

default: a.out

a.out: main.o
$(CXX) $(CXXFLAGS) $^ -L$(AMREXPR_ROOT)/lib -lamrexpr

main.o: main.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<

.PHONY: clean

clean:
$(RM) main.o a.out
16 changes: 16 additions & 0 deletions Tutorials/libamrexpr/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "amrexpr.hpp"
#include <iostream>

int main (int argc, char* argv[])
{
amrexpr::Parser parser("a*x + b*y");
parser.setConstant("a", 4.0);
parser.setConstant("b", 2.0);
parser.registerVariables({"x","y"});
auto f = parser.compile<2>(); // 2: two variables
double x = 10.0;
double y = 1.0;
double result = f(x,y);
std::cout << "f(x,y) = " << parser.expr() << "\n"
<< "f(" << x << "," << y << ") = " << result << "\n";
}

0 comments on commit 113d2d9

Please sign in to comment.