2 atlc - arbitrary transmission line calculator, for the analysis of
3 transmission lines are directional couplers.
5 Copyright (C) 2002. Dr. David Kirkby, PhD (G8WRB).
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either package_version 2
10 of the License, or (at your option) any later package_version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 Dr. David Kirkby, e-mail drkirkby@ntlworld.com
40 return (4.0 / (1.0 + a*a));
44 int main(int argc,char *argv[])
47 int done = 0, n, myid, numprocs, i;
48 double PI25DT = 3.141592653589793238462643;
49 double mypi, pi, h, sum, x;
50 double startwtime = 0.0, endwtime;
52 char processor_name[MPI_MAX_PROCESSOR_NAME];
54 MPI_Init(&argc,&argv);
55 MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
56 MPI_Comm_rank(MPI_COMM_WORLD,&myid);
57 MPI_Get_processor_name(processor_name,&namelen);
66 printf("Enter the number of intervals: (0 quits) ");
69 if (n==0) n=10000; else n=0;
71 startwtime = MPI_Wtime();
73 MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
80 /* A slightly better approach starts from large i and works back */
81 for (i = myid + 1; i <= n; i += numprocs)
83 x = h * ((double)i - 0.5);
88 MPI_Reduce(&mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
92 /* printf("pi is approximately %.16f, Error is %.16f\n",
93 pi, fabs(pi - PI25DT)); */
94 if (fabs(pi - PI25DT) > 0.00000001 )
99 endwtime = MPI_Wtime();
100 //printf("wall clock time = %f\n", endwtime-startwtime);