2-D FFT using MPI_Alltoall in MPI - mpi

I have a 4X6 matrix split as two 2X6 matrices on 2 processors. Since the rows have been split in a contiguous way (C Language) on the processors, we can carry out a 1-D FFT on the rows. The problem is we need an MPI_Alltoall() to collect contiguous columns on a particular processor for 1-D column FFT i.e. Processor 0 has:
A B C D E F
G H I J K L
Processor 1 has:
M N O P Q R
S T U V W X
The MPI_Alltoall() needs to convert this to the following on Processor 0:
A G M S
B H N T
C I O U
And the following on Processor 2:
D J P V
E K Q W
F L R X
I tried to define a vector having count=2, blocklength=1, stride=6 as the sending type vector, set its extent to MPI_INT, displacement to 0 and sent 3 instances of this vector using MPI_Alltoall(). This according to me should send A G, B H, and C I to processor 0 and D J, E K, and F L to processor 1. Similarly M S, N T, and O U to processor 0 and P V, Q W, and R X to processor 1.
Is my interpretation correct ? If yes, then how do I receive these 3 instances of vectors on the receiving side ( What/How do I define the datatype?).

Related

integer programming: need help to formulate a constrain

I am trying to formulate a constrain for my math model. the constrain goal is:
if A = 1 and B = 1 then C <= D
otherwise (A or B or both are 0) there is no constraint.
A and B are binary variables. C and D are integer numbers.
so far I was able to come up with this equation:
M(A - 1) - (B - 1) + C <= D (M is a big big number)
this formulation does not hold when A = 1 and B = 0
You could do this in two steps, first introduce a variable X representing logical and of A and B.
X >= A + B - 1
X <= A
X <= B
Then use X to express the inequality:
C - M(1-X) <= D

Explanation about RFC3284 - VCDIFF format

i'm new trying to read this type of documentation, and i'm confused in how the instruction of VCDIFF works, this is the original doc:
https://www.rfc-editor.org/rfc/rfc3284
This part:
ADD: This instruction has two arguments, a size x and a sequence
of x bytes to be copied.
COPY: This instruction has two arguments, a size x and an address
p in the string U. The arguments specify the substring of U
that must be copied. We shall assert that such a substring
must be entirely contained in either S or T.
RUN: This instruction has two arguments, a size x and a byte b,
that will be repeated x times.
Now the doc put an example:
a b c d e f g h i j k l m n o p
a b c d w x y z e f g h e f g h e f g h e f g h z z z z
COPY 4, 0
ADD 4, w x y z
COPY 4, 4
COPY 12, 24
RUN 4, z
I don't understand what every op did, i think the first copy is the first "a b c d", the add now includes "w x y z", now i don't understand well how the next two copies works.
If i think would be useful if someone can show what do that instructions, like "this instruction have this string as result and the next this", just to can compare step by step :D
Thx.
It looks like at the point you are executing this you will know the length of the output. In this "language" the input and output are consecutive in "memory". So you start with:
abcdefghijklmnop----------------------------
|<- S ->||<- T ->|
First COPY 4 bytes starting at offset 0 in the combined string:
ABCDefghijklmnopABCD------------------------
|<- S ->||<- T ->|
Then ADD 4 bytes, literally w x y z:
abcdefghijklmnopabcdWXYZ--------------------
|<- S ->||<- T ->|
Then COPY 4 bytes starting at offset 4:
abcdEFGHijklmnopabcdwxyzEFGH----------------
|<- S ->||<- T ->|
Then COPY 12 bytes starting at offset 24. This is a little tricky, because offset 24 is the "efgh" we just wrote and we haven't written the last 8 bytes yet, but if you do it one byte at a time the overlap doesn't matter:
|<- from ->|
|<- to ->|
abcdEFGHijklmnopabcdwxyzefghEFGHEFGHEFGH----
|<- S ->||<- T ->|
Finally there is a RUN of 4 consecutive bytes all "z":
abcdEFGHijklmnopabcdwxyzefghefghefghefghZZZZ
|<- S ->||<- T ->|

Is there a infinite loop in my codes? in ocaml

I want to get the sum of function f(i) values when i is equal from a to b
= f(a)+f(a+1)+...+f(b-1)+f(b)
So I wrote code like this.
let rec sigma : (int -> int) -> int -> int -> int
= fun f a b ->
if a=b then f a
else f b + sigma f a b-1 ;;
but result is that there is stack overflow during evaluation. Is there a infinite loop? and why?
sigma f a b-1 is parsed as (sigma f a b) - 1 instead of your intention, sigma f a (b-1). Since sigma f a b calls sigma f a b recursively in your code, it never stops.
The best practice is to put white spaces around binary operators like sigma f a b - 1 so that you would not misread what you write.

