In distributed deep learning frameworks, Reduce-Scatter is a common collective communication primitive.
There are $$$P$$$ processes numbered from $$$0$$$ to $$$P-1$$$. Process $$$i$$$ holds an array $$$A_i$$$ of length $$$P\cdot K$$$, indexed from $$$0$$$ to $$$P\cdot K-1$$$.
First, add the arrays element by element. For every index $$$x$$$, let $$$S_x$$$ be the sum of $$$A_i[x]$$$ over all processes $$$i$$$.
Next, divide $$$S$$$ from left to right into $$$P$$$ consecutive blocks of length $$$K$$$. Process $$$j$$$ receives block $$$j$$$, which consists of $$$S_{jK},S_{jK+1},\dots,S_{jK+K-1}$$$.
Given all arrays, determine the block received by every process.
The first line contains two integers $$$P$$$ and $$$K$$$ ($$$1\le P,K\le 50$$$), the number of processes and the length of each block.
Each of the next $$$P$$$ lines contains $$$P\cdot K$$$ integers. For every $$$0\le i \lt P$$$, line $$$i+1$$$ among these lines contains $$$A_i[0],A_i[1],\dots,A_i[P\cdot K-1]$$$ ($$$|A_i[x]|\le 10^9$$$), the array held by process $$$i$$$.
Print $$$P$$$ lines. For every $$$0\le j \lt P$$$, line $$$j+1$$$ must contain the $$$K$$$ integers received by process $$$j$$$, in their original order.
2 21 2 3 45 6 7 8
6 8 10 12
1 3-1 1 2
-1 1 2
In the first example, the element-wise sum is $$$[6,8,10,12]$$$. Therefore, process $$$0$$$ receives $$$[6,8]$$$, and process $$$1$$$ receives $$$[10,12]$$$.
In the second example, there is only one process, so it receives the entire array.
| Название |
|---|


