source: CIVL/examples/complex/fourth.c@ 2b25839

2.0 acw/focus-triggers main
Last change on this file since 2b25839 was a1fbf85, checked in by Stephen Siegel <siegel@…>, 7 days ago

Finished support of complex numbers for MPI, including reductions.
Started new approach to "apply". Trying to get rid of the $apply
system function and replace with pure CIVL-C.
Added more complex number tests, including for MPI.

  • 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.