Commit 634a7c85 authored by Xin Zhao's avatar Xin Zhao
Browse files

Move ircpi.c from test/mpi/rma to examples.



ircpi.c is an interactive test, which is never triggered
in RMA test suite. It is better to put it under examples.
Signed-off-by: Kenneth Raffenetti's avatarKen Raffenetti <raffenet@mcs.anl.gov>
parent dcd7ee6c
......@@ -57,7 +57,7 @@ noinst_PROGRAMS = cpi
# pmandel requires a separate set of socket calls (its a long story)
# and may not build on most platforms
EXTRA_PROGRAMS = pmandel pmandel_spawn pmandel_service pmandel_spaserv \
pmandel_fence hellow icpi parent child srtest \
pmandel_fence hellow icpi ircpi parent child srtest \
spawn_merge_parent spawn_merge_child1 spawn_merge_child2
# LIBS includes -lmpich and other libraries (e.g., -lpmpich if
......@@ -82,6 +82,8 @@ cpi_LDFLAGS = $(AM_LDFLAGS) $(mpich_libtool_static_flag)
icpi_SOURCES = icpi.c
icpi_LDADD = -lm
ircpi_SOURCES = ircpi.c
ircpi_LDADD = -lm
pmandel_SOURCES = pmandel.c
pmandel_LDADD = -lm
pmandel_spawn_SOURCES = pmandel_spawn.c
......
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
* (C) 2001 by Argonne National Laboratory.
* See COPYRIGHT in top-level directory.
*/
#include "mpi.h"
#include "stdio.h"
#include <math.h>
/* From Using MPI-2 */
int main(int argc, char *argv[])
{
int n, myid, numprocs, i, ierr;
double PI25DT = 3.141592653589793238462643;
double mypi, pi, h, sum, x;
MPI_Win nwin, piwin;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
if (myid == 0) {
MPI_Win_create(&n, sizeof(int), 1, MPI_INFO_NULL,
MPI_COMM_WORLD, &nwin);
MPI_Win_create(&pi, sizeof(double), 1, MPI_INFO_NULL,
MPI_COMM_WORLD, &piwin);
}
else {
MPI_Win_create(MPI_BOTTOM, 0, 1, MPI_INFO_NULL,
MPI_COMM_WORLD, &nwin);
MPI_Win_create(MPI_BOTTOM, 0, 1, MPI_INFO_NULL,
MPI_COMM_WORLD, &piwin);
}
while (1) {
if (myid == 0) {
fprintf(stdout, "Enter the number of intervals: (0 quits) ");
fflush(stdout);
ierr=scanf("%d",&n);
pi = 0.0;
}
MPI_Win_fence(0, nwin);
if (myid != 0)
MPI_Get(&n, 1, MPI_INT, 0, 0, 1, MPI_INT, nwin);
MPI_Win_fence(0, nwin);
if (n == 0)
break;
else {
h = 1.0 / (double) n;
sum = 0.0;
for (i = myid + 1; i <= n; i += numprocs) {
x = h * ((double)i - 0.5);
sum += (4.0 / (1.0 + x*x));
}
mypi = h * sum;
MPI_Win_fence( 0, piwin);
MPI_Accumulate(&mypi, 1, MPI_DOUBLE, 0, 0, 1, MPI_DOUBLE,
MPI_SUM, piwin);
MPI_Win_fence(0, piwin);
if (myid == 0) {
fprintf(stdout, "pi is approximately %.16f, Error is %.16f\n",
pi, fabs(pi - PI25DT));
fflush(stdout);
}
}
}
MPI_Win_free(&nwin);
MPI_Win_free(&piwin);
MPI_Finalize();
return 0;
}
......@@ -14,7 +14,6 @@ EXTRA_DIST = testlist
## correctly
noinst_PROGRAMS = \
allocmem \
ircpi \
test1 \
test2 \
test2_shm \
......@@ -216,5 +215,3 @@ mutex_bench_shm_ordered_SOURCES = mutex_bench.c mcs-mutex.c mcs-mutex.h
linked_list_bench_lock_shr_nocheck_SOURCES = linked_list_bench_lock_shr.c
linked_list_bench_lock_shr_nocheck_CPPFLAGS = -DUSE_MODE_NOCHECK $(AM_CPPFLAGS)
ircpi_LDADD = $(LDADD) -lm
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
* (C) 2001 by Argonne National Laboratory.
* See COPYRIGHT in top-level directory.
*/
#include "mpi.h"
#include "stdio.h"
#include <math.h>
/* From Using MPI-2 */
int main(int argc, char *argv[])
{
int n, myid, numprocs, i, ierr;
double PI25DT = 3.141592653589793238462643;
double mypi, pi, h, sum, x;
MPI_Win nwin, piwin;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
if (myid == 0) {
MPI_Win_create(&n, sizeof(int), 1, MPI_INFO_NULL,
MPI_COMM_WORLD, &nwin);
MPI_Win_create(&pi, sizeof(double), 1, MPI_INFO_NULL,
MPI_COMM_WORLD, &piwin);
}
else {
MPI_Win_create(MPI_BOTTOM, 0, 1, MPI_INFO_NULL,
MPI_COMM_WORLD, &nwin);
MPI_Win_create(MPI_BOTTOM, 0, 1, MPI_INFO_NULL,
MPI_COMM_WORLD, &piwin);
}
while (1) {
if (myid == 0) {
fprintf(stdout, "Enter the number of intervals: (0 quits) ");
fflush(stdout);
ierr=scanf("%d",&n);
pi = 0.0;
}
MPI_Win_fence(0, nwin);
if (myid != 0)
MPI_Get(&n, 1, MPI_INT, 0, 0, 1, MPI_INT, nwin);
MPI_Win_fence(0, nwin);
if (n == 0)
break;
else {
h = 1.0 / (double) n;
sum = 0.0;
for (i = myid + 1; i <= n; i += numprocs) {
x = h * ((double)i - 0.5);
sum += (4.0 / (1.0 + x*x));
}
mypi = h * sum;
MPI_Win_fence( 0, piwin);
MPI_Accumulate(&mypi, 1, MPI_DOUBLE, 0, 0, 1, MPI_DOUBLE,
MPI_SUM, piwin);
MPI_Win_fence(0, piwin);
if (myid == 0) {
fprintf(stdout, "pi is approximately %.16f, Error is %.16f\n",
pi, fabs(pi - PI25DT));
fflush(stdout);
}
}
}
MPI_Win_free(&nwin);
MPI_Win_free(&piwin);
MPI_Finalize();
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment