Merge lp:~albertog/siesta/4.0-pool into lp:siesta/4.0

Proposed by Alberto Garcia
Status: Merged
Merged at revision: 593
Proposed branch: lp:~albertog/siesta/4.0-pool
Merge into: lp:siesta/4.0
Diff against target: 109 lines (+47/-10) (has conflicts)
2 files modified
Src/matel_registry.F90 (+42/-10)
version.info (+5/-0)
Text conflict in version.info
To merge this branch: bzr merge lp:~albertog/siesta/4.0-pool
Reviewer Review Type Date Requested Status
Nick Papior Approve
Review via email: mp+364488@code.launchpad.net

Description of the change

Make radial function pool dynamically extensible.

To post a comment you must log in.
Revision history for this message
Nick Papior (nickpapior) wrote :

Nice! Great job!

LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Src/matel_registry.F90'
2--- Src/matel_registry.F90 2016-01-25 16:00:16 +0000
3+++ Src/matel_registry.F90 2019-03-15 09:23:30 +0000
4@@ -8,7 +8,7 @@
5 module m_matel_registry
6 !
7 ! This module provides a general interface to the
8- ! functions needed by matel
9+ ! functions needed by (new_)matel
10 !
11 ! Sketch of usage (see examples in the code):
12 !
13@@ -20,7 +20,7 @@
14 !
15 ! Once registered, a function can be evaluated, its cutoff and
16 ! angular momentum obtained, etc. So far only the functions
17- ! needed by matel are implemented: rcut, lcut, evaluate (former phiatm).
18+ ! needed by (new_)matel are implemented: rcut, lcut, evaluate (former phiatm).
19 !
20 ! The registry contains some meta-data for each function (its
21 ! kind as a string, and the original indexes handled by the
22@@ -71,13 +71,13 @@
23 integer :: lcut = -huge(1)
24 end type registered_function_t
25 !
26- ! There should be a mechanism to make the size
27- ! of the pool dynamic.
28- !
29- integer, parameter :: nmax_funcs = 300
30- type(registered_function_t), dimension(nmax_funcs), save :: matel_pool
31+ ! This is a dynamic array, allocated and extended as needed.
32+ type(registered_function_t), dimension(:), allocatable, save :: matel_pool
33
34- integer, private :: nfuncs = 0
35+ integer, parameter :: initial_size = 100 ! initial size of pool
36+ integer, parameter :: delta_size = 50 ! chunk size for extensions
37+ integer, private :: nmax_funcs = 0 ! current maximum size of the pool
38+ integer, private :: nfuncs = 0 ! number of functions in pool
39
40 public :: register_in_rf_pool, register_in_tf_pool
41 public :: evaluate, rcut, lcut
42@@ -93,6 +93,36 @@
43 ok = (gindex > 0 .AND. gindex <= nfuncs)
44 end function valid
45
46+ !> Extends the size of the pool if needed
47+ subroutine check_size_of_pool(nfuncs)
48+ integer, intent(in) :: nfuncs
49+
50+ type(registered_function_t), dimension(:), allocatable :: tmp_pool
51+
52+ if (nfuncs > nmax_funcs) then
53+ if (.not. allocated(matel_pool)) then
54+ allocate(matel_pool(initial_size))
55+ nmax_funcs = initial_size
56+ else
57+ ! copy data to tmp array
58+ allocate(tmp_pool(nmax_funcs))
59+
60+ ! Each element (derived type) involves just two scalars
61+ ! and two pointers, so the copy overhead is small.
62+ ! Note that we do not use the F2003 "move_alloc" idiom.
63+
64+ tmp_pool(1:nmax_funcs) = matel_pool(1:nmax_funcs)
65+ deallocate(matel_pool)
66+ allocate(matel_pool(nmax_funcs + delta_size))
67+ matel_pool(1:nmax_funcs) = tmp_pool(1:nmax_funcs)
68+ nmax_funcs = nmax_funcs + delta_size
69+
70+ deallocate(tmp_pool)
71+
72+ endif
73+ endif
74+ end subroutine check_size_of_pool
75+
76 !
77 ! This is the main entry to the registry for simple radial functions
78 !
79@@ -109,7 +139,8 @@
80 n_indexes = size(indexes)
81
82 nfuncs = nfuncs + 1
83- if (nfuncs > nmax_funcs) call die("Overflow in registry")
84+ call check_size_of_pool(nfuncs)
85+
86 gindex = nfuncs
87
88 allocate(matel_pool(gindex)%rf)
89@@ -139,7 +170,8 @@
90 integer, intent(out) :: gindex ! global index
91
92 nfuncs = nfuncs + 1
93- if (nfuncs > nmax_funcs) call die("Overflow in registry")
94+ call check_size_of_pool(nfuncs)
95+
96 gindex = nfuncs
97
98 allocate(matel_pool(gindex)%tf)
99
100=== modified file 'version.info'
101--- version.info 2019-02-20 19:40:46 +0000
102+++ version.info 2019-03-15 09:23:30 +0000
103@@ -1,1 +1,6 @@
104+<<<<<<< TREE
105 siesta-4.0--592
106+=======
107+siesta-4.0--591--pool-593
108+
109+>>>>>>> MERGE-SOURCE

Subscribers

People subscribed via source and target branches