Yet Another eXchange Tool 0.11.4
|
This example(rrobin.c) is the first step to understand working with yaxt. First of all include the basic header files:
We need to initialize MPI and yaxt as follows:
Find out number of processes and the local rank like in common MPI programs.
In this exmaple we are going to create a source array of length 5 for each process.
Each process will have an array the is filled with unique values. It is recommendable to use an array length < 10 and a number of processes < 10 to get a readable output.
In this case each process gets values of the form "abc", where
For example: 132 is the source value of on the process with rank 3 and is on the position 3 in the local array.
The goal of this little program is to rotate the source arrays in a round robin fashion. First proces owns first five elements indexed by 0, 1, 2, 3, 4 and is going to get the next five elements from the second process indexed by 5, 6, 7, 8, 9, without knowing who owns those. In fact first rank gets value array from second rank, the second one from the third and so on. The last rank gets an array from the first. We fill the source arrays with the previously defined values, and fill the destination arrays with -1 to see the change.
There are many ways to define, which elements are locally available (source) and which are required (destination). We could define them with an array of indices using an index vector (xt_idxvec.h), or we could define a block of elements we want to have using index stripes (xt_idxstripes.h). Using stripes we have to name the local start index, how many elements we want to have, an the stride between the elements. Here we need for the source an index stripe containing 5 elements with a stride of 1, beginnig at 0 for rank 0, at 1*len for rank 1 etc.
Now, we need the mapping of source and destination data between the processes and a redistribution object for the actual data exchange. There multiple strategies for doing the mapping, in this example all2all is used. An alternative would be dist_dir (xt_xmap_dist_dir.h).
To do the main step, we need pointers of source and destination arrays. Here it is "overdressed", but shows the main charachter if you have higher number of data arrays.
To see the result:
Once the created yaxt objects are not needed anymore they need to be deleted.
Common MPI finalisation