main
test-branch
|
Last change
on this file since bb03188 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago |
|
Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
776 bytes
|
| Line | |
|---|
| 1 | #include<stdio.h>
|
|---|
| 2 | #include<stdlib.h>
|
|---|
| 3 | #include<mpi.h>
|
|---|
| 4 | #include<civlc.cvh>
|
|---|
| 5 | #pragma CIVL ACSL
|
|---|
| 6 | $input int N;
|
|---|
| 7 | $assume(N > 0);
|
|---|
| 8 | $input double a[N];
|
|---|
| 9 | $output double sum_out;
|
|---|
| 10 | double sum_global, sum_local = 0.0;
|
|---|
| 11 | int pid, nprocs;
|
|---|
| 12 | int main() {
|
|---|
| 13 | MPI_Init(NULL, NULL);
|
|---|
| 14 | MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
|
|---|
| 15 | MPI_Comm_rank(MPI_COMM_WORLD, &pid);
|
|---|
| 16 | int first = N*pid/nprocs, afterLast = N*(pid+1)/nprocs;
|
|---|
| 17 | /*@ loop invariant first <= i <= afterLast;
|
|---|
| 18 | @ loop invariant sum_local == \sum(first, i-1, \lambda int t; a[t]);
|
|---|
| 19 | @*/
|
|---|
| 20 | for (int i=first; i<afterLast; i++)
|
|---|
| 21 | sum_local += a[i];
|
|---|
| 22 | MPI_Reduce(&sum_local, &sum_global, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
|
|---|
| 23 | if (pid == 0) {
|
|---|
| 24 | printf("impl: sum=%lf\n", sum_global);
|
|---|
| 25 | sum_out = sum_global;
|
|---|
| 26 | }
|
|---|
| 27 | MPI_Finalize();
|
|---|
| 28 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.