| 1 | /* FEVS: A Functional Equivalence Verification Suite for High-Performance
|
|---|
| 2 | * Scientific Computing
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright (C) 2010, Stephen F. Siegel, Timothy K. Zirkel,
|
|---|
| 5 | * University of Delaware
|
|---|
| 6 | *
|
|---|
| 7 | * This program is free software; you can redistribute it and/or
|
|---|
| 8 | * modify it under the terms of the GNU General Public License as
|
|---|
| 9 | * published by the Free Software Foundation; either version 3 of the
|
|---|
| 10 | * License, or (at your option) any later version.
|
|---|
| 11 | *
|
|---|
| 12 | * This program is distributed in the hope that it will be useful, but
|
|---|
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 15 | * General Public License for more details.
|
|---|
| 16 | *
|
|---|
| 17 | * You should have received a copy of the GNU General Public License
|
|---|
| 18 | * along with this program; if not, write to the Free Software
|
|---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|---|
| 20 | * 02110-1301 USA.
|
|---|
| 21 | */
|
|---|
| 22 |
|
|---|
| 23 | #include<stdio.h>
|
|---|
| 24 | #include<stdlib.h>
|
|---|
| 25 | #include"mpi.h"
|
|---|
| 26 | #include<civlc.cvh>
|
|---|
| 27 |
|
|---|
| 28 | #pragma CIVL ACSL
|
|---|
| 29 |
|
|---|
| 30 | $input int N;
|
|---|
| 31 | $assume(N > 0);
|
|---|
| 32 | $input double a[N];
|
|---|
| 33 | $output double __sum;
|
|---|
| 34 |
|
|---|
| 35 | double sum;
|
|---|
| 36 | double localSum = 0.0;
|
|---|
| 37 | int PID;
|
|---|
| 38 | int NPROCS;
|
|---|
| 39 |
|
|---|
| 40 | int main(int argc, char *argv[]) {
|
|---|
| 41 | int n, first, afterLast, i;
|
|---|
| 42 |
|
|---|
| 43 | MPI_Init(&argc, &argv);
|
|---|
| 44 | MPI_Comm_size(MPI_COMM_WORLD, &NPROCS);
|
|---|
| 45 | MPI_Comm_rank(MPI_COMM_WORLD, &PID);
|
|---|
| 46 | n = N;
|
|---|
| 47 | first = n*PID/NPROCS;
|
|---|
| 48 | afterLast = n*(PID+1)/NPROCS;
|
|---|
| 49 |
|
|---|
| 50 | /*@ loop invariant first <= i <= afterLast;
|
|---|
| 51 | @ loop invariant localSum == \sum(first, i-1, \lambda int t; a[t]);
|
|---|
| 52 | @ loop assigns localSum, i;
|
|---|
| 53 | @*/
|
|---|
| 54 | for (i=first; i<afterLast; i++)
|
|---|
| 55 | localSum += a[i];
|
|---|
| 56 |
|
|---|
| 57 | MPI_Reduce(&localSum, &sum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
|
|---|
| 58 | if (PID == 0)
|
|---|
| 59 | __sum = sum;
|
|---|
| 60 | MPI_Finalize();
|
|---|
| 61 | return 0;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|