From be5bea1f8526e64c87a4f69d17212db694f4372f Mon Sep 17 00:00:00 2001 From: vijay Date: Thu, 15 Oct 2020 07:56:43 +0200 Subject: [PATCH 1/9] Added a delete function to clear the qmckl_context instance. Perhaps we want to organize garbage collection differently !? I thought it's a nice first commit to add a basic delete function to motivate the ways in which instances can be deleted. Obviously this is only a proposal to learn from. Note that no information is being sent (other than the fact that free has been called) about the contents of the _context_ instance after the call to the function. --- src/qmckl_context.org | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/qmckl_context.org b/src/qmckl_context.org index 1aba050..f2f8951 100644 --- a/src/qmckl_context.org +++ b/src/qmckl_context.org @@ -90,6 +90,27 @@ qmckl_context qmckl_context_copy(qmckl_context context) { } #+END_SRC +** =qmckl_context_delete= + + To delete a new context, use =qmckl_context_delete()=. If the deletion + failed, the function returns =0=. On success, the function returns =1= + implying that the context has been freed. + + #+BEGIN_SRC C :tangle qmckl_context.h +qmckl_context qmckl_context_delete(qmckl_context context); + #+END_SRC + + #+BEGIN_SRC C :tangle qmckl_context.c +qmckl_context qmckl_context_delete(qmckl_context context) { + + if (context == NULL) { + return (qmckl_context) 0; + } + + free(context); + return (qmckl_context) 1; +} + #+END_SRC * Precision From e08d8d3d511f4f6d0d2e66a4d18933a31121cfae Mon Sep 17 00:00:00 2001 From: Pablo Oliveira Date: Thu, 15 Oct 2020 08:57:01 +0200 Subject: [PATCH 2/9] Remove trailing whitespace --- src/qmckl_context.org | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qmckl_context.org b/src/qmckl_context.org index 1aba050..2a4844b 100644 --- a/src/qmckl_context.org +++ b/src/qmckl_context.org @@ -1,6 +1,6 @@ # -*- mode: org -*- -#+TITLE: Context +#+TITLE: Context This file is written in C because it is more natural to express the context in C than in Fortran. @@ -17,7 +17,7 @@ C than in Fortran. is stored in the following data structure, which can't be seen outside of the library. - + #+BEGIN_SRC C :tangle qmckl_context.h #define QMCKL_DEFAULT_PRECISION 53 #define QMCKL_DEFAULT_RANGE 2 From a3d8b6f402baba5c02bd83b10a8feaa208cb18f7 Mon Sep 17 00:00:00 2001 From: vijay Date: Thu, 15 Oct 2020 09:00:22 +0200 Subject: [PATCH 3/9] Changed to _qmckl_context_destroy_ to be consistent ZMQ Changed _qmckl_context_destroy_ to be consistent ZMQ and other similar libraries. --- src/qmckl_context.org | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qmckl_context.org b/src/qmckl_context.org index f2f8951..0d7be0d 100644 --- a/src/qmckl_context.org +++ b/src/qmckl_context.org @@ -90,18 +90,18 @@ qmckl_context qmckl_context_copy(qmckl_context context) { } #+END_SRC -** =qmckl_context_delete= +** =qmckl_context_destroy= - To delete a new context, use =qmckl_context_delete()=. If the deletion + To delete a new context, use =qmckl_context_destroy()=. If the deletion failed, the function returns =0=. On success, the function returns =1= implying that the context has been freed. #+BEGIN_SRC C :tangle qmckl_context.h -qmckl_context qmckl_context_delete(qmckl_context context); +qmckl_context qmckl_context_destroy(qmckl_context context); #+END_SRC #+BEGIN_SRC C :tangle qmckl_context.c -qmckl_context qmckl_context_delete(qmckl_context context) { +qmckl_context qmckl_context_destroy(qmckl_context context) { if (context == NULL) { return (qmckl_context) 0; From 739d0dba3c72243eb84bcc4ce65fd388599d4b92 Mon Sep 17 00:00:00 2001 From: Pablo Oliveira Date: Thu, 15 Oct 2020 09:22:24 +0200 Subject: [PATCH 4/9] Add const qualifier since context is immutable --- src/qmckl_context.org | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/qmckl_context.org b/src/qmckl_context.org index 2a4844b..5d1f510 100644 --- a/src/qmckl_context.org +++ b/src/qmckl_context.org @@ -66,11 +66,11 @@ qmckl_context qmckl_context_create() { ** =qmckl_context_copy= #+BEGIN_SRC C :tangle qmckl_context.h -qmckl_context qmckl_context_copy(qmckl_context context); +qmckl_context qmckl_context_copy(const qmckl_context context); #+END_SRC #+BEGIN_SRC C :tangle qmckl_context.c -qmckl_context qmckl_context_copy(qmckl_context context) { +qmckl_context qmckl_context_copy(const qmckl_context context) { qmckl_context_struct* old_context; qmckl_context_struct* new_context; @@ -102,11 +102,11 @@ qmckl_context qmckl_context_copy(qmckl_context context) { ** =qmckl_context_set_precision= #+BEGIN_SRC C :tangle qmckl_context.h -qmckl_context qmckl_context_set_precision(qmckl_context context, int precision); +qmckl_context qmckl_context_set_precision(const qmckl_context context, int precision); #+END_SRC #+BEGIN_SRC C :tangle qmckl_context.c -qmckl_context qmckl_context_set_precision(qmckl_context context, int precision) { +qmckl_context qmckl_context_set_precision(const qmckl_context context, int precision) { qmckl_context_struct* ctx; if (precision < 2) return (qmckl_context) 0; @@ -120,11 +120,11 @@ qmckl_context qmckl_context_set_precision(qmckl_context context, int precision) ** =qmckl_context_set_range= #+BEGIN_SRC C :tangle qmckl_context.h -qmckl_context qmckl_context_set_range(qmckl_context context, int range); +qmckl_context qmckl_context_set_range(const qmckl_context context, int range); #+END_SRC #+BEGIN_SRC C :tangle qmckl_context.c -qmckl_context qmckl_context_set_range(qmckl_context context, int range) { +qmckl_context qmckl_context_set_range(const qmckl_context context, int range) { qmckl_context_struct* ctx; if (range < 2) return (qmckl_context) 0; @@ -141,11 +141,11 @@ qmckl_context qmckl_context_set_range(qmckl_context context, int range) { ** =qmckl_context_get_precision= #+BEGIN_SRC C :tangle qmckl_context.h -int qmckl_context_get_precision(qmckl_context context); +int qmckl_context_get_precision(const qmckl_context context); #+END_SRC #+BEGIN_SRC C :tangle qmckl_context.c -int qmckl_context_get_precision(qmckl_context context) { +int qmckl_context_get_precision(const qmckl_context context) { qmckl_context_struct* ctx; ctx = (qmckl_context_struct*) context; return ctx->precision; @@ -155,11 +155,11 @@ int qmckl_context_get_precision(qmckl_context context) { ** =qmckl_context_get_range= #+BEGIN_SRC C :tangle qmckl_context.h -int qmckl_context_get_range(qmckl_context context); +int qmckl_context_get_range(const qmckl_context context); #+END_SRC #+BEGIN_SRC C :tangle qmckl_context.c -int qmckl_context_get_range(qmckl_context context) { +int qmckl_context_get_range(const qmckl_context context) { qmckl_context_struct* ctx; ctx = (qmckl_context_struct*) context; return ctx->range; From a65d4b364839c3dd2a2f0daef80952518e15479c Mon Sep 17 00:00:00 2001 From: Pablo Oliveira Date: Thu, 15 Oct 2020 09:41:26 +0200 Subject: [PATCH 5/9] Fix Makefile --- src/Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Makefile b/src/Makefile index cd61181..293255a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,17 +4,20 @@ CFLAGS= FC=gfortran FFLAGS= -SOURCE_FILES=$(wildcard *.org) +ORG_SOURCE_FILES=qmckl_context.org +OBJECT_FILES=$(patsubst %.org,%.o,$(ORG_SOURCE_FILES)) .PHONY: clean +all: $(OBJECT_FILES) + %.c %.h: %.org emacs --quick --no-init-file --batch --eval "(require 'org)" --eval '(org-babel-tangle-file "$^")' %.c %.h %_f.f90: %.org emacs --quick --no-init-file --batch --eval "(require 'org)" --eval '(org-babel-tangle-file "$^")' -%.o: %.c +%.o: %.c $(CC) $(CFLAGS) -c $*.c -o $*.o %.o: %.f90 From 42637b4e18ac5f48fce1737149c55f6a931060a2 Mon Sep 17 00:00:00 2001 From: Pablo Oliveira Date: Thu, 15 Oct 2020 10:14:05 +0200 Subject: [PATCH 6/9] Add a github action to test build automatically --- .github/workflows/test-build.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/test-build.yml diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml new file mode 100644 index 0000000..f6baeb5 --- /dev/null +++ b/.github/workflows/test-build.yml @@ -0,0 +1,17 @@ +name: test-build + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: make + run: make -C src/ From df8714f1db8b70e85784c9c2783a6c2a34e6b172 Mon Sep 17 00:00:00 2001 From: Pablo Oliveira Date: Thu, 15 Oct 2020 10:19:17 +0200 Subject: [PATCH 7/9] Add build success status badge to README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7cafb1a..f0902ec 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # qmckl + +[![Build Status](https://github.com/TREX-CoE/qmckl/workflows/test-build/badge.svg?branch=main) + Quantum Monte Carlo Kernel Library. See the [Wiki](https://github.com/TREX-CoE/qmckl/wiki) for more information. From 3be637dcc212ada38b6e68e21a37eca6ad27f364 Mon Sep 17 00:00:00 2001 From: Pablo de Oliveira Castro Date: Thu, 15 Oct 2020 12:17:20 +0200 Subject: [PATCH 8/9] Fix CI dependencies: must install emacs to untangle org files (#5) --- .github/workflows/test-build.yml | 2 ++ README.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index f6baeb5..7d22a09 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -13,5 +13,7 @@ jobs: steps: - uses: actions/checkout@v2 + - name: install dependencies + run: sudo apt-get install emacs - name: make run: make -C src/ diff --git a/README.md b/README.md index f0902ec..7d64383 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # qmckl -[![Build Status](https://github.com/TREX-CoE/qmckl/workflows/test-build/badge.svg?branch=main) +![Build Status](https://github.com/TREX-CoE/qmckl/workflows/test-build/badge.svg?branch=main) Quantum Monte Carlo Kernel Library. From 32d633bfb6dc8dc7f7be791931285417aab8c99a Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 15 Oct 2020 12:36:52 +0200 Subject: [PATCH 9/9] Fixed type in free --- TODO.org | 12 ++++++++++++ src/Makefile | 5 +++-- src/qmckl_context.org | 16 ++++++++++------ 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 TODO.org diff --git a/TODO.org b/TODO.org new file mode 100644 index 0000000..2d5626b --- /dev/null +++ b/TODO.org @@ -0,0 +1,12 @@ +* Set up CI on Travis +* Write tests + +* malloc/free : Parameters for accelerators? +We should define qmckl_malloc and qmckl_free just to give the +possibility of the HPC implementations to define how they allocate the +memory (on CPU or GPU, using alternatives to malloc/free, etc). +A possibility could be to pass the id of a NUMA domain as a parameter of +qmckl_malloc, where the domain id is something obtained from the +context. + + diff --git a/src/Makefile b/src/Makefile index 293255a..9255ca0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,8 +1,9 @@ CC=gcc -CFLAGS= +CFLAGS=-fexceptions -Wall -Werror -Wpedantic -Wextra FC=gfortran -FFLAGS= +FFLAGS=-fcheck=all -Waliasing -Wampersand -Wconversion -Wsurprising -Wintrinsics-std -Wno-tabs -Wintrinsic-shadow -Wline-truncation -Wreal-q-constant -Wuninitialized -fbacktrace -ffpe-trap=zero,overflow,underflow -finit-real=nan + ORG_SOURCE_FILES=qmckl_context.org OBJECT_FILES=$(patsubst %.org,%.o,$(ORG_SOURCE_FILES)) diff --git a/src/qmckl_context.org b/src/qmckl_context.org index b24f7f0..255b2dc 100644 --- a/src/qmckl_context.org +++ b/src/qmckl_context.org @@ -97,18 +97,22 @@ qmckl_context qmckl_context_copy(const qmckl_context context) { implying that the context has been freed. #+BEGIN_SRC C :tangle qmckl_context.h -qmckl_context qmckl_context_destroy(qmckl_context context); +int qmckl_context_destroy(qmckl_context context); #+END_SRC #+BEGIN_SRC C :tangle qmckl_context.c -qmckl_context qmckl_context_destroy(qmckl_context context) { +int qmckl_context_destroy(qmckl_context context) { - if (context == NULL) { - return (qmckl_context) 0; + qmckl_context_struct* ctx; + + ctx = (qmckl_context_struct*) context; + + if (ctx == NULL) { + return 0; } - free(context); - return (qmckl_context) 1; + free(ctx); + return 1; } #+END_SRC