MPI.Reducev

Aperta
#531 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
julia

Direzione di ricerca

Inizia esaminando le API esistenti di riduzione e dei communicator di MPI.jl, quindi confronta il codice Julia proposto con l’implementazione Python collegata e con le convenzioni send/receive del progetto. Il lavoro è completo quando è stata concordata e implementata un’API MPI.Reducev che riduca oggetti Julia di dimensione variabile tra i rank, e quando il comportamento e le operazioni supportate sono documentati e verificati tramite test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

It would be nice if we could have an MPI.Reducev for reducing variable-sized Julia objects. I saw a Python implementation, maybe a GitHub gist [1], with an implementation that I roughly ported to Julia, probably with some mistakes based on my limited understanding of the MPI.jl API:

function Reducev(value, op, comm::MPI.Comm)
    # Reduces values on all processes to a single value on rank 0.
    # 
    # This function does the same thing as the function MPI_Reduce using
    # only MPI_Send and MPI_Recv. As shown, it operates with additions on
    # integers, so you could trivially use MPI_Reduce, but for operations
    # on variable size structs for which you cannot define an MPI_Datatype,
    # you can still use this method, by modifying it to use your op
    # and your datastructure.

    # TODO: Actually determine buffer
    tag = 0
    size = get_nworkers(comm)
    rank = get_worker_idx(comm)-1
    lastpower = 1 << log2(size)

    # each of the ranks greater than the last power of 2 less than size
    # need to downshift their data, since the binary tree reduction below
    # only works when N is a power of two.
    for i in lastpower:(size-1)
        if rank == i
            MPI.send(value, i-lastpower, tag, comm)
        end
    for i in 0:(size-lastpower-1)
        if rank == i
            MPI.Recv!(recvbuffer, i+lastpower, tag, comm)
            value = op(value, recvbuffer)
        end
    end

    for d in 0:(fastlog2(lastpower)-1)
        k = 0
        while k < lastpower
            k += 1 << (d + 1)
        end
        receiver = k
        sender = k + (1 << d)
        if rank == receiver
            MPI.Recv!(recvbuffer, 1, sender, tag)
            value = op(value, recvbuffer)
        elseif rank == sender
            MPI.Send(value, 1, receiver, tag)
        end
    end
    value
end

function fastlog2(v::UInt32)
    multiply_de_bruijn_bit_position::Vector{Int32} = [
        0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
        8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
    ]

    v |= v >> 1 # first round down to one less than a power of 2 
    v |= v >> 2
    v |= v >> 4
    v |= v >> 8
    v |= v >> 16

    # TODO: Fix this
    multiply_de_bruijn_bit_position[(UInt32(v * 0x07C4ACDDU) >> 27) + 1]
end

[1] https://gist.github.com/rmcgibbo/7178576

Lingua principale
Julia
Stelle
441
Fork
129
Merge medio
50m
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di JuliaParallel/MPI.jl

Tutte le issue di JuliaParallel/MPI.jl

Issue simili

Altre issue su Julia

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.