source: CIVL/examples/compare/adder/adder_par.c@ bb03188

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: 2.0 KB
RevLine 
[e936ca5]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
27#ifdef _CIVL
28#include<civlc.cvh>
29$input int NB;
30$output double __sum;
31#endif
32double sum;
33double localSum = 0.0;
34int PID;
35int NPROCS;
36
37double computeGlobalSum() {
38 double result = localSum;
39 double buffer;
40 int i;
41 MPI_Status status;
42
43 for (i=1; i<NPROCS; i++) {
44 MPI_Recv(&buffer, 1, MPI_DOUBLE, i, 0, MPI_COMM_WORLD, &status);
45 result += buffer;
46 }
47 return result;
48}
49
50int main(int argc, char *argv[]) {
51 int n, first, afterLast, i;
52 FILE *fp = fopen("data","r");
53
54 MPI_Init(&argc, &argv);
55 MPI_Comm_size(MPI_COMM_WORLD, &NPROCS);
56 MPI_Comm_rank(MPI_COMM_WORLD, &PID);
[5ca4694]57#ifdef _CIVL
58 $assume(1 < argc);
59#endif
[e936ca5]60 n = atoi(argv[1]);
61#ifdef _CIVL
62 $assume(0 < n && n <= NB);
63#endif
64
65 double a[n];
66
67 first = n*PID/NPROCS;
68 afterLast = n*(PID+1)/NPROCS;
69 for (i=0; i<n; i++) fscanf(fp, "%lf", &a[i]);
70 for (i=first; i<afterLast; i++) localSum += a[i];
71 if (PID == 0) {
72 sum = computeGlobalSum();
73 printf("%lf", sum);
74#ifdef _CIVL
75 __sum = sum;
76#endif
77 } else {
78 MPI_Send(&localSum, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
79 }
80 fclose(fp);
81 MPI_Finalize();
82 return 0;
83}
84
85
Note: See TracBrowser for help on using the repository browser.