Commit 7a70f960 authored by saad.aswad's avatar saad.aswad

[P2] Add skeleton for manual reduce

parent 5ef116de
# problem2/manual_reduce.py
from mpi4py import MPI
import numpy as np
def manual_reduce(sendbuf, recvbuf, op, root, comm):
"""
Implementation of MPI_Reduce using tree-based communication.
Toplogy:
rank i children: 2*i+1, 2*i+2
rank i parent: (i-1)//2
"""
rank = comm.Get_rank()
size = comm.Get_size()
# Start with local data
# We assume sendbuf is a numpy array (for addition)
# Copy sendbuf to a local accumulator (or directly to recvbuf if leaf,
# but we need a temp buffer for accumulation)
# Logic:
# 1. Receive from children (if any).
# 2. Add to local accumulator.
# 3. If rank != root, Send accumulator to parent.
# 4. If rank == root, copy accumulator to recvbuf.
pass
def main():
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment