Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pypocketfft
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
4
Issues
4
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Martin Reinecke
pypocketfft
Commits
5eb570e0
Commit
5eb570e0
authored
Jun 20, 2019
by
Martin Reinecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make caching thread-safe
parent
d3d3204c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
11 deletions
+25
-11
pocketfft_hdronly.h
pocketfft_hdronly.h
+25
-11
No files found.
pocketfft_hdronly.h
View file @
5eb570e0
...
...
@@ -48,6 +48,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <memory>
#include <vector>
#include <complex>
#include <mutex>
#ifdef POCKETFFT_OPENMP
#include <omp.h>
#endif
...
...
@@ -2205,18 +2206,31 @@ template<typename T> shared_ptr<T> get_plan(size_t length)
constexpr
size_t
nmax
=
10
;
static
vector
<
shared_ptr
<
T
>>
cache
(
nmax
);
static
size_t
lastpos
=
0
;
// searching phase
size_t
pos
=
lastpos
;
do
{
if
(
!
cache
[
pos
])
break
;
if
(
cache
[
pos
]
->
length
()
==
length
)
return
cache
[
pos
];
pos
=
(
pos
==
0
)
?
nmax
-
1
:
pos
-
1
;
}
while
(
pos
!=
lastpos
);
// adding phase
static
mutex
mut
;
{
lock_guard
<
mutex
>
lock
(
mut
);
for
(
size_t
i
=
0
;
i
<
nmax
;
++
i
)
{
if
(
cache
[
i
]
==
nullptr
)
break
;
if
(
cache
[
i
]
->
length
()
==
length
)
return
cache
[
i
];
}
}
auto
plan
=
make_shared
<
T
>
(
length
);
{
lock_guard
<
mutex
>
lock
(
mut
);
for
(
size_t
i
=
0
;
i
<
nmax
;
++
i
)
{
if
(
cache
[
i
]
==
nullptr
)
break
;
if
(
cache
[
i
]
->
length
()
==
length
)
return
cache
[
i
];
}
cache
[
lastpos
]
=
plan
;
if
(
++
lastpos
>=
nmax
)
lastpos
=
0
;
cache
[
lastpos
]
=
make_shared
<
T
>
(
length
);
return
cache
[
lastpos
]
;
}
return
plan
;
}
class
arr_info
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment