acw/focus-triggers
|
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
|
| Rev | Line | |
|---|
| [a1fbf85] | 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 |
|
|---|
| 6 | int nprocs, rank;
|
|---|
| 7 |
|
|---|
| 8 | int main(void) {
|
|---|
| 9 | MPI_Init(NULL, NULL);
|
|---|
| 10 | MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
|
|---|
| 11 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| [ef04a5c] | 12 | assert(nprocs == 4);
|
|---|
| [a1fbf85] | 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.