Breadth and depth first search on a graph with returning edges

I do understand depth and breadth first search but this graph got me confused as there is nodes that points to preceding nodes in the graph.
So let's say for instant that N is a goal state, then using Depth first search we would have
A B E J K L F G M N
So we is it correct this way ? I don't repeat the A because it was visited before right.
And using breadth first search I would go level by level and so I would have
A B C D E F G H I J K L M N
Is this correct ?
And if we change the Goal state to P
then DFS will give us A B E J K L F G M N H O P
and BFS will give us A B C D E F G H I J K L M N O P
I feel I got this right, I am just uncertain if I am right because of the returning edges in this graph. So I just want someone to confirm that I am on the right track here.
That sounds correct to me. When pointing to a node that's already in your result set, it should not be added into the result set a second time.

Accumulating Curried Function (SML)

I have a set of problems that I've been working through and can't seem to understand what the last one is asking. Here is the first problem, and my solution to it:
a) Often we are interested in computing ∑i=m..n f(i), the sum of function values f(i) for i = m through n. Define sigma f m n which computes ∑i=m..n f(i). This is different from defining sigma (f, m, n).
fun sigma f m n = if (m=n) then f(m) else (f(m) + sigma f (m+1) n);
The second problem, and my solution:
b) In the computation of sigma above, the index i goes from current
i to next value i+1. We may want to compute the sum of f(i) where i
goes from current i to the next, say i+2, not i+1. If we send this
information as an argument, we can compute more generalized
summation. Define ‘sum f next m n’ to compute such summation, where
‘next’ is a function to compute the next index value from the
current index value. To get ‘sigma’ in (a), you send the successor
function as ‘next’.
fun sum f next m n = if (m>=n) then f(m) else (f(m) + sum f (next) (next(m)) n);
And the third problem, with my attempt:
c) Generalizing sum in (b), we can compute not only summation but also
product and other forms of accumulation. If we want to compute sum in
(b), we send addition as an argument; if we want to compute the
product of function values, we send multiplication as an argument for
the same parameter. We also have to send the identity of the
operator. Define ‘accum h v f next m n’ to compute such accumulation,
where h is a two-variable function to do accumulation, and v is the
base value for accumulation. If we send the multiplication function
for h, 1 for v, and the successor function as ‘next’, this ‘accum’
computes ∏i=m..n f(i). Create examples whose ‘h’ is not addition or
multiplication, too.
fun accum h v f next m n = if (m>=n) then f(m) else (h (f(m)) (accum (h) (v) (f) (next) (next(m)) n));
In problem C, I'm unsure of what i'm suppose to do with my "v" argument. Right now the function will take any interval of numbers m - n and apply any kind of operation to them. For example, I could call my function
accum mult (4?) double next3 1 5;
where double is a doubling function and next3 adds 3 to a given value. Any ideas on how i'm suppoes to utilize the v value?
This set of problems is designed to lead to implementation of accumulation function. It takes
h - combines previous value and current value to produce next value
v - starting value for h
f - function to be applied to values from [m, n) interval before passing them to h function
next - computes next value in sequence
m and n - boundaries
Here is how I'd define accum:
fun accum h v f next m n = if m >= n then v else accum h (h (f m) v) f next (next m) n
Examples that were described in C will look like this:
fun sum x y = x + y;
fun mult x y = x * y;
fun id x = x;
accum sum 0 id next 1 10; (* sum [1, 10) staring 0 *)
accum mult 1 id next 1 10; (* prod [1, 10) starting 1 *)
For example, you can calculate sum of numbers from 1 to 10 and plus 5 if you pass 5 as v in first example.
The instructions will make more sense if you consider the possibility of an empty interval.
The "sum" of a single value n is n. The sum of no values is zero.
The "product" of a single value n is n. The product of no values is one.
A list of a single value n is [n] (n::nil). A list of no values is nil.
Currently, you're assuming that m ≤ n, and treating m = n as a special case that returns f m. Another approach is to treat m > n as the special case, returning v. Then, when m = n, your function will automatically return h v (f m), which is the same as (f m) (provided that v was selected properly for this h).
To be honest, though, I think the v-less approach is fine when the function's arguments specify an interval of the form [m,n], since there's no logical reason that such a function would support an empty interval. (I mean, [m,m−1] isn't so much "the empty interval" as it is "obvious error".) The v-ful approach is chiefly useful when the function's arguments specify a list or set of elements in some way that really could conceivably be empty, e.g. as an 'a list.

Resources