source: CIVL/examples/complex/fourth.c

main
Last change on this file was ef04a5c, checked in by Stephen Siegel <siegel@…>, 3 days ago

Added some more complex and collective tests.
Some minor code cleanup as well.

  • Property mode set to 100644
File size: 590 bytes
Line 
1/* Sums the 4-th roots of unity using MPI with 4 procs. */
2#include <assert.h>
3#include <complex.h>
4#include <mpi.h>
5
6int nprocs, rank;
7
8int main(void) {
9 MPI_Init(NULL, NULL);
10 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
11 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
12 assert(nprocs == 4);
13 long double _Complex x = 1.0il; // primitive 4-th root of unity
14 long double _Complex y = 1.0l;
15 for (int i=0; i<rank; i++)
16 y *= x;
17 // now y = i^rank
18 long double _Complex s;
19 MPI_Allreduce(&y, &s, 1, MPI_C_LONG_DOUBLE_COMPLEX, MPI_SUM, MPI_COMM_WORLD);
20 assert(s == 0.0l);
21 MPI_Finalize();
22}
Note: See TracBrowser for help on using the repository browser.