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

timelockanalysis: use parfor instead of for #2068

Merged
merged 3 commits into from Sep 22, 2022

Conversation

AljenU
Copy link

@AljenU AljenU commented Jul 1, 2022

With some small adaptations, it is possible to use a parfor loop in
ft_timelockanalysis. This potentially speeds up the calculation, when the
parallel computing toolbox is available.

Tested with https://github.com/AljenU/fieldtrip-parallel-support/tree/additional_tests, however no tests were found that take more than a few seconds on ft_timelockanalysis, making it hard to actually compare performance.

@AljenU
Copy link
Author

AljenU commented Jul 11, 2022

I am looking at a way where, for ~keeptrials, the size of covsig can stay at [nchan, nchan], instead of using [nrpt, nchan, nchan]. I found it is possible. For clarity, it should use a small helper function that contains the first half of the parfor loop, that calculates dat and numsmp.
EDIT: This has been added in the third commit in this branch.

OLD: Due to how fieldtrip does the preamble, it cannot be a nested function nor a subfuction, but needs to be in its own file.
Where to put such a file, for what i have now called ft_timelockanalysis_covdat() ?
FOLLOW UP on OLD: Using a subfunction is possible, the problem I experienced had to do with what path was set on the parallel workers. When using matlab Parallel Computing Toolbox, the parpool should only be started when all fieldtrip folders have been added to the path, i.e. when ft_defaults has been called at least once.

With some small adaptations, it is possible to use a parfor loop in
ft_timelockanalysis. This potentially speeds up the calculation, when the
parallel computing toolbox is available.
Setting this limit to 0 will make the execution non-parallel
For the not-keeptrials case, it is possible to use less memory, by adding results
within the loop. This was done with the regular for loop. Rework the parfor
implementation to also do the reduction within the loop. Does require having two
implementations of the parfor loop, because variables need to always be assigned to
in the same way within a single parfor loop.
@AljenU AljenU changed the base branch from master to parallel September 22, 2022 07:53
@robertoostenveld robertoostenveld merged commit b20f50a into fieldtrip:parallel Sep 22, 2022
@robertoostenveld robertoostenveld moved this from In progress to Done in FieldTrip performance improvements Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants