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

Parallelization of Wedge Product #29796

Open
mjungmath opened this issue Jun 4, 2020 · 18 comments
Open

Parallelization of Wedge Product #29796

mjungmath opened this issue Jun 4, 2020 · 18 comments

Comments

@mjungmath
Copy link

Apparently, the wedge product is not performed on multiple cores when parallel computation is enabled. According to the compontent-wise computation of general tensors, I add this feature for the wedge product for alternate forms, too.

CC: @egourgoulhon @tscrim @mkoeppe

Component: geometry

Keywords: differential_forms, parallel

Author: Michael Jung

Branch/Commit: u/gh-mjungmath/wedge_product_parallel @ 6303e7c

Issue created by migration from https://trac.sagemath.org/ticket/29796

@mjungmath mjungmath added this to the sage-9.2 milestone Jun 4, 2020
@mjungmath

This comment has been minimized.

@mjungmath
Copy link
Author

Author: Michael Jung

@mjungmath
Copy link
Author

Changed keywords from none to mixed_forms

@mjungmath

This comment has been minimized.

@mjungmath
Copy link
Author

Changed keywords from mixed_forms to differential_forms, parallel

@mjungmath

This comment has been minimized.

@mjungmath mjungmath changed the title Mixed Forms - Fast zero check Parallelization of Wedge Product Jun 18, 2020
@mjungmath

This comment has been minimized.

@mjungmath
Copy link
Author

@mjungmath
Copy link
Author

Commit: d8ecedc

@mjungmath
Copy link
Author

comment:7

This is my very first approach simply copied from the previous ones. However, I noticed that in lower dimensions, the parallelization is even slower. Furthermore, one could improve this process a little bit further just my considering distinct indices from the beginning (see the check in the loop).

I appreciate any help since I am not familiar with effective parallelization.


New commits:

d8ecedcTrac #29796: first parallelization approach

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 20, 2020

Changed commit from d8ecedc to 6303e7c

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 20, 2020

Branch pushed to git repo; I updated commit sha1. New commits:

0961bdcTrac #29796: further small improvements
6303e7cTrac #29796: indentation fixed

@mjungmath
Copy link
Author

comment:9

Some computations in 4 dimensions made it slightly worse: from around 8 sec to 15 sec. In contrast, more complicated computations in 6 dimensions yield a good improvement.

However, I noticed that the cpus are not fully engaged and run around 20-80% workload, varying all the time. Hence, there is much room for improvement.

I appreciate any suggestions. I feel a little bit lost here.


New commits:

0961bdcTrac #29796: further small improvements
6303e7cTrac #29796: indentation fixed

@egourgoulhon
Copy link
Member

comment:10

Replying to @mjungmath:

Some computations in 4 dimensions made it slightly worse: from around 8 sec to 15 sec. In contrast, more complicated computations in 6 dimensions yield a good improvement.

However, I noticed that the cpus are not fully engaged and run around 20-80% workload, varying all the time. Hence, there is much room for improvement.

I appreciate any suggestions. I feel a little bit lost here.

I would say that the behaviour that you observe is due to the computation being not fully parallelized in the current code. Indeed, in the final lines

            for ii, val in paral_wedge(listParalInput):
                 for jj in val:
                     cmp_r[[jj[0]]] += jj[1]

the computation cmp_r[[jj[0]]] += jj[1] is performed sequentially.

@mjungmath
Copy link
Author

comment:11

Interestingly, I dropped the summation completely, and still, the computation takes longer than without parallelization. This is odd, isn't it?

Even this modification doesn't improve anything:

        ind_list = [(ind_s, ind_o) for ind_s in cmp_s._comp
                                   for ind_o in cmp_o._comp
                    if len(ind_s+ind_o) == len(set(ind_s+ind_o))]
        nproc = Parallelism().get('tensor')
        if nproc != 1:
            # Parallel computation
            lol = lambda lst, sz: [lst[i:i + sz] for i in
                                   range(0, len(lst), sz)]
            ind_step = max(1, int(len(ind_list) / nproc))
            local_list = lol(ind_list, ind_step)
            # list of input parameters:
            listParalInput = [(cmp_s, cmp_o, ind_part) for ind_part in
                              local_list]

            @parallel(p_iter='multiprocessing', ncpus=nproc)
            def paral_wedge(s, o, local_list_ind):
                partial = []
                for ind_s, ind_o in local_list_ind:
                    ind_r = ind_s + ind_o
                    partial.append([ind_r, s._comp[ind_s] * o._comp[ind_o]])
                return partial
            for ii, val in paral_wedge(listParalInput):
                for jj in val:
                    cmp_r[[jj[0]]] = jj[1]
        else:
            # Sequential computation
            for ind_s, ind_o in ind_list:
                ind_r = ind_s + ind_o
                cmp_r[[ind_r]] += cmp_s._comp[ind_s] * cmp_o._comp[ind_o]

If nproc is set to 1, the original speed is preserved.

I am fully aware that this leads to wrong results and the summation should be covered within the parallelization, somehow. Nevertheless, this seems strange to me.

@mjungmath
Copy link
Author

comment:12

Besides this odd fact, do you have any ideas how the summation can be parallelized, too?

@mkoeppe mkoeppe modified the milestones: sage-9.2, sage-9.3 Aug 29, 2020
@mkoeppe
Copy link
Contributor

mkoeppe commented Feb 13, 2021

comment:15

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.

@mkoeppe mkoeppe modified the milestones: sage-9.3, sage-9.4 Feb 13, 2021
@mjungmath
Copy link
Author

comment:16

By the way, why don't we use MapReduce patterns (or similar) for parallelizations? The parallelization syntax used all over is hardly readable imho.

See for example: https://towardsdatascience.com/a-beginners-introduction-into-mapreduce-2c912bb5e6ac

@mkoeppe mkoeppe modified the milestones: sage-9.4, sage-9.5 Jul 19, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 18, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.6, sage-9.7 Apr 1, 2022
@mkoeppe mkoeppe modified the milestones: sage-9.7, sage-9.8 Aug 31, 2022
@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants