Opened 13 months ago

Last modified 4 months ago

#29796 new enhancement

Parallelization of Wedge Product

Reported by: gh-mjungmath Owned by:
Priority: major Milestone: sage-9.4
Component: geometry Keywords: manifolds, differential_forms, parallel
Cc: egourgoulhon, tscrim, mkoeppe Merged in:
Authors: Michael Jung Reviewers:
Report Upstream: N/A Work issues:
Branch: u/gh-mjungmath/wedge_product_parallel (Commits, GitHub, GitLab) Commit: 6303e7c19f873255c82c0dd76721baa8c5721669
Dependencies: Stopgaps:

Status badges

Description (last modified by gh-mjungmath)

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.

Change History (15)

comment:1 Changed 13 months ago by gh-mjungmath

  • Authors set to Michael Jung
  • Cc egourgoulhon added
  • Component changed from PLEASE CHANGE to geometry
  • Description modified (diff)
  • Keywords manifolds mixed_forms added

comment:2 Changed 13 months ago by gh-mjungmath

  • Type changed from PLEASE CHANGE to enhancement

comment:3 Changed 13 months ago by gh-mjungmath

  • Description modified (diff)

comment:4 Changed 12 months ago by gh-mjungmath

  • Description modified (diff)
  • Keywords differential_forms parallel added; mixed_forms removed
  • Summary changed from Mixed Forms - Fast zero check to Parallelization of Wedge Product

comment:5 Changed 12 months ago by gh-mjungmath

  • Description modified (diff)

comment:6 Changed 12 months ago by gh-mjungmath

  • Branch set to u/gh-mjungmath/wedge_product_parallel

comment:7 Changed 12 months ago by gh-mjungmath

  • Cc tscrim added
  • Commit set to d8ecedceb0f88de6afb5af3ad4f53a622552fec4

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 have no clue about effective parallelization.


New commits:

d8ecedcTrac #29796: first parallelization approach
Version 1, edited 12 months ago by gh-mjungmath (previous) (next) (diff)

comment:8 Changed 12 months ago by git

  • Commit changed from d8ecedceb0f88de6afb5af3ad4f53a622552fec4 to 6303e7c19f873255c82c0dd76721baa8c5721669

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

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

comment:9 follow-up: Changed 12 months ago by gh-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.


New commits:

0961bdcTrac #29796: further small improvements
6303e7cTrac #29796: indentation fixed
Last edited 12 months ago by gh-mjungmath (previous) (diff)

comment:10 in reply to: ↑ 9 Changed 12 months ago by egourgoulhon

Replying to gh-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.

comment:11 Changed 12 months ago by gh-mjungmath

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.

Last edited 12 months ago by gh-mjungmath (previous) (diff)

comment:12 Changed 12 months ago by gh-mjungmath

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

comment:13 Changed 12 months ago by gh-mjungmath

  • Cc mkoeppe added

comment:14 Changed 10 months ago by mkoeppe

  • Milestone changed from sage-9.2 to sage-9.3

comment:15 Changed 4 months ago by mkoeppe

  • Milestone changed from sage-9.3 to sage-9.4

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

Note: See TracTickets for help on using tickets.