Fix line delimiters
diff --git a/samples/shallow-c/Makefile.mk b/samples/shallow-c/Makefile.mk
index 1a4eea8..cbe455f 100644
--- a/samples/shallow-c/Makefile.mk
+++ b/samples/shallow-c/Makefile.mk
@@ -1,30 +1,30 @@
-#
-
-CC = mpicc
-CFLAGS = -g
-LIB =
-
-CFILES = calc.c copy.c diag.c init.c main.c time.c tstep.c worker.c dump.c
-OBJECTS = calc.o copy.o diag.o init.o main.o time.o tstep.o worker.o dump.o
-HEADERS = decs.h
-
-all: shallow
-
-shallow: $(OBJECTS) $(HEADERS)
- $(CC) -g -o shallow $(OBJECTS) -lm $(LIB)
-
-tags: $(SOURCES) $(HEADERS)
- ctags -w $(SOURCES) $(HEADERS)
-
-clean:
- -rm -f shallow $(OBJECTS) core
-
-calc.o: calc.c decs.h
-copy.o: copy.c decs.h
-diag.o: diag.c decs.h
-init.o: init.c decs.h
-main.o: main.c decs.h
-time.o: time.c decs.h
-tstep.o: tstep.c decs.h
-worker.o: worker.c decs.h
-dump.o: dump.c decs.h
+#
+
+CC = mpicc
+CFLAGS = -g
+LIB =
+
+CFILES = calc.c copy.c diag.c init.c main.c time.c tstep.c worker.c dump.c
+OBJECTS = calc.o copy.o diag.o init.o main.o time.o tstep.o worker.o dump.o
+HEADERS = decs.h
+
+all: shallow
+
+shallow: $(OBJECTS) $(HEADERS)
+ $(CC) -g -o shallow $(OBJECTS) -lm $(LIB)
+
+tags: $(SOURCES) $(HEADERS)
+ ctags -w $(SOURCES) $(HEADERS)
+
+clean:
+ -rm -f shallow $(OBJECTS) core
+
+calc.o: calc.c decs.h
+copy.o: copy.c decs.h
+diag.o: diag.c decs.h
+init.o: init.c decs.h
+main.o: main.c decs.h
+time.o: time.c decs.h
+tstep.o: tstep.c decs.h
+worker.o: worker.c decs.h
+dump.o: dump.c decs.h
diff --git a/samples/shallow-c/calc.c b/samples/shallow-c/calc.c
index e0de89d..3a326c7 100644
--- a/samples/shallow-c/calc.c
+++ b/samples/shallow-c/calc.c
@@ -1,53 +1,53 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-
-#include "decs.h"
-
-void calcuvzh(jstart,jend,p,u,v,cu,cv,h,z,fsdx,fsdy)
-int jstart,jend;
-float p[n][m];
-float u[n][m];
-float v[n][m];
-float cu[n][m];
-float cv[n][m];
-float h[n][m];
-float z[n][m];
-float fsdx, fsdy;
-{
- int i,j,ip,jp;
-
- for(j=jstart;j<=jend;j++) {
- jp = (j+1) % n;
- for (i = 0; i < m; i++){
- ip = (i+1) % m;
- cu[j][ip] = 0.5*(p[j][ip]+p[j][i])*u[j][ip];
- cv[jp][i] = 0.5*(p[jp][i]+p[j][i])*v[jp][i];
- z[jp][ip] = (fsdx*(v[jp][ip]-v[jp][i])-fsdy*(u[jp][ip]
- -u[j][ip]))/(p[j][i]+p[j][ip]+p[jp][ip]+p[jp][i]);
- h[j][i] = p[j][i]+0.25*(u[j][ip]*u[j][ip]+u[j][i]*u[j][i]
- +v[jp][i]*v[jp][i]+v[j][i]*v[j][i]);
- }
- }
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+
+#include "decs.h"
+
+void calcuvzh(jstart,jend,p,u,v,cu,cv,h,z,fsdx,fsdy)
+int jstart,jend;
+float p[n][m];
+float u[n][m];
+float v[n][m];
+float cu[n][m];
+float cv[n][m];
+float h[n][m];
+float z[n][m];
+float fsdx, fsdy;
+{
+ int i,j,ip,jp;
+
+ for(j=jstart;j<=jend;j++) {
+ jp = (j+1) % n;
+ for (i = 0; i < m; i++){
+ ip = (i+1) % m;
+ cu[j][ip] = 0.5*(p[j][ip]+p[j][i])*u[j][ip];
+ cv[jp][i] = 0.5*(p[jp][i]+p[j][i])*v[jp][i];
+ z[jp][ip] = (fsdx*(v[jp][ip]-v[jp][i])-fsdy*(u[jp][ip]
+ -u[j][ip]))/(p[j][i]+p[j][ip]+p[jp][ip]+p[jp][i]);
+ h[j][i] = p[j][i]+0.25*(u[j][ip]*u[j][ip]+u[j][i]*u[j][i]
+ +v[jp][i]*v[jp][i]+v[j][i]*v[j][i]);
+ }
+ }
+}
diff --git a/samples/shallow-c/copy.c b/samples/shallow-c/copy.c
index 052f5c0..9fcb945 100644
--- a/samples/shallow-c/copy.c
+++ b/samples/shallow-c/copy.c
@@ -1,91 +1,91 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-#include <strings.h>
-#include "decs.h"
-
-twod_acopy(src,dest)
-float src[n][m];
-float dest[n][m];
-{
- int i, j;
-
- /*
- for (i = 0; i < m; i++) {
- for (j = 0; j < n; j++) {
- dest[j][i] = src[j][i];
- }
- }
- */
- for (j = 0; j < n; j++)
- bcopy(src[j], dest[j], sizeof(src[j]));
-}
-
-twod_acopy_column(src,dest,column)
-float src[n][m];
-float dest[n][m];
-int column;
-/*
-This now does a ROW COPY and not a column copy
-*/
-{
- int i;
-
- /*
- for (i = 0; i < m; i++)
- dest[column][i] = src[column][i];
- */
- bcopy(src[column], dest[column], sizeof(src[column]));
-}
-
-acopy_two_to_one(twodim,onedim,column)
-float twodim[n][m];
-float onedim[m];
-int column;
-/*
-This now does a ROW COPY and not a column copy
-*/
-{
- int i;
-
- /*
- for (i = 0; i < m; i++)
- onedim[i] = twodim[column][i];
- */
- bcopy(twodim[column], onedim, sizeof(twodim[column]));
-}
-
-acopy_one_to_two(onedim,twodim,column)
-float twodim[n][m];
-float onedim[m];
-int column;
-{
- int i;
-
- /*
- for (i = 0; i < m; i++)
- twodim[column][i] = onedim[i];
- */
- bcopy(onedim, twodim[column], sizeof(twodim[column]));
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+#include <strings.h>
+#include "decs.h"
+
+twod_acopy(src,dest)
+float src[n][m];
+float dest[n][m];
+{
+ int i, j;
+
+ /*
+ for (i = 0; i < m; i++) {
+ for (j = 0; j < n; j++) {
+ dest[j][i] = src[j][i];
+ }
+ }
+ */
+ for (j = 0; j < n; j++)
+ bcopy(src[j], dest[j], sizeof(src[j]));
+}
+
+twod_acopy_column(src,dest,column)
+float src[n][m];
+float dest[n][m];
+int column;
+/*
+This now does a ROW COPY and not a column copy
+*/
+{
+ int i;
+
+ /*
+ for (i = 0; i < m; i++)
+ dest[column][i] = src[column][i];
+ */
+ bcopy(src[column], dest[column], sizeof(src[column]));
+}
+
+acopy_two_to_one(twodim,onedim,column)
+float twodim[n][m];
+float onedim[m];
+int column;
+/*
+This now does a ROW COPY and not a column copy
+*/
+{
+ int i;
+
+ /*
+ for (i = 0; i < m; i++)
+ onedim[i] = twodim[column][i];
+ */
+ bcopy(twodim[column], onedim, sizeof(twodim[column]));
+}
+
+acopy_one_to_two(onedim,twodim,column)
+float twodim[n][m];
+float onedim[m];
+int column;
+{
+ int i;
+
+ /*
+ for (i = 0; i < m; i++)
+ twodim[column][i] = onedim[i];
+ */
+ bcopy(onedim, twodim[column], sizeof(twodim[column]));
+}
diff --git a/samples/shallow-c/decs.h b/samples/shallow-c/decs.h
index b302a9b..f815667 100644
--- a/samples/shallow-c/decs.h
+++ b/samples/shallow-c/decs.h
@@ -1,97 +1,97 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-
-#define m 32 /* 18 Number of points in x direction */
-#define n 32 /* 18 Number of points in y direction */
-#define a 1.e6 /* Nominally the radius of the earth but here just
- a length scale*/
-#define dt 90.0 /* Time step in seconds */
-#define secs_pd 86400. /* Seconds per day */
-#define dx 1.e5 /* Grid spacing in x direction */
-#define dy 1.e5 /* Grid spacing in y direction */
-#define alpha 0.001 /* Asselin time filter parameter */
-#define itmax 1000 /* Number of time steps in run */
-#define mprint 50 /* Print diagnostics every mprint steps */
-
-#define lower 1 /* low bound of range of processors */
-#define upper 20 /* hi bound of range of processors */
-#define version 0.6 /* version number of program */
-
-/* constants used by dump() to determine what data structure to print */
-#define one_dim 1
-#define two_dim 2
-#define p_label 0
-#define u_label 1
-#define v_label 2
-#define pold_label 3
-#define uold_label 4
-#define vold_label 5
-#define psi_label 6
-#define cu_label 7
-#define cv_label 8
-#define h_label 9
-#define z_label 10
-#define dudt_label 11
-#define dvdt_label 12
-
-/* message types */
-#define START_SIGNAL 0
-#define END_SIGNAL 4
-#define CALC1a 20
-#define CALC1b 21
-#define CALC1c 22
-#define CALC2a 23
-#define CALC2b 24
-#define TIME1a 30
-#define TIME1b 31
-#define TIME1c 32
-#define TIME1d 33
-#define TIME2 34
-#define P_ROW 50
-#define U_ROW 51
-#define V_ROW 52
-#define PSI_ROW 53
-#define POLD_ROW 54
-#define UOLD_ROW 55
-#define VOLD_ROW 56
-#define H_ROW 57
-#define Z_ROW 58
-
-#define PREV 0
-#define NEXT 1
-#define JSTART 2
-#define JEND 3
-
-#define debug_data 0x1
-#define debug_master 0x2
-#define debug_worker 0x4
-#define debug_call 0x8
-#define debug 0x0
-
-struct res
-{
- float row[m];
- int indx;
-};
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+
+#define m 32 /* 18 Number of points in x direction */
+#define n 32 /* 18 Number of points in y direction */
+#define a 1.e6 /* Nominally the radius of the earth but here just
+ a length scale*/
+#define dt 90.0 /* Time step in seconds */
+#define secs_pd 86400. /* Seconds per day */
+#define dx 1.e5 /* Grid spacing in x direction */
+#define dy 1.e5 /* Grid spacing in y direction */
+#define alpha 0.001 /* Asselin time filter parameter */
+#define itmax 1000 /* Number of time steps in run */
+#define mprint 50 /* Print diagnostics every mprint steps */
+
+#define lower 1 /* low bound of range of processors */
+#define upper 20 /* hi bound of range of processors */
+#define version 0.6 /* version number of program */
+
+/* constants used by dump() to determine what data structure to print */
+#define one_dim 1
+#define two_dim 2
+#define p_label 0
+#define u_label 1
+#define v_label 2
+#define pold_label 3
+#define uold_label 4
+#define vold_label 5
+#define psi_label 6
+#define cu_label 7
+#define cv_label 8
+#define h_label 9
+#define z_label 10
+#define dudt_label 11
+#define dvdt_label 12
+
+/* message types */
+#define START_SIGNAL 0
+#define END_SIGNAL 4
+#define CALC1a 20
+#define CALC1b 21
+#define CALC1c 22
+#define CALC2a 23
+#define CALC2b 24
+#define TIME1a 30
+#define TIME1b 31
+#define TIME1c 32
+#define TIME1d 33
+#define TIME2 34
+#define P_ROW 50
+#define U_ROW 51
+#define V_ROW 52
+#define PSI_ROW 53
+#define POLD_ROW 54
+#define UOLD_ROW 55
+#define VOLD_ROW 56
+#define H_ROW 57
+#define Z_ROW 58
+
+#define PREV 0
+#define NEXT 1
+#define JSTART 2
+#define JEND 3
+
+#define debug_data 0x1
+#define debug_master 0x2
+#define debug_worker 0x4
+#define debug_call 0x8
+#define debug 0x0
+
+struct res
+{
+ float row[m];
+ int indx;
+};
diff --git a/samples/shallow-c/diag.c b/samples/shallow-c/diag.c
index 919a26a..255b167 100644
--- a/samples/shallow-c/diag.c
+++ b/samples/shallow-c/diag.c
@@ -1,75 +1,75 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-#include <stdio.h>
-#include "decs.h"
-
-void diag(ncycle,time,p,u,v,h,z)
-int ncycle;
-float time;
-float p[n][m];
-float u[n][m];
-float v[n][m];
-float h[n][m];
-float z[n][m];
-/*
-Calculate global integrals of kinetic and potential energy and
-potential enstrophy
-*/
-{
- float ptot,ketot,etot,enstot,ptime,pmean;
- int i,j,ip,jp;
-
- ptot=0.; ketot=0.; etot=0.; enstot = 0.; pmean = 0.;
- for (j = 0; j < n; j++) {
- for (i = 0; i < m; i++) {
- pmean = pmean+p[j][i];
- }
- }
- pmean = pmean/(m*n);
- for (j = 0; j < n; j++){
- jp = (j+1) % n;
- for (i = 0; i < m; i++){
- ip = (i+1) % m;
- ketot += p[j][i]*0.25*(u[j][ip]*u[j][ip]+u[j][i]*u[j][i]
- +v[jp][i]*v[jp][i]+v[j][i]*v[j][i]);
- ptot += (p[j][i]-pmean)*(p[j][i]-pmean);
- etot += h[j][i];
- enstot += z[jp][ip]*z[jp][ip] * 0.25*
- (p[j][i]+p[j][ip]+p[jp][ip]+p[jp][i]);
- }
- }
- ptot *= 0.5/(m*n);
- ketot /= (m*n);
- etot /= (m*n);
- enstot /= (m*n);
- ptime = time/secs_pd;
-
- if ( ncycle > 0 ) {
- printf("Cycle number %5d Model time in days %6.2f \n \
- Potential energy %12.3f Kinetic Energy %12.3f \n \
- Total Energy %12.3f Pot. Enstrophy %15.6e \n\n",
- ncycle,ptime,ptot,ketot,ptot+ketot,enstot);
- }
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+#include <stdio.h>
+#include "decs.h"
+
+void diag(ncycle,time,p,u,v,h,z)
+int ncycle;
+float time;
+float p[n][m];
+float u[n][m];
+float v[n][m];
+float h[n][m];
+float z[n][m];
+/*
+Calculate global integrals of kinetic and potential energy and
+potential enstrophy
+*/
+{
+ float ptot,ketot,etot,enstot,ptime,pmean;
+ int i,j,ip,jp;
+
+ ptot=0.; ketot=0.; etot=0.; enstot = 0.; pmean = 0.;
+ for (j = 0; j < n; j++) {
+ for (i = 0; i < m; i++) {
+ pmean = pmean+p[j][i];
+ }
+ }
+ pmean = pmean/(m*n);
+ for (j = 0; j < n; j++){
+ jp = (j+1) % n;
+ for (i = 0; i < m; i++){
+ ip = (i+1) % m;
+ ketot += p[j][i]*0.25*(u[j][ip]*u[j][ip]+u[j][i]*u[j][i]
+ +v[jp][i]*v[jp][i]+v[j][i]*v[j][i]);
+ ptot += (p[j][i]-pmean)*(p[j][i]-pmean);
+ etot += h[j][i];
+ enstot += z[jp][ip]*z[jp][ip] * 0.25*
+ (p[j][i]+p[j][ip]+p[jp][ip]+p[jp][i]);
+ }
+ }
+ ptot *= 0.5/(m*n);
+ ketot /= (m*n);
+ etot /= (m*n);
+ enstot /= (m*n);
+ ptime = time/secs_pd;
+
+ if ( ncycle > 0 ) {
+ printf("Cycle number %5d Model time in days %6.2f \n \
+ Potential energy %12.3f Kinetic Energy %12.3f \n \
+ Total Energy %12.3f Pot. Enstrophy %15.6e \n\n",
+ ncycle,ptime,ptot,ketot,ptot+ketot,enstot);
+ }
+}
diff --git a/samples/shallow-c/dump.c b/samples/shallow-c/dump.c
index 4c484bb..4ffe41f 100644
--- a/samples/shallow-c/dump.c
+++ b/samples/shallow-c/dump.c
@@ -1,90 +1,90 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-
-#include "decs.h"
-#include <stdio.h>
-
-void dump(int indx,int one_or_two,float onedim[m],float twodim[n][m])
-{
- int i, j;
-
- printf("\n");
- switch (indx) {
- case p_label :
- printf("dumping p:\n");
- break;
- case u_label :
- printf("dumping u:\n");
- break;
- case v_label :
- printf("dumping v:\n");
- break;
- case pold_label :
- printf("dumping pold:\n");
- break;
- case uold_label :
- printf("dumping uold:\n");
- break;
- case vold_label :
- printf("dumping vold:\n");
- break;
- case psi_label :
- printf("dumping psi:\n");
- break;
- case cu_label :
- printf("dumping cu:\n");
- break;
- case cv_label :
- printf("dumping cv:\n");
- break;
- case h_label :
- printf("dumping h:\n");
- break;
- case z_label :
- printf("dumping z:\n");
- break;
- case dudt_label :
- printf("dumping dudt:\n");
- break;
- case dvdt_label :
- printf("dumping dvdt:\n");
- break;
- }
-
- if (one_or_two == 1) {
- for (i = 0; i < m; i++) {
- printf("%d %f", i, onedim[i]);
- printf("\n");
- }
- }
- else {
- for (i = 0; i < m; i++) {
- for (j = 0; j < n; j++) {
- printf("%d,%d %f", i, j, twodim[j][i]);
- printf("\n");
- }
- }
- }
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+
+#include "decs.h"
+#include <stdio.h>
+
+void dump(int indx,int one_or_two,float onedim[m],float twodim[n][m])
+{
+ int i, j;
+
+ printf("\n");
+ switch (indx) {
+ case p_label :
+ printf("dumping p:\n");
+ break;
+ case u_label :
+ printf("dumping u:\n");
+ break;
+ case v_label :
+ printf("dumping v:\n");
+ break;
+ case pold_label :
+ printf("dumping pold:\n");
+ break;
+ case uold_label :
+ printf("dumping uold:\n");
+ break;
+ case vold_label :
+ printf("dumping vold:\n");
+ break;
+ case psi_label :
+ printf("dumping psi:\n");
+ break;
+ case cu_label :
+ printf("dumping cu:\n");
+ break;
+ case cv_label :
+ printf("dumping cv:\n");
+ break;
+ case h_label :
+ printf("dumping h:\n");
+ break;
+ case z_label :
+ printf("dumping z:\n");
+ break;
+ case dudt_label :
+ printf("dumping dudt:\n");
+ break;
+ case dvdt_label :
+ printf("dumping dvdt:\n");
+ break;
+ }
+
+ if (one_or_two == 1) {
+ for (i = 0; i < m; i++) {
+ printf("%d %f", i, onedim[i]);
+ printf("\n");
+ }
+ }
+ else {
+ for (i = 0; i < m; i++) {
+ for (j = 0; j < n; j++) {
+ printf("%d,%d %f", i, j, twodim[j][i]);
+ printf("\n");
+ }
+ }
+ }
+}
diff --git a/samples/shallow-c/init.c b/samples/shallow-c/init.c
index b14b76f..55cf163 100644
--- a/samples/shallow-c/init.c
+++ b/samples/shallow-c/init.c
@@ -1,86 +1,86 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-#include <stdio.h>
-#include <math.h>
-#include "decs.h"
-
-void initialise(p, u, v, psi, pold, uold, vold, di, dj, z)
-float p[n][m];
-float u[n][m];
-float v[n][m];
-float psi[n][m];
-float pold[n][m];
-float uold[n][m];
-float vold[n][m];
-float di, dj;
-float z[n][m];
-{
- int i,j,ip,jp;
-
- /* initialise values of the streamfunction */
- for (j = 0; j < n; j++){
- for (i = 0; i < m; i++){
- float sin1 = sin((double)((i+0.5)*di));
- float sin2 = sin((double)((j+0.5)*dj));
- psi[j][i] = a*sin1*sin2;
- }
- }
-
- /* initialise velocities */
- for (j = 0; j < n; j++){
- jp = (j+1) % n;
- for (i = 0; i < m; i++){
- ip = (i+1) % m;
- u[j][ip] = -(psi[jp][ip]-psi[j][ip])/dy;
- v[jp][i] = -(psi[jp][ip]-psi[jp][i])/dx;
- }
- }
-
- for (j = 0; j < n; j++) {
- for (i = 0; i < m; i++) {
- uold[j][i] = u[j][i];
- vold[j][i] = v[j][i];
- /* free surface height * gravitational acceleration */
- pold[j][i] = 50000.;
- p[j][i] = 50000.;
- }
- }
-
- for (j = 0; j < n; j++) {
- for (i = 0; i < m; i++) {
- z[j][i] = 0.;
- }
- }
-
-
- printf("\n");
- printf("Shallow water weather model - Distributed Memory Version 0.6\n\n");
- printf("Number of points in the X direction%8d\n", n);
- printf("Number of points in the Y direction%8d\n", m);
- printf("Grid spacing in the X direction %8.2f\n", dx);
- printf("Grid spacing in the Y direction %8.2f\n", dy);
- printf("Time step %8.3f\n", dt);
- printf("Time filter parameter %8.3f\n", alpha);
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+#include <stdio.h>
+#include <math.h>
+#include "decs.h"
+
+void initialise(p, u, v, psi, pold, uold, vold, di, dj, z)
+float p[n][m];
+float u[n][m];
+float v[n][m];
+float psi[n][m];
+float pold[n][m];
+float uold[n][m];
+float vold[n][m];
+float di, dj;
+float z[n][m];
+{
+ int i,j,ip,jp;
+
+ /* initialise values of the streamfunction */
+ for (j = 0; j < n; j++){
+ for (i = 0; i < m; i++){
+ float sin1 = sin((double)((i+0.5)*di));
+ float sin2 = sin((double)((j+0.5)*dj));
+ psi[j][i] = a*sin1*sin2;
+ }
+ }
+
+ /* initialise velocities */
+ for (j = 0; j < n; j++){
+ jp = (j+1) % n;
+ for (i = 0; i < m; i++){
+ ip = (i+1) % m;
+ u[j][ip] = -(psi[jp][ip]-psi[j][ip])/dy;
+ v[jp][i] = -(psi[jp][ip]-psi[jp][i])/dx;
+ }
+ }
+
+ for (j = 0; j < n; j++) {
+ for (i = 0; i < m; i++) {
+ uold[j][i] = u[j][i];
+ vold[j][i] = v[j][i];
+ /* free surface height * gravitational acceleration */
+ pold[j][i] = 50000.;
+ p[j][i] = 50000.;
+ }
+ }
+
+ for (j = 0; j < n; j++) {
+ for (i = 0; i < m; i++) {
+ z[j][i] = 0.;
+ }
+ }
+
+
+ printf("\n");
+ printf("Shallow water weather model - Distributed Memory Version 0.6\n\n");
+ printf("Number of points in the X direction%8d\n", n);
+ printf("Number of points in the Y direction%8d\n", m);
+ printf("Grid spacing in the X direction %8.2f\n", dx);
+ printf("Grid spacing in the Y direction %8.2f\n", dy);
+ printf("Time step %8.3f\n", dt);
+ printf("Time filter parameter %8.3f\n", alpha);
+}
diff --git a/samples/shallow-c/main.c b/samples/shallow-c/main.c
index 42645da..ebae9e0 100644
--- a/samples/shallow-c/main.c
+++ b/samples/shallow-c/main.c
@@ -1,261 +1,261 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-
-#include <math.h>
-#include <mpi.h>
-#include <stdio.h>
-#include "decs.h"
-
-extern void worker();
-MPI_Datatype * setup_res();
-
-main (argc, argv)
- int argc;
- char * argv[];
-{
- float pi=4.*(float)atan((double)1.);
- float p[n][m]; /* Pressure (or free surface height) */
- float u[n][m]; /* Zonal wind */
- float v[n][m]; /* Meridional wind */
- float psi[n][m]; /* Velocity streamfunction */
- float pold[n][m];
- float uold[n][m];
- float vold[n][m];
- float h[n][m];
- float z[n][m];
- float dummy1[m];
- float dummy2[n][m];
- float tpi=pi+pi;
- float di=tpi/(float)m;
- float dj=tpi/(float)n;
- int i, j, chunk_size, nxt, prv;
-
- int master_packet[4];
- float p_start[m];
- float u_start[m];
- float v_start[m];
- float psi_start[m];
- float pold_start[m];
- float uold_start[m];
- float vold_start[m];
- int proc_cnt;
- int tid;
- MPI_Datatype * res_type;
-
- MPI_Init(&argc, &argv);
- MPI_Comm_size(MPI_COMM_WORLD, &proc_cnt);
- MPI_Comm_rank(MPI_COMM_WORLD, &tid);
-
- if ( proc_cnt < 2 )
- {
- fprintf(stderr, "must have at least 2 processes, not %d\n", proc_cnt);
- MPI_Finalize();
- return 1;
- }
-
- if ( (n % (proc_cnt - 1)) != 0 )
- {
- if ( tid == 0 )
- fprintf(stderr, "(number of processes - 1) must be a multiple of %d\n", n);
-
- MPI_Finalize();
- return 1;
- }
-
- if (tid != 0) {
- worker();
- MPI_Barrier(MPI_COMM_WORLD);
- MPI_Finalize();
- } else {
-
- /* master process */
-
- chunk_size = n / (proc_cnt - 1);
-
- for (i = 1: i < proc_cnt; i++) {
- /* calculate each worker's boundary */
- master_packet[JSTART] = (i - 1) * chunk_size;
-
- if (i == proc_cnt - 1)
- master_packet[JEND] = n - 1;
- else
- master_packet[JEND] = i * chunk_size - 1;
-
- if (i == 1)
- prv = proc_cnt-1;
- else
- prv = i-1;
-
- master_packet[PREV] = prv;
-
- if (i == proc_cnt - 1)
- nxt = 1;
- else
- nxt = i+1;
-
- master_packet[NEXT] = nxt;
-
- MPI_Send(&master_packet, 4, MPI_INT, i, START_SIGNAL,
- MPI_COMM_WORLD);
-
- printf("jstart=%d, jend=%d, next=%d, prev=%d\n",
- master_packet[JSTART],
- master_packet[JEND],
- master_packet[NEXT],
- master_packet[PREV]);
- }
-
-
- /*
- initialise data structures and construct packets to be sent to workers
- */
-
- initialise(p, u, v, psi, pold, uold, vold, di, dj, z);
- diag(1, 0., p, u, v, h, z);
-
- for (i = 1; i < proc_cnt; i++) {
- for (j = 0; j < n; j++) {
- acopy_two_to_one(p, p_start, j);
- MPI_Send(&p_start, m, MPI_FLOAT, i, P_ROW,
- MPI_COMM_WORLD);
-
- acopy_two_to_one(u, u_start, j);
- MPI_Send(&u_start, m, MPI_FLOAT, i, U_ROW,
- MPI_COMM_WORLD);
-
- acopy_two_to_one(v, v_start, j);
- MPI_Send(&v_start, m, MPI_FLOAT, i, V_ROW,
- MPI_COMM_WORLD);
-
- acopy_two_to_one(psi, psi_start, j);
- MPI_Send(&psi_start, m, MPI_FLOAT, i, PSI_ROW,
- MPI_COMM_WORLD);
-
- acopy_two_to_one(pold, pold_start, j);
- MPI_Send(&pold_start, m, MPI_FLOAT, i, POLD_ROW,
- MPI_COMM_WORLD);
-
- acopy_two_to_one(uold, uold_start, j);
- MPI_Send(&uold_start, m, MPI_FLOAT, i, UOLD_ROW,
- MPI_COMM_WORLD);
-
- acopy_two_to_one(vold, vold_start, j);
- MPI_Send(&vold_start, m, MPI_FLOAT, i, VOLD_ROW,
- MPI_COMM_WORLD);
- }
- }
-
- /*
- receive packets back from the workers
- */
- res_type = setup_res();
-
- if ( debug & debug_master )
- printf("receiving P\n");
-
- update_global_ds(res_type, P_ROW, p);
-
- if ( debug & debug_master )
- printf("receiving U\n");
-
- update_global_ds(res_type, U_ROW, u);
-
- if ( debug & debug_master )
- printf("receiving V\n");
-
- update_global_ds(res_type, V_ROW, v);
-
- if ( debug & debug_master )
- printf("receiving H\n");
-
- update_global_ds(res_type, H_ROW, h);
-
- if ( debug & debug_master )
- printf("receiving Z\n");
-
- update_global_ds(res_type, Z_ROW, z);
-
- for (i = 1; i < proc_cnt; i++){
- MPI_Send(&master_packet, 4, MPI_INT, i, END_SIGNAL,
- MPI_COMM_WORLD);
- }
-
- /* wait for all workers to end */
- MPI_Barrier(MPI_COMM_WORLD);
- MPI_Finalize();
-
- diag(itmax, itmax*dt, p, u, v, h, z);
- }
-
- return 0;
-}
-
-MPI_Datatype *
-setup_res()
-{
- struct res res;
- MPI_Aint res_disp[2];
- static int res_done = 0;
- static int res_len[2] = { m, 1 };
- static MPI_Datatype res_old[2] = { MPI_FLOAT, MPI_INT };
- static MPI_Datatype res_type;
-
- if ( res_done )
- return &res_type;
-
- res_done++;
- MPI_Address(&res.row[0], &res_disp[0]);
- MPI_Address(&res.indx, &res_disp[1]);
- res_disp[1] -= res_disp[0];
- res_disp[0] = 0;
- MPI_Type_struct(2, res_len, res_disp, res_old, &res_type);
- MPI_Type_commit(&res_type);
-
- return &res_type;
-}
-
-/*
-this function waits for all the workers to return the packets of
-a particular type and then updates the master's copy of the same type
-*/
-update_global_ds(res_type, indx, ds)
- MPI_Datatype * res_type;
- int indx;
- float ds[n][m];
-
-{
- int i;
- int row;
- struct res res;
- MPI_Status status;
-
- for (i = 0; i < n; i++) {
- MPI_Recv(&res, 1, *res_type, MPI_ANY_SOURCE, indx,
- MPI_COMM_WORLD, &status);
-
- acopy_one_to_two(res.row, ds, res.indx);
- }
-
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+
+#include <math.h>
+#include <mpi.h>
+#include <stdio.h>
+#include "decs.h"
+
+extern void worker();
+MPI_Datatype * setup_res();
+
+main (argc, argv)
+ int argc;
+ char * argv[];
+{
+ float pi=4.*(float)atan((double)1.);
+ float p[n][m]; /* Pressure (or free surface height) */
+ float u[n][m]; /* Zonal wind */
+ float v[n][m]; /* Meridional wind */
+ float psi[n][m]; /* Velocity streamfunction */
+ float pold[n][m];
+ float uold[n][m];
+ float vold[n][m];
+ float h[n][m];
+ float z[n][m];
+ float dummy1[m];
+ float dummy2[n][m];
+ float tpi=pi+pi;
+ float di=tpi/(float)m;
+ float dj=tpi/(float)n;
+ int i, j, chunk_size, nxt, prv;
+
+ int master_packet[4];
+ float p_start[m];
+ float u_start[m];
+ float v_start[m];
+ float psi_start[m];
+ float pold_start[m];
+ float uold_start[m];
+ float vold_start[m];
+ int proc_cnt;
+ int tid;
+ MPI_Datatype * res_type;
+
+ MPI_Init(&argc, &argv);
+ MPI_Comm_size(MPI_COMM_WORLD, &proc_cnt);
+ MPI_Comm_rank(MPI_COMM_WORLD, &tid);
+
+ if ( proc_cnt < 2 )
+ {
+ fprintf(stderr, "must have at least 2 processes, not %d\n", proc_cnt);
+ MPI_Finalize();
+ return 1;
+ }
+
+ if ( (n % (proc_cnt - 1)) != 0 )
+ {
+ if ( tid == 0 )
+ fprintf(stderr, "(number of processes - 1) must be a multiple of %d\n", n);
+
+ MPI_Finalize();
+ return 1;
+ }
+
+ if (tid != 0) {
+ worker();
+ MPI_Barrier(MPI_COMM_WORLD);
+ MPI_Finalize();
+ } else {
+
+ /* master process */
+
+ chunk_size = n / (proc_cnt - 1);
+
+ for (i = 1: i < proc_cnt; i++) {
+ /* calculate each worker's boundary */
+ master_packet[JSTART] = (i - 1) * chunk_size;
+
+ if (i == proc_cnt - 1)
+ master_packet[JEND] = n - 1;
+ else
+ master_packet[JEND] = i * chunk_size - 1;
+
+ if (i == 1)
+ prv = proc_cnt-1;
+ else
+ prv = i-1;
+
+ master_packet[PREV] = prv;
+
+ if (i == proc_cnt - 1)
+ nxt = 1;
+ else
+ nxt = i+1;
+
+ master_packet[NEXT] = nxt;
+
+ MPI_Send(&master_packet, 4, MPI_INT, i, START_SIGNAL,
+ MPI_COMM_WORLD);
+
+ printf("jstart=%d, jend=%d, next=%d, prev=%d\n",
+ master_packet[JSTART],
+ master_packet[JEND],
+ master_packet[NEXT],
+ master_packet[PREV]);
+ }
+
+
+ /*
+ initialise data structures and construct packets to be sent to workers
+ */
+
+ initialise(p, u, v, psi, pold, uold, vold, di, dj, z);
+ diag(1, 0., p, u, v, h, z);
+
+ for (i = 1; i < proc_cnt; i++) {
+ for (j = 0; j < n; j++) {
+ acopy_two_to_one(p, p_start, j);
+ MPI_Send(&p_start, m, MPI_FLOAT, i, P_ROW,
+ MPI_COMM_WORLD);
+
+ acopy_two_to_one(u, u_start, j);
+ MPI_Send(&u_start, m, MPI_FLOAT, i, U_ROW,
+ MPI_COMM_WORLD);
+
+ acopy_two_to_one(v, v_start, j);
+ MPI_Send(&v_start, m, MPI_FLOAT, i, V_ROW,
+ MPI_COMM_WORLD);
+
+ acopy_two_to_one(psi, psi_start, j);
+ MPI_Send(&psi_start, m, MPI_FLOAT, i, PSI_ROW,
+ MPI_COMM_WORLD);
+
+ acopy_two_to_one(pold, pold_start, j);
+ MPI_Send(&pold_start, m, MPI_FLOAT, i, POLD_ROW,
+ MPI_COMM_WORLD);
+
+ acopy_two_to_one(uold, uold_start, j);
+ MPI_Send(&uold_start, m, MPI_FLOAT, i, UOLD_ROW,
+ MPI_COMM_WORLD);
+
+ acopy_two_to_one(vold, vold_start, j);
+ MPI_Send(&vold_start, m, MPI_FLOAT, i, VOLD_ROW,
+ MPI_COMM_WORLD);
+ }
+ }
+
+ /*
+ receive packets back from the workers
+ */
+ res_type = setup_res();
+
+ if ( debug & debug_master )
+ printf("receiving P\n");
+
+ update_global_ds(res_type, P_ROW, p);
+
+ if ( debug & debug_master )
+ printf("receiving U\n");
+
+ update_global_ds(res_type, U_ROW, u);
+
+ if ( debug & debug_master )
+ printf("receiving V\n");
+
+ update_global_ds(res_type, V_ROW, v);
+
+ if ( debug & debug_master )
+ printf("receiving H\n");
+
+ update_global_ds(res_type, H_ROW, h);
+
+ if ( debug & debug_master )
+ printf("receiving Z\n");
+
+ update_global_ds(res_type, Z_ROW, z);
+
+ for (i = 1; i < proc_cnt; i++){
+ MPI_Send(&master_packet, 4, MPI_INT, i, END_SIGNAL,
+ MPI_COMM_WORLD);
+ }
+
+ /* wait for all workers to end */
+ MPI_Barrier(MPI_COMM_WORLD);
+ MPI_Finalize();
+
+ diag(itmax, itmax*dt, p, u, v, h, z);
+ }
+
+ return 0;
+}
+
+MPI_Datatype *
+setup_res()
+{
+ struct res res;
+ MPI_Aint res_disp[2];
+ static int res_done = 0;
+ static int res_len[2] = { m, 1 };
+ static MPI_Datatype res_old[2] = { MPI_FLOAT, MPI_INT };
+ static MPI_Datatype res_type;
+
+ if ( res_done )
+ return &res_type;
+
+ res_done++;
+ MPI_Address(&res.row[0], &res_disp[0]);
+ MPI_Address(&res.indx, &res_disp[1]);
+ res_disp[1] -= res_disp[0];
+ res_disp[0] = 0;
+ MPI_Type_struct(2, res_len, res_disp, res_old, &res_type);
+ MPI_Type_commit(&res_type);
+
+ return &res_type;
+}
+
+/*
+this function waits for all the workers to return the packets of
+a particular type and then updates the master's copy of the same type
+*/
+update_global_ds(res_type, indx, ds)
+ MPI_Datatype * res_type;
+ int indx;
+ float ds[n][m];
+
+{
+ int i;
+ int row;
+ struct res res;
+ MPI_Status status;
+
+ for (i = 0; i < n; i++) {
+ MPI_Recv(&res, 1, *res_type, MPI_ANY_SOURCE, indx,
+ MPI_COMM_WORLD, &status);
+
+ acopy_one_to_two(res.row, ds, res.indx);
+ }
+
+}
diff --git a/samples/shallow-c/time.c b/samples/shallow-c/time.c
index f72718b..a30ee29 100644
--- a/samples/shallow-c/time.c
+++ b/samples/shallow-c/time.c
@@ -1,56 +1,56 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-
-#include "decs.h"
-
-void timetend(jstart,jend,dpdt,dudt,dvdt,cu,cv,h,z)
-int jstart,jend;
-float dudt[n][m];
-float dvdt[n][m];
-float dpdt[n][m];
-float z[n][m];
-float cv[n][m];
-float cu[n][m];
-float h[n][m];
-{
- int i,j,ip,jp;
- float invdx, invdy;
-
- invdx = 1./dx; invdy=1./dy;
- for(j=jstart;j<=jend;j++) {
- jp = (j+1) % n;
- for (i = 0; i < m; i++) {
- ip = (i+1) % m;
- /* ENERGY CONSERVING */
- dpdt[j][i] = -(cu[j][ip]-cu[j][i])*invdx - (cv[jp][i]-cv[j][i])*invdy;
- dudt[j][ip] =
- 0.125 * (z[jp][ip] * (cv[jp][ip] + cv[jp][i]) + z[j][ip] *
- (cv[j][ip]+cv[j][i])) - (h[j][ip] - h[j][i]) * invdx;
- dvdt[jp][i] =
- -0.125 * (z[jp][ip] * (cu[jp][ip] + cu[j][ip]) + z[jp][i] *
- (cu[jp][i]+cu[j][i])) - (h[jp][i] - h[j][i]) * invdy;
- }
- }
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+
+#include "decs.h"
+
+void timetend(jstart,jend,dpdt,dudt,dvdt,cu,cv,h,z)
+int jstart,jend;
+float dudt[n][m];
+float dvdt[n][m];
+float dpdt[n][m];
+float z[n][m];
+float cv[n][m];
+float cu[n][m];
+float h[n][m];
+{
+ int i,j,ip,jp;
+ float invdx, invdy;
+
+ invdx = 1./dx; invdy=1./dy;
+ for(j=jstart;j<=jend;j++) {
+ jp = (j+1) % n;
+ for (i = 0; i < m; i++) {
+ ip = (i+1) % m;
+ /* ENERGY CONSERVING */
+ dpdt[j][i] = -(cu[j][ip]-cu[j][i])*invdx - (cv[jp][i]-cv[j][i])*invdy;
+ dudt[j][ip] =
+ 0.125 * (z[jp][ip] * (cv[jp][ip] + cv[jp][i]) + z[j][ip] *
+ (cv[j][ip]+cv[j][i])) - (h[j][ip] - h[j][i]) * invdx;
+ dvdt[jp][i] =
+ -0.125 * (z[jp][ip] * (cu[jp][ip] + cu[j][ip]) + z[jp][i] *
+ (cu[jp][i]+cu[j][i])) - (h[jp][i] - h[j][i]) * invdy;
+ }
+ }
+}
diff --git a/samples/shallow-c/tstep.c b/samples/shallow-c/tstep.c
index ae035aa..14f5c7b 100644
--- a/samples/shallow-c/tstep.c
+++ b/samples/shallow-c/tstep.c
@@ -1,77 +1,77 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-
-#include "decs.h"
-
-void tstep(
-int m_,
-int n_,
-float alpha_,
-int jstart,
-int jend,
-float pold[n][m],
-float uold[n][m],
-float vold[n][m],
-float p[n][m],
-float u[n][m],
-float v[n][m],
-float pnew[n][m],
-float unew[n][m],
-float vnew[n][m],
-float dpdt[n][m],
-float dudt[n][m],
-float dvdt[n][m],
-int firststep,
-float tdt)
-{
- int i,j;
-
- for (j = jstart; j <= jend; j++){
- for (i = 0; i < m; i++){
- pnew[j][i] = pold[j][i] + tdt*dpdt[j][i];
- unew[j][i] = uold[j][i] + tdt*dudt[j][i];
- vnew[j][i] = vold[j][i] + tdt*dvdt[j][i];
- }
- }
-
- /* Don't apply time filter on first step */
- if ( !firststep ) {
- for (j = jstart; j <= jend; j++) {
- for (i = 0; i < m; i++) {
- pold[j][i] = p[j][i]+alpha*(pnew[j][i]-2.*p[j][i]+pold[j][i]);
- uold[j][i] = u[j][i]+alpha*(unew[j][i]-2.*u[j][i]+uold[j][i]);
- vold[j][i] = v[j][i]+alpha*(vnew[j][i]-2.*v[j][i]+vold[j][i]);
- }
- }
- }
-
- for (j = jstart; j <= jend; j++) {
- for (i = 0; i < m; i++) {
- p[j][i] = pnew[j][i];
- u[j][i] = unew[j][i];
- v[j][i] = vnew[j][i];
- }
- }
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+
+#include "decs.h"
+
+void tstep(
+int m_,
+int n_,
+float alpha_,
+int jstart,
+int jend,
+float pold[n][m],
+float uold[n][m],
+float vold[n][m],
+float p[n][m],
+float u[n][m],
+float v[n][m],
+float pnew[n][m],
+float unew[n][m],
+float vnew[n][m],
+float dpdt[n][m],
+float dudt[n][m],
+float dvdt[n][m],
+int firststep,
+float tdt)
+{
+ int i,j;
+
+ for (j = jstart; j <= jend; j++){
+ for (i = 0; i < m; i++){
+ pnew[j][i] = pold[j][i] + tdt*dpdt[j][i];
+ unew[j][i] = uold[j][i] + tdt*dudt[j][i];
+ vnew[j][i] = vold[j][i] + tdt*dvdt[j][i];
+ }
+ }
+
+ /* Don't apply time filter on first step */
+ if ( !firststep ) {
+ for (j = jstart; j <= jend; j++) {
+ for (i = 0; i < m; i++) {
+ pold[j][i] = p[j][i]+alpha*(pnew[j][i]-2.*p[j][i]+pold[j][i]);
+ uold[j][i] = u[j][i]+alpha*(unew[j][i]-2.*u[j][i]+uold[j][i]);
+ vold[j][i] = v[j][i]+alpha*(vnew[j][i]-2.*v[j][i]+vold[j][i]);
+ }
+ }
+ }
+
+ for (j = jstart; j <= jend; j++) {
+ for (i = 0; i < m; i++) {
+ p[j][i] = pnew[j][i];
+ u[j][i] = unew[j][i];
+ v[j][i] = vnew[j][i];
+ }
+ }
+}
diff --git a/samples/shallow-c/worker.c b/samples/shallow-c/worker.c
index 31a97c5..ae51680 100644
--- a/samples/shallow-c/worker.c
+++ b/samples/shallow-c/worker.c
@@ -1,358 +1,358 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-
-#include <math.h>
-#include <mpi.h>
-#include <stdio.h>
-#include "decs.h"
-
-MPI_Datatype * setup_res();
-
-extern void tstep(
-int m_,
-int n_,
-float alpha_,
-int jstart,
-int jend,
-float pold[n][m],
-float uold[n][m],
-float vold[n][m],
-float p[n][m],
-float u[n][m],
-float v[n][m],
-float pnew[n][m],
-float unew[n][m],
-float vnew[n][m],
-float dpdt[n][m],
-float dudt[n][m],
-float dvdt[n][m],
-int firststep,
-float tdt);
-
-void
-worker()
-{
- int firststep, ncycle;
- float tdt, time;
- int i,j,ip,jp,jstart,jend;
- int prv;
- int nxt;
-
- int msg_type;
- int master_id, my_id;
- int nprocs;
- int nbytes;
-
- float p[n][m]; /* Pressure (or free surface height) */
- float u[n][m]; /* Zonal wind */
- float v[n][m]; /* Meridional wind */
- float psi[n][m]; /* Velocity streamfunction */
- float pold[n][m];
- float uold[n][m];
- float vold[n][m];
- float pnew[n][m];
- float unew[n][m];
- float vnew[n][m];
- float dpdt[n][m];
- float dudt[n][m]; /* Time tendency of u */
- float dvdt[n][m];
- float cu[n][m]; /* Mass weighted u */
- float cv[n][m]; /* Mass weighted v */
- float h[n][m];
- float z[n][m]; /* Potential enstrophy */
- float dummy1[m];
- float dummy2[n];
- float fsdx = 4./dx;
- float fsdy = 4./dy;
-
- int worker[4];
- float p_start[m];
- float u_start[m];
- float v_start[m];
- float psi_start[m];
- float pold_start[m];
- float uold_start[m];
- float vold_start[m];
- MPI_Datatype * res_type;
- MPI_Status status;
-
- /*
- initialise control variables
- */
-
- firststep = 1;
- ncycle = 0;
- tdt = dt;
- time = 0.;
-
- /*
- set up environment for worker
- */
-
- MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
- MPI_Comm_rank(MPI_COMM_WORLD, &my_id);
-
- MPI_Recv(&worker, 4, MPI_INT, MPI_ANY_SOURCE, START_SIGNAL,
- MPI_COMM_WORLD, &status);
-
- prv = worker[PREV];
- nxt = worker[NEXT];
- jstart = worker[JSTART];
- jend = worker[JEND];
-
- /*
- receive initialisation packets from master
- */
-
- for (i = 0; i < n; i++){
- MPI_Recv(&p_start, m, MPI_FLOAT, 0, P_ROW,
- MPI_COMM_WORLD, &status);
- acopy_one_to_two(p_start, p, i);
-
- MPI_Recv(&u_start, m, MPI_FLOAT, 0, U_ROW,
- MPI_COMM_WORLD, &status);
- acopy_one_to_two(u_start, u, i);
-
- MPI_Recv(&v_start, m, MPI_FLOAT, 0, V_ROW,
- MPI_COMM_WORLD, &status);
- acopy_one_to_two(v_start, v, i);
-
- MPI_Recv(&psi_start, m, MPI_FLOAT, 0, PSI_ROW,
- MPI_COMM_WORLD, &status);
- acopy_one_to_two(psi_start, psi, i);
-
- MPI_Recv(&pold_start, m, MPI_FLOAT, 0, POLD_ROW,
- MPI_COMM_WORLD, &status);
- acopy_one_to_two(pold_start, pold, i);
-
- MPI_Recv(&uold_start, m, MPI_FLOAT, 0, UOLD_ROW,
- MPI_COMM_WORLD, &status);
- acopy_one_to_two(uold_start, uold, i);
-
- MPI_Recv(&vold_start, m, MPI_FLOAT, 0, VOLD_ROW,
- MPI_COMM_WORLD, &status);
- acopy_one_to_two(vold_start, vold, i);
- }
-
- while (ncycle < itmax) {
- /*
- loop over latitudes calculating U, V, z and h
- do the block of latitudes from jstart to jend inclusive
- */
-
- calc_load(prv, nxt, my_id, jstart, jend, p, u,v);
- calcuvzh(jstart, jend, p, u, v, cu, cv, h, z, fsdx, fsdy);
- calc_unload(prv, nxt, my_id, jstart, jend, cv, z);
-
-
- /*
- Calculate time tendencies of p, u and v
- */
-
- time_load(prv, nxt, my_id, jstart, jend, cu, cv, h, z);
- timetend(jstart, jend, dpdt, dudt, dvdt, cu, cv, h, z);
- time_unload(prv, nxt, my_id, jstart, jend, dvdt);
-
- if ((my_id == 1) && (ncycle%mprint==0)) {
- diag(ncycle, time, p, u, v, h, z);
- }
-
- time += dt;
-
- tstep(m, n, alpha,
- jstart, jend, pold, uold, vold, p, u, v, pnew,
- unew, vnew, dpdt, dudt, dvdt, firststep, tdt);
-
- if ( firststep ) {
- /* Double tdt because all future steps are leapfrog */
- firststep = 0;
- tdt = tdt+tdt;
- }
-
- ncycle++;
- } /* End of time step loop */
-
- /*
- send local data structures (results) back to master
- */
-
- res_type = setup_res();
-
- send_updated_ds(res_type, jstart, jend, p, P_ROW, 0);
- send_updated_ds(res_type, jstart, jend, u, U_ROW, 0);
- send_updated_ds(res_type, jstart, jend, v, V_ROW, 0);
- send_updated_ds(res_type, jstart, jend, h, H_ROW, 0);
- send_updated_ds(res_type, jstart, jend, z, Z_ROW, 0);
-
- MPI_Recv(&worker, 4, MPI_INT, 0, END_SIGNAL,
- MPI_COMM_WORLD, &status);
-
- if (debug & debug_call) {
- printf("worker %d sent TIDY_UP to master\n", my_id);
- printf("worker %d got END_SIGNAL from master\n", my_id);
- }
-}
-
-send_updated_ds(res_type, jstart, jend, ds, indx, master_id)
- MPI_Datatype * res_type;
- int jstart;
- int jend;
- float ds[n][m];
- int indx;
- int master_id;
-{
- int j;
- struct res res;
- MPI_Request rq[2];
- MPI_Status stat[2];
-
- for (j = jstart; j <= jend; j++) {
- acopy_two_to_one(ds, res.row, j);
- res.indx = j;
-
- MPI_Send(&res, 1, *res_type, master_id, indx,
- MPI_COMM_WORLD);
- }
-}
-
-/*
-this procedure does all the message passing before the call to _calcuvzh_
-*/
-calc_load(prv,nxt,my_id,jstart,jend,p,u,v)
- int prv;
- int nxt;
- int my_id;
- int jstart;
- int jend;
- float p[n][m];
- float u[n][m];
- float v[n][m];
-{
- neighbour_send(prv, my_id, CALC1a, p, jstart);
- neighbour_send(prv, my_id, CALC1b, u, jstart);
- neighbour_send(prv, my_id, CALC1c, v, jstart);
- neighbour_receive(nxt, my_id, CALC1a, p, (jend+1) % n);
- neighbour_receive(nxt, my_id, CALC1b, u, (jend+1) % n);
- neighbour_receive(nxt, my_id, CALC1c, v, (jend+1) % n);
-}
-
-/*
-this procedure does all the message passing after the call to _calcuvzh_
-*/
-calc_unload(prv,nxt,my_id,jstart,jend,cv,z)
- int prv;
- int nxt;
- int my_id;
- int jstart;
- int jend;
- float cv[n][m];
- float z[n][m];
-{
- neighbour_send(nxt, my_id, CALC2a, cv, (jend+1) % n);
- neighbour_send(nxt, my_id, CALC2b, z, (jend+1) % n);
- neighbour_receive(prv, my_id, CALC2a, cv, jstart);
- neighbour_receive(prv, my_id, CALC2b, z, jstart);
-}
-
-/*
-this procedure does all the message passing before the call to _timetend_
-*/
-time_load(prv,nxt,my_id,jstart,jend,cu,cv,h,z)
- int prv;
- int nxt;
- int my_id;
- int jstart;
- int jend;
- float cu[n][m];
- float cv[n][m];
- float h[n][m];
- float z[n][m];
-{
- neighbour_send(prv, my_id, TIME1a, cu, jstart);
- neighbour_send(prv, my_id, TIME1b, cv, jstart);
- neighbour_send(prv, my_id, TIME1c, h, jstart);
- neighbour_send(prv, my_id, TIME1d, z, jstart);
- neighbour_receive(nxt, my_id, TIME1a, cu, (jend+1) % n);
- neighbour_receive(nxt, my_id, TIME1b, cv, (jend+1) % n);
- neighbour_receive(nxt, my_id, TIME1c, h, (jend+1) % n);
- neighbour_receive(nxt, my_id, TIME1d, z, (jend+1) % n);
-}
-
-/*
-this procedure does all the message passing after the call to _timetend_
-*/
-time_unload(prv,nxt,tu_my_id,jstart,jend,dvdt)
- int prv;
- int nxt;
- int tu_my_id;
- int jstart;
- int jend;
- float dvdt[n][m];
-{
- neighbour_send(nxt, tu_my_id, TIME2, dvdt, (jend+1) % n);
- neighbour_receive(prv, tu_my_id, TIME2, dvdt, jstart);
-}
-
-/*
-this is a general purpose function for sending packets b/w workers
-*/
-neighbour_send(ns_neighbour,ns_my_id,ns_rec_id,ns_ds,ns_edge)
- int ns_neighbour;
- int ns_my_id;
- int ns_rec_id;
- float ns_ds[n][m];
- int ns_edge;
-{
- float ns_rec[m];
- MPI_Request rq;
-
- acopy_two_to_one(ns_ds, ns_rec, ns_edge);
-
- MPI_Isend(&ns_rec, m, MPI_FLOAT, ns_neighbour, ns_rec_id,
- MPI_COMM_WORLD, &rq);
-
- if (debug & debug_worker)
- printf("worker %d sent packet %d to worker %d\n", ns_my_id,
- ns_rec_id, ns_neighbour);
-}
-
-/*
-this is a general purpose function for receiving packets b/w workers
-*/
-neighbour_receive(nr_neighbour,nr_my_id,nr_rec_id,nr_ds,nr_edge)
- int nr_neighbour;
- int nr_my_id;
- int nr_rec_id;
- float nr_ds[n][m];
- int nr_edge;
-{
- float nr_rec[m];
- MPI_Status status;
-
- MPI_Recv(&nr_rec, m, MPI_FLOAT, nr_neighbour, nr_rec_id,
- MPI_COMM_WORLD, &status);
-
- acopy_one_to_two(nr_rec, nr_ds, nr_edge);
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+
+#include <math.h>
+#include <mpi.h>
+#include <stdio.h>
+#include "decs.h"
+
+MPI_Datatype * setup_res();
+
+extern void tstep(
+int m_,
+int n_,
+float alpha_,
+int jstart,
+int jend,
+float pold[n][m],
+float uold[n][m],
+float vold[n][m],
+float p[n][m],
+float u[n][m],
+float v[n][m],
+float pnew[n][m],
+float unew[n][m],
+float vnew[n][m],
+float dpdt[n][m],
+float dudt[n][m],
+float dvdt[n][m],
+int firststep,
+float tdt);
+
+void
+worker()
+{
+ int firststep, ncycle;
+ float tdt, time;
+ int i,j,ip,jp,jstart,jend;
+ int prv;
+ int nxt;
+
+ int msg_type;
+ int master_id, my_id;
+ int nprocs;
+ int nbytes;
+
+ float p[n][m]; /* Pressure (or free surface height) */
+ float u[n][m]; /* Zonal wind */
+ float v[n][m]; /* Meridional wind */
+ float psi[n][m]; /* Velocity streamfunction */
+ float pold[n][m];
+ float uold[n][m];
+ float vold[n][m];
+ float pnew[n][m];
+ float unew[n][m];
+ float vnew[n][m];
+ float dpdt[n][m];
+ float dudt[n][m]; /* Time tendency of u */
+ float dvdt[n][m];
+ float cu[n][m]; /* Mass weighted u */
+ float cv[n][m]; /* Mass weighted v */
+ float h[n][m];
+ float z[n][m]; /* Potential enstrophy */
+ float dummy1[m];
+ float dummy2[n];
+ float fsdx = 4./dx;
+ float fsdy = 4./dy;
+
+ int worker[4];
+ float p_start[m];
+ float u_start[m];
+ float v_start[m];
+ float psi_start[m];
+ float pold_start[m];
+ float uold_start[m];
+ float vold_start[m];
+ MPI_Datatype * res_type;
+ MPI_Status status;
+
+ /*
+ initialise control variables
+ */
+
+ firststep = 1;
+ ncycle = 0;
+ tdt = dt;
+ time = 0.;
+
+ /*
+ set up environment for worker
+ */
+
+ MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+ MPI_Comm_rank(MPI_COMM_WORLD, &my_id);
+
+ MPI_Recv(&worker, 4, MPI_INT, MPI_ANY_SOURCE, START_SIGNAL,
+ MPI_COMM_WORLD, &status);
+
+ prv = worker[PREV];
+ nxt = worker[NEXT];
+ jstart = worker[JSTART];
+ jend = worker[JEND];
+
+ /*
+ receive initialisation packets from master
+ */
+
+ for (i = 0; i < n; i++){
+ MPI_Recv(&p_start, m, MPI_FLOAT, 0, P_ROW,
+ MPI_COMM_WORLD, &status);
+ acopy_one_to_two(p_start, p, i);
+
+ MPI_Recv(&u_start, m, MPI_FLOAT, 0, U_ROW,
+ MPI_COMM_WORLD, &status);
+ acopy_one_to_two(u_start, u, i);
+
+ MPI_Recv(&v_start, m, MPI_FLOAT, 0, V_ROW,
+ MPI_COMM_WORLD, &status);
+ acopy_one_to_two(v_start, v, i);
+
+ MPI_Recv(&psi_start, m, MPI_FLOAT, 0, PSI_ROW,
+ MPI_COMM_WORLD, &status);
+ acopy_one_to_two(psi_start, psi, i);
+
+ MPI_Recv(&pold_start, m, MPI_FLOAT, 0, POLD_ROW,
+ MPI_COMM_WORLD, &status);
+ acopy_one_to_two(pold_start, pold, i);
+
+ MPI_Recv(&uold_start, m, MPI_FLOAT, 0, UOLD_ROW,
+ MPI_COMM_WORLD, &status);
+ acopy_one_to_two(uold_start, uold, i);
+
+ MPI_Recv(&vold_start, m, MPI_FLOAT, 0, VOLD_ROW,
+ MPI_COMM_WORLD, &status);
+ acopy_one_to_two(vold_start, vold, i);
+ }
+
+ while (ncycle < itmax) {
+ /*
+ loop over latitudes calculating U, V, z and h
+ do the block of latitudes from jstart to jend inclusive
+ */
+
+ calc_load(prv, nxt, my_id, jstart, jend, p, u,v);
+ calcuvzh(jstart, jend, p, u, v, cu, cv, h, z, fsdx, fsdy);
+ calc_unload(prv, nxt, my_id, jstart, jend, cv, z);
+
+
+ /*
+ Calculate time tendencies of p, u and v
+ */
+
+ time_load(prv, nxt, my_id, jstart, jend, cu, cv, h, z);
+ timetend(jstart, jend, dpdt, dudt, dvdt, cu, cv, h, z);
+ time_unload(prv, nxt, my_id, jstart, jend, dvdt);
+
+ if ((my_id == 1) && (ncycle%mprint==0)) {
+ diag(ncycle, time, p, u, v, h, z);
+ }
+
+ time += dt;
+
+ tstep(m, n, alpha,
+ jstart, jend, pold, uold, vold, p, u, v, pnew,
+ unew, vnew, dpdt, dudt, dvdt, firststep, tdt);
+
+ if ( firststep ) {
+ /* Double tdt because all future steps are leapfrog */
+ firststep = 0;
+ tdt = tdt+tdt;
+ }
+
+ ncycle++;
+ } /* End of time step loop */
+
+ /*
+ send local data structures (results) back to master
+ */
+
+ res_type = setup_res();
+
+ send_updated_ds(res_type, jstart, jend, p, P_ROW, 0);
+ send_updated_ds(res_type, jstart, jend, u, U_ROW, 0);
+ send_updated_ds(res_type, jstart, jend, v, V_ROW, 0);
+ send_updated_ds(res_type, jstart, jend, h, H_ROW, 0);
+ send_updated_ds(res_type, jstart, jend, z, Z_ROW, 0);
+
+ MPI_Recv(&worker, 4, MPI_INT, 0, END_SIGNAL,
+ MPI_COMM_WORLD, &status);
+
+ if (debug & debug_call) {
+ printf("worker %d sent TIDY_UP to master\n", my_id);
+ printf("worker %d got END_SIGNAL from master\n", my_id);
+ }
+}
+
+send_updated_ds(res_type, jstart, jend, ds, indx, master_id)
+ MPI_Datatype * res_type;
+ int jstart;
+ int jend;
+ float ds[n][m];
+ int indx;
+ int master_id;
+{
+ int j;
+ struct res res;
+ MPI_Request rq[2];
+ MPI_Status stat[2];
+
+ for (j = jstart; j <= jend; j++) {
+ acopy_two_to_one(ds, res.row, j);
+ res.indx = j;
+
+ MPI_Send(&res, 1, *res_type, master_id, indx,
+ MPI_COMM_WORLD);
+ }
+}
+
+/*
+this procedure does all the message passing before the call to _calcuvzh_
+*/
+calc_load(prv,nxt,my_id,jstart,jend,p,u,v)
+ int prv;
+ int nxt;
+ int my_id;
+ int jstart;
+ int jend;
+ float p[n][m];
+ float u[n][m];
+ float v[n][m];
+{
+ neighbour_send(prv, my_id, CALC1a, p, jstart);
+ neighbour_send(prv, my_id, CALC1b, u, jstart);
+ neighbour_send(prv, my_id, CALC1c, v, jstart);
+ neighbour_receive(nxt, my_id, CALC1a, p, (jend+1) % n);
+ neighbour_receive(nxt, my_id, CALC1b, u, (jend+1) % n);
+ neighbour_receive(nxt, my_id, CALC1c, v, (jend+1) % n);
+}
+
+/*
+this procedure does all the message passing after the call to _calcuvzh_
+*/
+calc_unload(prv,nxt,my_id,jstart,jend,cv,z)
+ int prv;
+ int nxt;
+ int my_id;
+ int jstart;
+ int jend;
+ float cv[n][m];
+ float z[n][m];
+{
+ neighbour_send(nxt, my_id, CALC2a, cv, (jend+1) % n);
+ neighbour_send(nxt, my_id, CALC2b, z, (jend+1) % n);
+ neighbour_receive(prv, my_id, CALC2a, cv, jstart);
+ neighbour_receive(prv, my_id, CALC2b, z, jstart);
+}
+
+/*
+this procedure does all the message passing before the call to _timetend_
+*/
+time_load(prv,nxt,my_id,jstart,jend,cu,cv,h,z)
+ int prv;
+ int nxt;
+ int my_id;
+ int jstart;
+ int jend;
+ float cu[n][m];
+ float cv[n][m];
+ float h[n][m];
+ float z[n][m];
+{
+ neighbour_send(prv, my_id, TIME1a, cu, jstart);
+ neighbour_send(prv, my_id, TIME1b, cv, jstart);
+ neighbour_send(prv, my_id, TIME1c, h, jstart);
+ neighbour_send(prv, my_id, TIME1d, z, jstart);
+ neighbour_receive(nxt, my_id, TIME1a, cu, (jend+1) % n);
+ neighbour_receive(nxt, my_id, TIME1b, cv, (jend+1) % n);
+ neighbour_receive(nxt, my_id, TIME1c, h, (jend+1) % n);
+ neighbour_receive(nxt, my_id, TIME1d, z, (jend+1) % n);
+}
+
+/*
+this procedure does all the message passing after the call to _timetend_
+*/
+time_unload(prv,nxt,tu_my_id,jstart,jend,dvdt)
+ int prv;
+ int nxt;
+ int tu_my_id;
+ int jstart;
+ int jend;
+ float dvdt[n][m];
+{
+ neighbour_send(nxt, tu_my_id, TIME2, dvdt, (jend+1) % n);
+ neighbour_receive(prv, tu_my_id, TIME2, dvdt, jstart);
+}
+
+/*
+this is a general purpose function for sending packets b/w workers
+*/
+neighbour_send(ns_neighbour,ns_my_id,ns_rec_id,ns_ds,ns_edge)
+ int ns_neighbour;
+ int ns_my_id;
+ int ns_rec_id;
+ float ns_ds[n][m];
+ int ns_edge;
+{
+ float ns_rec[m];
+ MPI_Request rq;
+
+ acopy_two_to_one(ns_ds, ns_rec, ns_edge);
+
+ MPI_Isend(&ns_rec, m, MPI_FLOAT, ns_neighbour, ns_rec_id,
+ MPI_COMM_WORLD, &rq);
+
+ if (debug & debug_worker)
+ printf("worker %d sent packet %d to worker %d\n", ns_my_id,
+ ns_rec_id, ns_neighbour);
+}
+
+/*
+this is a general purpose function for receiving packets b/w workers
+*/
+neighbour_receive(nr_neighbour,nr_my_id,nr_rec_id,nr_ds,nr_edge)
+ int nr_neighbour;
+ int nr_my_id;
+ int nr_rec_id;
+ float nr_ds[n][m];
+ int nr_edge;
+{
+ float nr_rec[m];
+ MPI_Status status;
+
+ MPI_Recv(&nr_rec, m, MPI_FLOAT, nr_neighbour, nr_rec_id,
+ MPI_COMM_WORLD, &status);
+
+ acopy_one_to_two(nr_rec, nr_ds, nr_edge);
+}
diff --git a/samples/shallow-mixed/Makefile.mk b/samples/shallow-mixed/Makefile.mk
index bd01b0a..daee61b 100644
--- a/samples/shallow-mixed/Makefile.mk
+++ b/samples/shallow-mixed/Makefile.mk
@@ -1,35 +1,35 @@
-#
-
-CC = mpicc
-CFLAGS = -g
-FC = mpif90
-FFLAGS = -g
-LIB = -lifcore -limf -ldl
-
-SOURCES = calc.c copy.c diag.c init.c main.c time.c tstep.f90 worker.c dump.c
-OBJECTS = calc.o copy.o diag.o init.o main.o time.o tstep.o worker.o dump.o
-HEADERS = decs.h
-
-all: shallow
-
-shallow: $(OBJECTS) $(HEADERS)
- $(CC) $(CFLAGS) -o shallow $(OBJECTS) -lm $(LIB)
-
-tags: $(SOURCES) $(HEADERS)
- ctags -w $(SOURCES) $(HEADERS)
-
-clean:
- -rm -f shallow $(OBJECTS) core
-
-calc.o: calc.c decs.h
-copy.o: copy.c decs.h
-diag.o: diag.c decs.h
-init.o: init.c decs.h
-main.o: main.c decs.h
-time.o: time.c decs.h
-
-tstep.o: tstep.f90
- $(FC) $(FFLAGS) -c -o $@ $<
-
-worker.o: worker.c decs.h
-dump.o: dump.c decs.h
+#
+
+CC = mpicc
+CFLAGS = -g
+FC = mpif90
+FFLAGS = -g
+LIB = -lifcore -limf -ldl
+
+SOURCES = calc.c copy.c diag.c init.c main.c time.c tstep.f90 worker.c dump.c
+OBJECTS = calc.o copy.o diag.o init.o main.o time.o tstep.o worker.o dump.o
+HEADERS = decs.h
+
+all: shallow
+
+shallow: $(OBJECTS) $(HEADERS)
+ $(CC) $(CFLAGS) -o shallow $(OBJECTS) -lm $(LIB)
+
+tags: $(SOURCES) $(HEADERS)
+ ctags -w $(SOURCES) $(HEADERS)
+
+clean:
+ -rm -f shallow $(OBJECTS) core
+
+calc.o: calc.c decs.h
+copy.o: copy.c decs.h
+diag.o: diag.c decs.h
+init.o: init.c decs.h
+main.o: main.c decs.h
+time.o: time.c decs.h
+
+tstep.o: tstep.f90
+ $(FC) $(FFLAGS) -c -o $@ $<
+
+worker.o: worker.c decs.h
+dump.o: dump.c decs.h
diff --git a/samples/shallow-mixed/calc.c b/samples/shallow-mixed/calc.c
index e0de89d..3a326c7 100644
--- a/samples/shallow-mixed/calc.c
+++ b/samples/shallow-mixed/calc.c
@@ -1,53 +1,53 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-
-#include "decs.h"
-
-void calcuvzh(jstart,jend,p,u,v,cu,cv,h,z,fsdx,fsdy)
-int jstart,jend;
-float p[n][m];
-float u[n][m];
-float v[n][m];
-float cu[n][m];
-float cv[n][m];
-float h[n][m];
-float z[n][m];
-float fsdx, fsdy;
-{
- int i,j,ip,jp;
-
- for(j=jstart;j<=jend;j++) {
- jp = (j+1) % n;
- for (i = 0; i < m; i++){
- ip = (i+1) % m;
- cu[j][ip] = 0.5*(p[j][ip]+p[j][i])*u[j][ip];
- cv[jp][i] = 0.5*(p[jp][i]+p[j][i])*v[jp][i];
- z[jp][ip] = (fsdx*(v[jp][ip]-v[jp][i])-fsdy*(u[jp][ip]
- -u[j][ip]))/(p[j][i]+p[j][ip]+p[jp][ip]+p[jp][i]);
- h[j][i] = p[j][i]+0.25*(u[j][ip]*u[j][ip]+u[j][i]*u[j][i]
- +v[jp][i]*v[jp][i]+v[j][i]*v[j][i]);
- }
- }
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+
+#include "decs.h"
+
+void calcuvzh(jstart,jend,p,u,v,cu,cv,h,z,fsdx,fsdy)
+int jstart,jend;
+float p[n][m];
+float u[n][m];
+float v[n][m];
+float cu[n][m];
+float cv[n][m];
+float h[n][m];
+float z[n][m];
+float fsdx, fsdy;
+{
+ int i,j,ip,jp;
+
+ for(j=jstart;j<=jend;j++) {
+ jp = (j+1) % n;
+ for (i = 0; i < m; i++){
+ ip = (i+1) % m;
+ cu[j][ip] = 0.5*(p[j][ip]+p[j][i])*u[j][ip];
+ cv[jp][i] = 0.5*(p[jp][i]+p[j][i])*v[jp][i];
+ z[jp][ip] = (fsdx*(v[jp][ip]-v[jp][i])-fsdy*(u[jp][ip]
+ -u[j][ip]))/(p[j][i]+p[j][ip]+p[jp][ip]+p[jp][i]);
+ h[j][i] = p[j][i]+0.25*(u[j][ip]*u[j][ip]+u[j][i]*u[j][i]
+ +v[jp][i]*v[jp][i]+v[j][i]*v[j][i]);
+ }
+ }
+}
diff --git a/samples/shallow-mixed/copy.c b/samples/shallow-mixed/copy.c
index 052f5c0..9fcb945 100644
--- a/samples/shallow-mixed/copy.c
+++ b/samples/shallow-mixed/copy.c
@@ -1,91 +1,91 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-#include <strings.h>
-#include "decs.h"
-
-twod_acopy(src,dest)
-float src[n][m];
-float dest[n][m];
-{
- int i, j;
-
- /*
- for (i = 0; i < m; i++) {
- for (j = 0; j < n; j++) {
- dest[j][i] = src[j][i];
- }
- }
- */
- for (j = 0; j < n; j++)
- bcopy(src[j], dest[j], sizeof(src[j]));
-}
-
-twod_acopy_column(src,dest,column)
-float src[n][m];
-float dest[n][m];
-int column;
-/*
-This now does a ROW COPY and not a column copy
-*/
-{
- int i;
-
- /*
- for (i = 0; i < m; i++)
- dest[column][i] = src[column][i];
- */
- bcopy(src[column], dest[column], sizeof(src[column]));
-}
-
-acopy_two_to_one(twodim,onedim,column)
-float twodim[n][m];
-float onedim[m];
-int column;
-/*
-This now does a ROW COPY and not a column copy
-*/
-{
- int i;
-
- /*
- for (i = 0; i < m; i++)
- onedim[i] = twodim[column][i];
- */
- bcopy(twodim[column], onedim, sizeof(twodim[column]));
-}
-
-acopy_one_to_two(onedim,twodim,column)
-float twodim[n][m];
-float onedim[m];
-int column;
-{
- int i;
-
- /*
- for (i = 0; i < m; i++)
- twodim[column][i] = onedim[i];
- */
- bcopy(onedim, twodim[column], sizeof(twodim[column]));
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+#include <strings.h>
+#include "decs.h"
+
+twod_acopy(src,dest)
+float src[n][m];
+float dest[n][m];
+{
+ int i, j;
+
+ /*
+ for (i = 0; i < m; i++) {
+ for (j = 0; j < n; j++) {
+ dest[j][i] = src[j][i];
+ }
+ }
+ */
+ for (j = 0; j < n; j++)
+ bcopy(src[j], dest[j], sizeof(src[j]));
+}
+
+twod_acopy_column(src,dest,column)
+float src[n][m];
+float dest[n][m];
+int column;
+/*
+This now does a ROW COPY and not a column copy
+*/
+{
+ int i;
+
+ /*
+ for (i = 0; i < m; i++)
+ dest[column][i] = src[column][i];
+ */
+ bcopy(src[column], dest[column], sizeof(src[column]));
+}
+
+acopy_two_to_one(twodim,onedim,column)
+float twodim[n][m];
+float onedim[m];
+int column;
+/*
+This now does a ROW COPY and not a column copy
+*/
+{
+ int i;
+
+ /*
+ for (i = 0; i < m; i++)
+ onedim[i] = twodim[column][i];
+ */
+ bcopy(twodim[column], onedim, sizeof(twodim[column]));
+}
+
+acopy_one_to_two(onedim,twodim,column)
+float twodim[n][m];
+float onedim[m];
+int column;
+{
+ int i;
+
+ /*
+ for (i = 0; i < m; i++)
+ twodim[column][i] = onedim[i];
+ */
+ bcopy(onedim, twodim[column], sizeof(twodim[column]));
+}
diff --git a/samples/shallow-mixed/decs.h b/samples/shallow-mixed/decs.h
index b302a9b..f815667 100644
--- a/samples/shallow-mixed/decs.h
+++ b/samples/shallow-mixed/decs.h
@@ -1,97 +1,97 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-
-#define m 32 /* 18 Number of points in x direction */
-#define n 32 /* 18 Number of points in y direction */
-#define a 1.e6 /* Nominally the radius of the earth but here just
- a length scale*/
-#define dt 90.0 /* Time step in seconds */
-#define secs_pd 86400. /* Seconds per day */
-#define dx 1.e5 /* Grid spacing in x direction */
-#define dy 1.e5 /* Grid spacing in y direction */
-#define alpha 0.001 /* Asselin time filter parameter */
-#define itmax 1000 /* Number of time steps in run */
-#define mprint 50 /* Print diagnostics every mprint steps */
-
-#define lower 1 /* low bound of range of processors */
-#define upper 20 /* hi bound of range of processors */
-#define version 0.6 /* version number of program */
-
-/* constants used by dump() to determine what data structure to print */
-#define one_dim 1
-#define two_dim 2
-#define p_label 0
-#define u_label 1
-#define v_label 2
-#define pold_label 3
-#define uold_label 4
-#define vold_label 5
-#define psi_label 6
-#define cu_label 7
-#define cv_label 8
-#define h_label 9
-#define z_label 10
-#define dudt_label 11
-#define dvdt_label 12
-
-/* message types */
-#define START_SIGNAL 0
-#define END_SIGNAL 4
-#define CALC1a 20
-#define CALC1b 21
-#define CALC1c 22
-#define CALC2a 23
-#define CALC2b 24
-#define TIME1a 30
-#define TIME1b 31
-#define TIME1c 32
-#define TIME1d 33
-#define TIME2 34
-#define P_ROW 50
-#define U_ROW 51
-#define V_ROW 52
-#define PSI_ROW 53
-#define POLD_ROW 54
-#define UOLD_ROW 55
-#define VOLD_ROW 56
-#define H_ROW 57
-#define Z_ROW 58
-
-#define PREV 0
-#define NEXT 1
-#define JSTART 2
-#define JEND 3
-
-#define debug_data 0x1
-#define debug_master 0x2
-#define debug_worker 0x4
-#define debug_call 0x8
-#define debug 0x0
-
-struct res
-{
- float row[m];
- int indx;
-};
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+
+#define m 32 /* 18 Number of points in x direction */
+#define n 32 /* 18 Number of points in y direction */
+#define a 1.e6 /* Nominally the radius of the earth but here just
+ a length scale*/
+#define dt 90.0 /* Time step in seconds */
+#define secs_pd 86400. /* Seconds per day */
+#define dx 1.e5 /* Grid spacing in x direction */
+#define dy 1.e5 /* Grid spacing in y direction */
+#define alpha 0.001 /* Asselin time filter parameter */
+#define itmax 1000 /* Number of time steps in run */
+#define mprint 50 /* Print diagnostics every mprint steps */
+
+#define lower 1 /* low bound of range of processors */
+#define upper 20 /* hi bound of range of processors */
+#define version 0.6 /* version number of program */
+
+/* constants used by dump() to determine what data structure to print */
+#define one_dim 1
+#define two_dim 2
+#define p_label 0
+#define u_label 1
+#define v_label 2
+#define pold_label 3
+#define uold_label 4
+#define vold_label 5
+#define psi_label 6
+#define cu_label 7
+#define cv_label 8
+#define h_label 9
+#define z_label 10
+#define dudt_label 11
+#define dvdt_label 12
+
+/* message types */
+#define START_SIGNAL 0
+#define END_SIGNAL 4
+#define CALC1a 20
+#define CALC1b 21
+#define CALC1c 22
+#define CALC2a 23
+#define CALC2b 24
+#define TIME1a 30
+#define TIME1b 31
+#define TIME1c 32
+#define TIME1d 33
+#define TIME2 34
+#define P_ROW 50
+#define U_ROW 51
+#define V_ROW 52
+#define PSI_ROW 53
+#define POLD_ROW 54
+#define UOLD_ROW 55
+#define VOLD_ROW 56
+#define H_ROW 57
+#define Z_ROW 58
+
+#define PREV 0
+#define NEXT 1
+#define JSTART 2
+#define JEND 3
+
+#define debug_data 0x1
+#define debug_master 0x2
+#define debug_worker 0x4
+#define debug_call 0x8
+#define debug 0x0
+
+struct res
+{
+ float row[m];
+ int indx;
+};
diff --git a/samples/shallow-mixed/diag.c b/samples/shallow-mixed/diag.c
index 919a26a..255b167 100644
--- a/samples/shallow-mixed/diag.c
+++ b/samples/shallow-mixed/diag.c
@@ -1,75 +1,75 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-#include <stdio.h>
-#include "decs.h"
-
-void diag(ncycle,time,p,u,v,h,z)
-int ncycle;
-float time;
-float p[n][m];
-float u[n][m];
-float v[n][m];
-float h[n][m];
-float z[n][m];
-/*
-Calculate global integrals of kinetic and potential energy and
-potential enstrophy
-*/
-{
- float ptot,ketot,etot,enstot,ptime,pmean;
- int i,j,ip,jp;
-
- ptot=0.; ketot=0.; etot=0.; enstot = 0.; pmean = 0.;
- for (j = 0; j < n; j++) {
- for (i = 0; i < m; i++) {
- pmean = pmean+p[j][i];
- }
- }
- pmean = pmean/(m*n);
- for (j = 0; j < n; j++){
- jp = (j+1) % n;
- for (i = 0; i < m; i++){
- ip = (i+1) % m;
- ketot += p[j][i]*0.25*(u[j][ip]*u[j][ip]+u[j][i]*u[j][i]
- +v[jp][i]*v[jp][i]+v[j][i]*v[j][i]);
- ptot += (p[j][i]-pmean)*(p[j][i]-pmean);
- etot += h[j][i];
- enstot += z[jp][ip]*z[jp][ip] * 0.25*
- (p[j][i]+p[j][ip]+p[jp][ip]+p[jp][i]);
- }
- }
- ptot *= 0.5/(m*n);
- ketot /= (m*n);
- etot /= (m*n);
- enstot /= (m*n);
- ptime = time/secs_pd;
-
- if ( ncycle > 0 ) {
- printf("Cycle number %5d Model time in days %6.2f \n \
- Potential energy %12.3f Kinetic Energy %12.3f \n \
- Total Energy %12.3f Pot. Enstrophy %15.6e \n\n",
- ncycle,ptime,ptot,ketot,ptot+ketot,enstot);
- }
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+#include <stdio.h>
+#include "decs.h"
+
+void diag(ncycle,time,p,u,v,h,z)
+int ncycle;
+float time;
+float p[n][m];
+float u[n][m];
+float v[n][m];
+float h[n][m];
+float z[n][m];
+/*
+Calculate global integrals of kinetic and potential energy and
+potential enstrophy
+*/
+{
+ float ptot,ketot,etot,enstot,ptime,pmean;
+ int i,j,ip,jp;
+
+ ptot=0.; ketot=0.; etot=0.; enstot = 0.; pmean = 0.;
+ for (j = 0; j < n; j++) {
+ for (i = 0; i < m; i++) {
+ pmean = pmean+p[j][i];
+ }
+ }
+ pmean = pmean/(m*n);
+ for (j = 0; j < n; j++){
+ jp = (j+1) % n;
+ for (i = 0; i < m; i++){
+ ip = (i+1) % m;
+ ketot += p[j][i]*0.25*(u[j][ip]*u[j][ip]+u[j][i]*u[j][i]
+ +v[jp][i]*v[jp][i]+v[j][i]*v[j][i]);
+ ptot += (p[j][i]-pmean)*(p[j][i]-pmean);
+ etot += h[j][i];
+ enstot += z[jp][ip]*z[jp][ip] * 0.25*
+ (p[j][i]+p[j][ip]+p[jp][ip]+p[jp][i]);
+ }
+ }
+ ptot *= 0.5/(m*n);
+ ketot /= (m*n);
+ etot /= (m*n);
+ enstot /= (m*n);
+ ptime = time/secs_pd;
+
+ if ( ncycle > 0 ) {
+ printf("Cycle number %5d Model time in days %6.2f \n \
+ Potential energy %12.3f Kinetic Energy %12.3f \n \
+ Total Energy %12.3f Pot. Enstrophy %15.6e \n\n",
+ ncycle,ptime,ptot,ketot,ptot+ketot,enstot);
+ }
+}
diff --git a/samples/shallow-mixed/dump.c b/samples/shallow-mixed/dump.c
index 4c484bb..4ffe41f 100644
--- a/samples/shallow-mixed/dump.c
+++ b/samples/shallow-mixed/dump.c
@@ -1,90 +1,90 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-
-#include "decs.h"
-#include <stdio.h>
-
-void dump(int indx,int one_or_two,float onedim[m],float twodim[n][m])
-{
- int i, j;
-
- printf("\n");
- switch (indx) {
- case p_label :
- printf("dumping p:\n");
- break;
- case u_label :
- printf("dumping u:\n");
- break;
- case v_label :
- printf("dumping v:\n");
- break;
- case pold_label :
- printf("dumping pold:\n");
- break;
- case uold_label :
- printf("dumping uold:\n");
- break;
- case vold_label :
- printf("dumping vold:\n");
- break;
- case psi_label :
- printf("dumping psi:\n");
- break;
- case cu_label :
- printf("dumping cu:\n");
- break;
- case cv_label :
- printf("dumping cv:\n");
- break;
- case h_label :
- printf("dumping h:\n");
- break;
- case z_label :
- printf("dumping z:\n");
- break;
- case dudt_label :
- printf("dumping dudt:\n");
- break;
- case dvdt_label :
- printf("dumping dvdt:\n");
- break;
- }
-
- if (one_or_two == 1) {
- for (i = 0; i < m; i++) {
- printf("%d %f", i, onedim[i]);
- printf("\n");
- }
- }
- else {
- for (i = 0; i < m; i++) {
- for (j = 0; j < n; j++) {
- printf("%d,%d %f", i, j, twodim[j][i]);
- printf("\n");
- }
- }
- }
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+
+#include "decs.h"
+#include <stdio.h>
+
+void dump(int indx,int one_or_two,float onedim[m],float twodim[n][m])
+{
+ int i, j;
+
+ printf("\n");
+ switch (indx) {
+ case p_label :
+ printf("dumping p:\n");
+ break;
+ case u_label :
+ printf("dumping u:\n");
+ break;
+ case v_label :
+ printf("dumping v:\n");
+ break;
+ case pold_label :
+ printf("dumping pold:\n");
+ break;
+ case uold_label :
+ printf("dumping uold:\n");
+ break;
+ case vold_label :
+ printf("dumping vold:\n");
+ break;
+ case psi_label :
+ printf("dumping psi:\n");
+ break;
+ case cu_label :
+ printf("dumping cu:\n");
+ break;
+ case cv_label :
+ printf("dumping cv:\n");
+ break;
+ case h_label :
+ printf("dumping h:\n");
+ break;
+ case z_label :
+ printf("dumping z:\n");
+ break;
+ case dudt_label :
+ printf("dumping dudt:\n");
+ break;
+ case dvdt_label :
+ printf("dumping dvdt:\n");
+ break;
+ }
+
+ if (one_or_two == 1) {
+ for (i = 0; i < m; i++) {
+ printf("%d %f", i, onedim[i]);
+ printf("\n");
+ }
+ }
+ else {
+ for (i = 0; i < m; i++) {
+ for (j = 0; j < n; j++) {
+ printf("%d,%d %f", i, j, twodim[j][i]);
+ printf("\n");
+ }
+ }
+ }
+}
diff --git a/samples/shallow-mixed/init.c b/samples/shallow-mixed/init.c
index b14b76f..55cf163 100644
--- a/samples/shallow-mixed/init.c
+++ b/samples/shallow-mixed/init.c
@@ -1,86 +1,86 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-#include <stdio.h>
-#include <math.h>
-#include "decs.h"
-
-void initialise(p, u, v, psi, pold, uold, vold, di, dj, z)
-float p[n][m];
-float u[n][m];
-float v[n][m];
-float psi[n][m];
-float pold[n][m];
-float uold[n][m];
-float vold[n][m];
-float di, dj;
-float z[n][m];
-{
- int i,j,ip,jp;
-
- /* initialise values of the streamfunction */
- for (j = 0; j < n; j++){
- for (i = 0; i < m; i++){
- float sin1 = sin((double)((i+0.5)*di));
- float sin2 = sin((double)((j+0.5)*dj));
- psi[j][i] = a*sin1*sin2;
- }
- }
-
- /* initialise velocities */
- for (j = 0; j < n; j++){
- jp = (j+1) % n;
- for (i = 0; i < m; i++){
- ip = (i+1) % m;
- u[j][ip] = -(psi[jp][ip]-psi[j][ip])/dy;
- v[jp][i] = -(psi[jp][ip]-psi[jp][i])/dx;
- }
- }
-
- for (j = 0; j < n; j++) {
- for (i = 0; i < m; i++) {
- uold[j][i] = u[j][i];
- vold[j][i] = v[j][i];
- /* free surface height * gravitational acceleration */
- pold[j][i] = 50000.;
- p[j][i] = 50000.;
- }
- }
-
- for (j = 0; j < n; j++) {
- for (i = 0; i < m; i++) {
- z[j][i] = 0.;
- }
- }
-
-
- printf("\n");
- printf("Shallow water weather model - Distributed Memory Version 0.6\n\n");
- printf("Number of points in the X direction%8d\n", n);
- printf("Number of points in the Y direction%8d\n", m);
- printf("Grid spacing in the X direction %8.2f\n", dx);
- printf("Grid spacing in the Y direction %8.2f\n", dy);
- printf("Time step %8.3f\n", dt);
- printf("Time filter parameter %8.3f\n", alpha);
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+#include <stdio.h>
+#include <math.h>
+#include "decs.h"
+
+void initialise(p, u, v, psi, pold, uold, vold, di, dj, z)
+float p[n][m];
+float u[n][m];
+float v[n][m];
+float psi[n][m];
+float pold[n][m];
+float uold[n][m];
+float vold[n][m];
+float di, dj;
+float z[n][m];
+{
+ int i,j,ip,jp;
+
+ /* initialise values of the streamfunction */
+ for (j = 0; j < n; j++){
+ for (i = 0; i < m; i++){
+ float sin1 = sin((double)((i+0.5)*di));
+ float sin2 = sin((double)((j+0.5)*dj));
+ psi[j][i] = a*sin1*sin2;
+ }
+ }
+
+ /* initialise velocities */
+ for (j = 0; j < n; j++){
+ jp = (j+1) % n;
+ for (i = 0; i < m; i++){
+ ip = (i+1) % m;
+ u[j][ip] = -(psi[jp][ip]-psi[j][ip])/dy;
+ v[jp][i] = -(psi[jp][ip]-psi[jp][i])/dx;
+ }
+ }
+
+ for (j = 0; j < n; j++) {
+ for (i = 0; i < m; i++) {
+ uold[j][i] = u[j][i];
+ vold[j][i] = v[j][i];
+ /* free surface height * gravitational acceleration */
+ pold[j][i] = 50000.;
+ p[j][i] = 50000.;
+ }
+ }
+
+ for (j = 0; j < n; j++) {
+ for (i = 0; i < m; i++) {
+ z[j][i] = 0.;
+ }
+ }
+
+
+ printf("\n");
+ printf("Shallow water weather model - Distributed Memory Version 0.6\n\n");
+ printf("Number of points in the X direction%8d\n", n);
+ printf("Number of points in the Y direction%8d\n", m);
+ printf("Grid spacing in the X direction %8.2f\n", dx);
+ printf("Grid spacing in the Y direction %8.2f\n", dy);
+ printf("Time step %8.3f\n", dt);
+ printf("Time filter parameter %8.3f\n", alpha);
+}
diff --git a/samples/shallow-mixed/main.c b/samples/shallow-mixed/main.c
index 42645da..ebae9e0 100644
--- a/samples/shallow-mixed/main.c
+++ b/samples/shallow-mixed/main.c
@@ -1,261 +1,261 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-
-#include <math.h>
-#include <mpi.h>
-#include <stdio.h>
-#include "decs.h"
-
-extern void worker();
-MPI_Datatype * setup_res();
-
-main (argc, argv)
- int argc;
- char * argv[];
-{
- float pi=4.*(float)atan((double)1.);
- float p[n][m]; /* Pressure (or free surface height) */
- float u[n][m]; /* Zonal wind */
- float v[n][m]; /* Meridional wind */
- float psi[n][m]; /* Velocity streamfunction */
- float pold[n][m];
- float uold[n][m];
- float vold[n][m];
- float h[n][m];
- float z[n][m];
- float dummy1[m];
- float dummy2[n][m];
- float tpi=pi+pi;
- float di=tpi/(float)m;
- float dj=tpi/(float)n;
- int i, j, chunk_size, nxt, prv;
-
- int master_packet[4];
- float p_start[m];
- float u_start[m];
- float v_start[m];
- float psi_start[m];
- float pold_start[m];
- float uold_start[m];
- float vold_start[m];
- int proc_cnt;
- int tid;
- MPI_Datatype * res_type;
-
- MPI_Init(&argc, &argv);
- MPI_Comm_size(MPI_COMM_WORLD, &proc_cnt);
- MPI_Comm_rank(MPI_COMM_WORLD, &tid);
-
- if ( proc_cnt < 2 )
- {
- fprintf(stderr, "must have at least 2 processes, not %d\n", proc_cnt);
- MPI_Finalize();
- return 1;
- }
-
- if ( (n % (proc_cnt - 1)) != 0 )
- {
- if ( tid == 0 )
- fprintf(stderr, "(number of processes - 1) must be a multiple of %d\n", n);
-
- MPI_Finalize();
- return 1;
- }
-
- if (tid != 0) {
- worker();
- MPI_Barrier(MPI_COMM_WORLD);
- MPI_Finalize();
- } else {
-
- /* master process */
-
- chunk_size = n / (proc_cnt - 1);
-
- for (i = 1: i < proc_cnt; i++) {
- /* calculate each worker's boundary */
- master_packet[JSTART] = (i - 1) * chunk_size;
-
- if (i == proc_cnt - 1)
- master_packet[JEND] = n - 1;
- else
- master_packet[JEND] = i * chunk_size - 1;
-
- if (i == 1)
- prv = proc_cnt-1;
- else
- prv = i-1;
-
- master_packet[PREV] = prv;
-
- if (i == proc_cnt - 1)
- nxt = 1;
- else
- nxt = i+1;
-
- master_packet[NEXT] = nxt;
-
- MPI_Send(&master_packet, 4, MPI_INT, i, START_SIGNAL,
- MPI_COMM_WORLD);
-
- printf("jstart=%d, jend=%d, next=%d, prev=%d\n",
- master_packet[JSTART],
- master_packet[JEND],
- master_packet[NEXT],
- master_packet[PREV]);
- }
-
-
- /*
- initialise data structures and construct packets to be sent to workers
- */
-
- initialise(p, u, v, psi, pold, uold, vold, di, dj, z);
- diag(1, 0., p, u, v, h, z);
-
- for (i = 1; i < proc_cnt; i++) {
- for (j = 0; j < n; j++) {
- acopy_two_to_one(p, p_start, j);
- MPI_Send(&p_start, m, MPI_FLOAT, i, P_ROW,
- MPI_COMM_WORLD);
-
- acopy_two_to_one(u, u_start, j);
- MPI_Send(&u_start, m, MPI_FLOAT, i, U_ROW,
- MPI_COMM_WORLD);
-
- acopy_two_to_one(v, v_start, j);
- MPI_Send(&v_start, m, MPI_FLOAT, i, V_ROW,
- MPI_COMM_WORLD);
-
- acopy_two_to_one(psi, psi_start, j);
- MPI_Send(&psi_start, m, MPI_FLOAT, i, PSI_ROW,
- MPI_COMM_WORLD);
-
- acopy_two_to_one(pold, pold_start, j);
- MPI_Send(&pold_start, m, MPI_FLOAT, i, POLD_ROW,
- MPI_COMM_WORLD);
-
- acopy_two_to_one(uold, uold_start, j);
- MPI_Send(&uold_start, m, MPI_FLOAT, i, UOLD_ROW,
- MPI_COMM_WORLD);
-
- acopy_two_to_one(vold, vold_start, j);
- MPI_Send(&vold_start, m, MPI_FLOAT, i, VOLD_ROW,
- MPI_COMM_WORLD);
- }
- }
-
- /*
- receive packets back from the workers
- */
- res_type = setup_res();
-
- if ( debug & debug_master )
- printf("receiving P\n");
-
- update_global_ds(res_type, P_ROW, p);
-
- if ( debug & debug_master )
- printf("receiving U\n");
-
- update_global_ds(res_type, U_ROW, u);
-
- if ( debug & debug_master )
- printf("receiving V\n");
-
- update_global_ds(res_type, V_ROW, v);
-
- if ( debug & debug_master )
- printf("receiving H\n");
-
- update_global_ds(res_type, H_ROW, h);
-
- if ( debug & debug_master )
- printf("receiving Z\n");
-
- update_global_ds(res_type, Z_ROW, z);
-
- for (i = 1; i < proc_cnt; i++){
- MPI_Send(&master_packet, 4, MPI_INT, i, END_SIGNAL,
- MPI_COMM_WORLD);
- }
-
- /* wait for all workers to end */
- MPI_Barrier(MPI_COMM_WORLD);
- MPI_Finalize();
-
- diag(itmax, itmax*dt, p, u, v, h, z);
- }
-
- return 0;
-}
-
-MPI_Datatype *
-setup_res()
-{
- struct res res;
- MPI_Aint res_disp[2];
- static int res_done = 0;
- static int res_len[2] = { m, 1 };
- static MPI_Datatype res_old[2] = { MPI_FLOAT, MPI_INT };
- static MPI_Datatype res_type;
-
- if ( res_done )
- return &res_type;
-
- res_done++;
- MPI_Address(&res.row[0], &res_disp[0]);
- MPI_Address(&res.indx, &res_disp[1]);
- res_disp[1] -= res_disp[0];
- res_disp[0] = 0;
- MPI_Type_struct(2, res_len, res_disp, res_old, &res_type);
- MPI_Type_commit(&res_type);
-
- return &res_type;
-}
-
-/*
-this function waits for all the workers to return the packets of
-a particular type and then updates the master's copy of the same type
-*/
-update_global_ds(res_type, indx, ds)
- MPI_Datatype * res_type;
- int indx;
- float ds[n][m];
-
-{
- int i;
- int row;
- struct res res;
- MPI_Status status;
-
- for (i = 0; i < n; i++) {
- MPI_Recv(&res, 1, *res_type, MPI_ANY_SOURCE, indx,
- MPI_COMM_WORLD, &status);
-
- acopy_one_to_two(res.row, ds, res.indx);
- }
-
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+
+#include <math.h>
+#include <mpi.h>
+#include <stdio.h>
+#include "decs.h"
+
+extern void worker();
+MPI_Datatype * setup_res();
+
+main (argc, argv)
+ int argc;
+ char * argv[];
+{
+ float pi=4.*(float)atan((double)1.);
+ float p[n][m]; /* Pressure (or free surface height) */
+ float u[n][m]; /* Zonal wind */
+ float v[n][m]; /* Meridional wind */
+ float psi[n][m]; /* Velocity streamfunction */
+ float pold[n][m];
+ float uold[n][m];
+ float vold[n][m];
+ float h[n][m];
+ float z[n][m];
+ float dummy1[m];
+ float dummy2[n][m];
+ float tpi=pi+pi;
+ float di=tpi/(float)m;
+ float dj=tpi/(float)n;
+ int i, j, chunk_size, nxt, prv;
+
+ int master_packet[4];
+ float p_start[m];
+ float u_start[m];
+ float v_start[m];
+ float psi_start[m];
+ float pold_start[m];
+ float uold_start[m];
+ float vold_start[m];
+ int proc_cnt;
+ int tid;
+ MPI_Datatype * res_type;
+
+ MPI_Init(&argc, &argv);
+ MPI_Comm_size(MPI_COMM_WORLD, &proc_cnt);
+ MPI_Comm_rank(MPI_COMM_WORLD, &tid);
+
+ if ( proc_cnt < 2 )
+ {
+ fprintf(stderr, "must have at least 2 processes, not %d\n", proc_cnt);
+ MPI_Finalize();
+ return 1;
+ }
+
+ if ( (n % (proc_cnt - 1)) != 0 )
+ {
+ if ( tid == 0 )
+ fprintf(stderr, "(number of processes - 1) must be a multiple of %d\n", n);
+
+ MPI_Finalize();
+ return 1;
+ }
+
+ if (tid != 0) {
+ worker();
+ MPI_Barrier(MPI_COMM_WORLD);
+ MPI_Finalize();
+ } else {
+
+ /* master process */
+
+ chunk_size = n / (proc_cnt - 1);
+
+ for (i = 1: i < proc_cnt; i++) {
+ /* calculate each worker's boundary */
+ master_packet[JSTART] = (i - 1) * chunk_size;
+
+ if (i == proc_cnt - 1)
+ master_packet[JEND] = n - 1;
+ else
+ master_packet[JEND] = i * chunk_size - 1;
+
+ if (i == 1)
+ prv = proc_cnt-1;
+ else
+ prv = i-1;
+
+ master_packet[PREV] = prv;
+
+ if (i == proc_cnt - 1)
+ nxt = 1;
+ else
+ nxt = i+1;
+
+ master_packet[NEXT] = nxt;
+
+ MPI_Send(&master_packet, 4, MPI_INT, i, START_SIGNAL,
+ MPI_COMM_WORLD);
+
+ printf("jstart=%d, jend=%d, next=%d, prev=%d\n",
+ master_packet[JSTART],
+ master_packet[JEND],
+ master_packet[NEXT],
+ master_packet[PREV]);
+ }
+
+
+ /*
+ initialise data structures and construct packets to be sent to workers
+ */
+
+ initialise(p, u, v, psi, pold, uold, vold, di, dj, z);
+ diag(1, 0., p, u, v, h, z);
+
+ for (i = 1; i < proc_cnt; i++) {
+ for (j = 0; j < n; j++) {
+ acopy_two_to_one(p, p_start, j);
+ MPI_Send(&p_start, m, MPI_FLOAT, i, P_ROW,
+ MPI_COMM_WORLD);
+
+ acopy_two_to_one(u, u_start, j);
+ MPI_Send(&u_start, m, MPI_FLOAT, i, U_ROW,
+ MPI_COMM_WORLD);
+
+ acopy_two_to_one(v, v_start, j);
+ MPI_Send(&v_start, m, MPI_FLOAT, i, V_ROW,
+ MPI_COMM_WORLD);
+
+ acopy_two_to_one(psi, psi_start, j);
+ MPI_Send(&psi_start, m, MPI_FLOAT, i, PSI_ROW,
+ MPI_COMM_WORLD);
+
+ acopy_two_to_one(pold, pold_start, j);
+ MPI_Send(&pold_start, m, MPI_FLOAT, i, POLD_ROW,
+ MPI_COMM_WORLD);
+
+ acopy_two_to_one(uold, uold_start, j);
+ MPI_Send(&uold_start, m, MPI_FLOAT, i, UOLD_ROW,
+ MPI_COMM_WORLD);
+
+ acopy_two_to_one(vold, vold_start, j);
+ MPI_Send(&vold_start, m, MPI_FLOAT, i, VOLD_ROW,
+ MPI_COMM_WORLD);
+ }
+ }
+
+ /*
+ receive packets back from the workers
+ */
+ res_type = setup_res();
+
+ if ( debug & debug_master )
+ printf("receiving P\n");
+
+ update_global_ds(res_type, P_ROW, p);
+
+ if ( debug & debug_master )
+ printf("receiving U\n");
+
+ update_global_ds(res_type, U_ROW, u);
+
+ if ( debug & debug_master )
+ printf("receiving V\n");
+
+ update_global_ds(res_type, V_ROW, v);
+
+ if ( debug & debug_master )
+ printf("receiving H\n");
+
+ update_global_ds(res_type, H_ROW, h);
+
+ if ( debug & debug_master )
+ printf("receiving Z\n");
+
+ update_global_ds(res_type, Z_ROW, z);
+
+ for (i = 1; i < proc_cnt; i++){
+ MPI_Send(&master_packet, 4, MPI_INT, i, END_SIGNAL,
+ MPI_COMM_WORLD);
+ }
+
+ /* wait for all workers to end */
+ MPI_Barrier(MPI_COMM_WORLD);
+ MPI_Finalize();
+
+ diag(itmax, itmax*dt, p, u, v, h, z);
+ }
+
+ return 0;
+}
+
+MPI_Datatype *
+setup_res()
+{
+ struct res res;
+ MPI_Aint res_disp[2];
+ static int res_done = 0;
+ static int res_len[2] = { m, 1 };
+ static MPI_Datatype res_old[2] = { MPI_FLOAT, MPI_INT };
+ static MPI_Datatype res_type;
+
+ if ( res_done )
+ return &res_type;
+
+ res_done++;
+ MPI_Address(&res.row[0], &res_disp[0]);
+ MPI_Address(&res.indx, &res_disp[1]);
+ res_disp[1] -= res_disp[0];
+ res_disp[0] = 0;
+ MPI_Type_struct(2, res_len, res_disp, res_old, &res_type);
+ MPI_Type_commit(&res_type);
+
+ return &res_type;
+}
+
+/*
+this function waits for all the workers to return the packets of
+a particular type and then updates the master's copy of the same type
+*/
+update_global_ds(res_type, indx, ds)
+ MPI_Datatype * res_type;
+ int indx;
+ float ds[n][m];
+
+{
+ int i;
+ int row;
+ struct res res;
+ MPI_Status status;
+
+ for (i = 0; i < n; i++) {
+ MPI_Recv(&res, 1, *res_type, MPI_ANY_SOURCE, indx,
+ MPI_COMM_WORLD, &status);
+
+ acopy_one_to_two(res.row, ds, res.indx);
+ }
+
+}
diff --git a/samples/shallow-mixed/time.c b/samples/shallow-mixed/time.c
index f72718b..a30ee29 100644
--- a/samples/shallow-mixed/time.c
+++ b/samples/shallow-mixed/time.c
@@ -1,56 +1,56 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-
-#include "decs.h"
-
-void timetend(jstart,jend,dpdt,dudt,dvdt,cu,cv,h,z)
-int jstart,jend;
-float dudt[n][m];
-float dvdt[n][m];
-float dpdt[n][m];
-float z[n][m];
-float cv[n][m];
-float cu[n][m];
-float h[n][m];
-{
- int i,j,ip,jp;
- float invdx, invdy;
-
- invdx = 1./dx; invdy=1./dy;
- for(j=jstart;j<=jend;j++) {
- jp = (j+1) % n;
- for (i = 0; i < m; i++) {
- ip = (i+1) % m;
- /* ENERGY CONSERVING */
- dpdt[j][i] = -(cu[j][ip]-cu[j][i])*invdx - (cv[jp][i]-cv[j][i])*invdy;
- dudt[j][ip] =
- 0.125 * (z[jp][ip] * (cv[jp][ip] + cv[jp][i]) + z[j][ip] *
- (cv[j][ip]+cv[j][i])) - (h[j][ip] - h[j][i]) * invdx;
- dvdt[jp][i] =
- -0.125 * (z[jp][ip] * (cu[jp][ip] + cu[j][ip]) + z[jp][i] *
- (cu[jp][i]+cu[j][i])) - (h[jp][i] - h[j][i]) * invdy;
- }
- }
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+
+#include "decs.h"
+
+void timetend(jstart,jend,dpdt,dudt,dvdt,cu,cv,h,z)
+int jstart,jend;
+float dudt[n][m];
+float dvdt[n][m];
+float dpdt[n][m];
+float z[n][m];
+float cv[n][m];
+float cu[n][m];
+float h[n][m];
+{
+ int i,j,ip,jp;
+ float invdx, invdy;
+
+ invdx = 1./dx; invdy=1./dy;
+ for(j=jstart;j<=jend;j++) {
+ jp = (j+1) % n;
+ for (i = 0; i < m; i++) {
+ ip = (i+1) % m;
+ /* ENERGY CONSERVING */
+ dpdt[j][i] = -(cu[j][ip]-cu[j][i])*invdx - (cv[jp][i]-cv[j][i])*invdy;
+ dudt[j][ip] =
+ 0.125 * (z[jp][ip] * (cv[jp][ip] + cv[jp][i]) + z[j][ip] *
+ (cv[j][ip]+cv[j][i])) - (h[j][ip] - h[j][i]) * invdx;
+ dvdt[jp][i] =
+ -0.125 * (z[jp][ip] * (cu[jp][ip] + cu[j][ip]) + z[jp][i] *
+ (cu[jp][i]+cu[j][i])) - (h[jp][i] - h[j][i]) * invdy;
+ }
+ }
+}
diff --git a/samples/shallow-mixed/tstep.c b/samples/shallow-mixed/tstep.c
index ae035aa..14f5c7b 100644
--- a/samples/shallow-mixed/tstep.c
+++ b/samples/shallow-mixed/tstep.c
@@ -1,77 +1,77 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-
-#include "decs.h"
-
-void tstep(
-int m_,
-int n_,
-float alpha_,
-int jstart,
-int jend,
-float pold[n][m],
-float uold[n][m],
-float vold[n][m],
-float p[n][m],
-float u[n][m],
-float v[n][m],
-float pnew[n][m],
-float unew[n][m],
-float vnew[n][m],
-float dpdt[n][m],
-float dudt[n][m],
-float dvdt[n][m],
-int firststep,
-float tdt)
-{
- int i,j;
-
- for (j = jstart; j <= jend; j++){
- for (i = 0; i < m; i++){
- pnew[j][i] = pold[j][i] + tdt*dpdt[j][i];
- unew[j][i] = uold[j][i] + tdt*dudt[j][i];
- vnew[j][i] = vold[j][i] + tdt*dvdt[j][i];
- }
- }
-
- /* Don't apply time filter on first step */
- if ( !firststep ) {
- for (j = jstart; j <= jend; j++) {
- for (i = 0; i < m; i++) {
- pold[j][i] = p[j][i]+alpha*(pnew[j][i]-2.*p[j][i]+pold[j][i]);
- uold[j][i] = u[j][i]+alpha*(unew[j][i]-2.*u[j][i]+uold[j][i]);
- vold[j][i] = v[j][i]+alpha*(vnew[j][i]-2.*v[j][i]+vold[j][i]);
- }
- }
- }
-
- for (j = jstart; j <= jend; j++) {
- for (i = 0; i < m; i++) {
- p[j][i] = pnew[j][i];
- u[j][i] = unew[j][i];
- v[j][i] = vnew[j][i];
- }
- }
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+
+#include "decs.h"
+
+void tstep(
+int m_,
+int n_,
+float alpha_,
+int jstart,
+int jend,
+float pold[n][m],
+float uold[n][m],
+float vold[n][m],
+float p[n][m],
+float u[n][m],
+float v[n][m],
+float pnew[n][m],
+float unew[n][m],
+float vnew[n][m],
+float dpdt[n][m],
+float dudt[n][m],
+float dvdt[n][m],
+int firststep,
+float tdt)
+{
+ int i,j;
+
+ for (j = jstart; j <= jend; j++){
+ for (i = 0; i < m; i++){
+ pnew[j][i] = pold[j][i] + tdt*dpdt[j][i];
+ unew[j][i] = uold[j][i] + tdt*dudt[j][i];
+ vnew[j][i] = vold[j][i] + tdt*dvdt[j][i];
+ }
+ }
+
+ /* Don't apply time filter on first step */
+ if ( !firststep ) {
+ for (j = jstart; j <= jend; j++) {
+ for (i = 0; i < m; i++) {
+ pold[j][i] = p[j][i]+alpha*(pnew[j][i]-2.*p[j][i]+pold[j][i]);
+ uold[j][i] = u[j][i]+alpha*(unew[j][i]-2.*u[j][i]+uold[j][i]);
+ vold[j][i] = v[j][i]+alpha*(vnew[j][i]-2.*v[j][i]+vold[j][i]);
+ }
+ }
+ }
+
+ for (j = jstart; j <= jend; j++) {
+ for (i = 0; i < m; i++) {
+ p[j][i] = pnew[j][i];
+ u[j][i] = unew[j][i];
+ v[j][i] = vnew[j][i];
+ }
+ }
+}
diff --git a/samples/shallow-mixed/worker.c b/samples/shallow-mixed/worker.c
index 31a97c5..ae51680 100644
--- a/samples/shallow-mixed/worker.c
+++ b/samples/shallow-mixed/worker.c
@@ -1,358 +1,358 @@
-
-/************************************************************************
-* *
-* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
-* - Division of Information Technology (DIT) *
-* - Division of Atmospheric Research (DAR) *
-* *
-* Shallow water weather model - Distributed Memory Version *
-* *
-* Finite difference model of shallow water equations based on :- *
-* "The dynamics of finite difference models of the shallow water *
-* equations" by R. Sadourney, JAS, 32, 1975. *
-* Code from:- *
-* "An introduction to three-dimensional climate modelling" *
-* by Washington and Parkinson *
-* *
-* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
-* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
-* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
-* Language = BSD c using Argonne NL macros *
-* O/S = Unix System V *
-* H/W = Encore Multimax 320 *
-* *
-************************************************************************/
-
-#include <math.h>
-#include <mpi.h>
-#include <stdio.h>
-#include "decs.h"
-
-MPI_Datatype * setup_res();
-
-extern void tstep(
-int m_,
-int n_,
-float alpha_,
-int jstart,
-int jend,
-float pold[n][m],
-float uold[n][m],
-float vold[n][m],
-float p[n][m],
-float u[n][m],
-float v[n][m],
-float pnew[n][m],
-float unew[n][m],
-float vnew[n][m],
-float dpdt[n][m],
-float dudt[n][m],
-float dvdt[n][m],
-int firststep,
-float tdt);
-
-void
-worker()
-{
- int firststep, ncycle;
- float tdt, time;
- int i,j,ip,jp,jstart,jend;
- int prv;
- int nxt;
-
- int msg_type;
- int master_id, my_id;
- int nprocs;
- int nbytes;
-
- float p[n][m]; /* Pressure (or free surface height) */
- float u[n][m]; /* Zonal wind */
- float v[n][m]; /* Meridional wind */
- float psi[n][m]; /* Velocity streamfunction */
- float pold[n][m];
- float uold[n][m];
- float vold[n][m];
- float pnew[n][m];
- float unew[n][m];
- float vnew[n][m];
- float dpdt[n][m];
- float dudt[n][m]; /* Time tendency of u */
- float dvdt[n][m];
- float cu[n][m]; /* Mass weighted u */
- float cv[n][m]; /* Mass weighted v */
- float h[n][m];
- float z[n][m]; /* Potential enstrophy */
- float dummy1[m];
- float dummy2[n];
- float fsdx = 4./dx;
- float fsdy = 4./dy;
-
- int worker[4];
- float p_start[m];
- float u_start[m];
- float v_start[m];
- float psi_start[m];
- float pold_start[m];
- float uold_start[m];
- float vold_start[m];
- MPI_Datatype * res_type;
- MPI_Status status;
-
- /*
- initialise control variables
- */
-
- firststep = 1;
- ncycle = 0;
- tdt = dt;
- time = 0.;
-
- /*
- set up environment for worker
- */
-
- MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
- MPI_Comm_rank(MPI_COMM_WORLD, &my_id);
-
- MPI_Recv(&worker, 4, MPI_INT, MPI_ANY_SOURCE, START_SIGNAL,
- MPI_COMM_WORLD, &status);
-
- prv = worker[PREV];
- nxt = worker[NEXT];
- jstart = worker[JSTART];
- jend = worker[JEND];
-
- /*
- receive initialisation packets from master
- */
-
- for (i = 0; i < n; i++){
- MPI_Recv(&p_start, m, MPI_FLOAT, 0, P_ROW,
- MPI_COMM_WORLD, &status);
- acopy_one_to_two(p_start, p, i);
-
- MPI_Recv(&u_start, m, MPI_FLOAT, 0, U_ROW,
- MPI_COMM_WORLD, &status);
- acopy_one_to_two(u_start, u, i);
-
- MPI_Recv(&v_start, m, MPI_FLOAT, 0, V_ROW,
- MPI_COMM_WORLD, &status);
- acopy_one_to_two(v_start, v, i);
-
- MPI_Recv(&psi_start, m, MPI_FLOAT, 0, PSI_ROW,
- MPI_COMM_WORLD, &status);
- acopy_one_to_two(psi_start, psi, i);
-
- MPI_Recv(&pold_start, m, MPI_FLOAT, 0, POLD_ROW,
- MPI_COMM_WORLD, &status);
- acopy_one_to_two(pold_start, pold, i);
-
- MPI_Recv(&uold_start, m, MPI_FLOAT, 0, UOLD_ROW,
- MPI_COMM_WORLD, &status);
- acopy_one_to_two(uold_start, uold, i);
-
- MPI_Recv(&vold_start, m, MPI_FLOAT, 0, VOLD_ROW,
- MPI_COMM_WORLD, &status);
- acopy_one_to_two(vold_start, vold, i);
- }
-
- while (ncycle < itmax) {
- /*
- loop over latitudes calculating U, V, z and h
- do the block of latitudes from jstart to jend inclusive
- */
-
- calc_load(prv, nxt, my_id, jstart, jend, p, u,v);
- calcuvzh(jstart, jend, p, u, v, cu, cv, h, z, fsdx, fsdy);
- calc_unload(prv, nxt, my_id, jstart, jend, cv, z);
-
-
- /*
- Calculate time tendencies of p, u and v
- */
-
- time_load(prv, nxt, my_id, jstart, jend, cu, cv, h, z);
- timetend(jstart, jend, dpdt, dudt, dvdt, cu, cv, h, z);
- time_unload(prv, nxt, my_id, jstart, jend, dvdt);
-
- if ((my_id == 1) && (ncycle%mprint==0)) {
- diag(ncycle, time, p, u, v, h, z);
- }
-
- time += dt;
-
- tstep(m, n, alpha,
- jstart, jend, pold, uold, vold, p, u, v, pnew,
- unew, vnew, dpdt, dudt, dvdt, firststep, tdt);
-
- if ( firststep ) {
- /* Double tdt because all future steps are leapfrog */
- firststep = 0;
- tdt = tdt+tdt;
- }
-
- ncycle++;
- } /* End of time step loop */
-
- /*
- send local data structures (results) back to master
- */
-
- res_type = setup_res();
-
- send_updated_ds(res_type, jstart, jend, p, P_ROW, 0);
- send_updated_ds(res_type, jstart, jend, u, U_ROW, 0);
- send_updated_ds(res_type, jstart, jend, v, V_ROW, 0);
- send_updated_ds(res_type, jstart, jend, h, H_ROW, 0);
- send_updated_ds(res_type, jstart, jend, z, Z_ROW, 0);
-
- MPI_Recv(&worker, 4, MPI_INT, 0, END_SIGNAL,
- MPI_COMM_WORLD, &status);
-
- if (debug & debug_call) {
- printf("worker %d sent TIDY_UP to master\n", my_id);
- printf("worker %d got END_SIGNAL from master\n", my_id);
- }
-}
-
-send_updated_ds(res_type, jstart, jend, ds, indx, master_id)
- MPI_Datatype * res_type;
- int jstart;
- int jend;
- float ds[n][m];
- int indx;
- int master_id;
-{
- int j;
- struct res res;
- MPI_Request rq[2];
- MPI_Status stat[2];
-
- for (j = jstart; j <= jend; j++) {
- acopy_two_to_one(ds, res.row, j);
- res.indx = j;
-
- MPI_Send(&res, 1, *res_type, master_id, indx,
- MPI_COMM_WORLD);
- }
-}
-
-/*
-this procedure does all the message passing before the call to _calcuvzh_
-*/
-calc_load(prv,nxt,my_id,jstart,jend,p,u,v)
- int prv;
- int nxt;
- int my_id;
- int jstart;
- int jend;
- float p[n][m];
- float u[n][m];
- float v[n][m];
-{
- neighbour_send(prv, my_id, CALC1a, p, jstart);
- neighbour_send(prv, my_id, CALC1b, u, jstart);
- neighbour_send(prv, my_id, CALC1c, v, jstart);
- neighbour_receive(nxt, my_id, CALC1a, p, (jend+1) % n);
- neighbour_receive(nxt, my_id, CALC1b, u, (jend+1) % n);
- neighbour_receive(nxt, my_id, CALC1c, v, (jend+1) % n);
-}
-
-/*
-this procedure does all the message passing after the call to _calcuvzh_
-*/
-calc_unload(prv,nxt,my_id,jstart,jend,cv,z)
- int prv;
- int nxt;
- int my_id;
- int jstart;
- int jend;
- float cv[n][m];
- float z[n][m];
-{
- neighbour_send(nxt, my_id, CALC2a, cv, (jend+1) % n);
- neighbour_send(nxt, my_id, CALC2b, z, (jend+1) % n);
- neighbour_receive(prv, my_id, CALC2a, cv, jstart);
- neighbour_receive(prv, my_id, CALC2b, z, jstart);
-}
-
-/*
-this procedure does all the message passing before the call to _timetend_
-*/
-time_load(prv,nxt,my_id,jstart,jend,cu,cv,h,z)
- int prv;
- int nxt;
- int my_id;
- int jstart;
- int jend;
- float cu[n][m];
- float cv[n][m];
- float h[n][m];
- float z[n][m];
-{
- neighbour_send(prv, my_id, TIME1a, cu, jstart);
- neighbour_send(prv, my_id, TIME1b, cv, jstart);
- neighbour_send(prv, my_id, TIME1c, h, jstart);
- neighbour_send(prv, my_id, TIME1d, z, jstart);
- neighbour_receive(nxt, my_id, TIME1a, cu, (jend+1) % n);
- neighbour_receive(nxt, my_id, TIME1b, cv, (jend+1) % n);
- neighbour_receive(nxt, my_id, TIME1c, h, (jend+1) % n);
- neighbour_receive(nxt, my_id, TIME1d, z, (jend+1) % n);
-}
-
-/*
-this procedure does all the message passing after the call to _timetend_
-*/
-time_unload(prv,nxt,tu_my_id,jstart,jend,dvdt)
- int prv;
- int nxt;
- int tu_my_id;
- int jstart;
- int jend;
- float dvdt[n][m];
-{
- neighbour_send(nxt, tu_my_id, TIME2, dvdt, (jend+1) % n);
- neighbour_receive(prv, tu_my_id, TIME2, dvdt, jstart);
-}
-
-/*
-this is a general purpose function for sending packets b/w workers
-*/
-neighbour_send(ns_neighbour,ns_my_id,ns_rec_id,ns_ds,ns_edge)
- int ns_neighbour;
- int ns_my_id;
- int ns_rec_id;
- float ns_ds[n][m];
- int ns_edge;
-{
- float ns_rec[m];
- MPI_Request rq;
-
- acopy_two_to_one(ns_ds, ns_rec, ns_edge);
-
- MPI_Isend(&ns_rec, m, MPI_FLOAT, ns_neighbour, ns_rec_id,
- MPI_COMM_WORLD, &rq);
-
- if (debug & debug_worker)
- printf("worker %d sent packet %d to worker %d\n", ns_my_id,
- ns_rec_id, ns_neighbour);
-}
-
-/*
-this is a general purpose function for receiving packets b/w workers
-*/
-neighbour_receive(nr_neighbour,nr_my_id,nr_rec_id,nr_ds,nr_edge)
- int nr_neighbour;
- int nr_my_id;
- int nr_rec_id;
- float nr_ds[n][m];
- int nr_edge;
-{
- float nr_rec[m];
- MPI_Status status;
-
- MPI_Recv(&nr_rec, m, MPI_FLOAT, nr_neighbour, nr_rec_id,
- MPI_COMM_WORLD, &status);
-
- acopy_one_to_two(nr_rec, nr_ds, nr_edge);
-}
+
+/************************************************************************
+* *
+* Commonwealth Scientific and Industrial Research Organisation (CSIRO) *
+* - Division of Information Technology (DIT) *
+* - Division of Atmospheric Research (DAR) *
+* *
+* Shallow water weather model - Distributed Memory Version *
+* *
+* Finite difference model of shallow water equations based on :- *
+* "The dynamics of finite difference models of the shallow water *
+* equations" by R. Sadourney, JAS, 32, 1975. *
+* Code from:- *
+* "An introduction to three-dimensional climate modelling" *
+* by Washington and Parkinson *
+* *
+* Programmers = David Abramson (DIT) rcoda@koel.co.rmit.oz *
+* = Paul Whiting (DIT) rcopw@koel.co.rmit.oz *
+* = Martin Dix (DAR) mrd@koel.co.rmit.oz *
+* Language = BSD c using Argonne NL macros *
+* O/S = Unix System V *
+* H/W = Encore Multimax 320 *
+* *
+************************************************************************/
+
+#include <math.h>
+#include <mpi.h>
+#include <stdio.h>
+#include "decs.h"
+
+MPI_Datatype * setup_res();
+
+extern void tstep(
+int m_,
+int n_,
+float alpha_,
+int jstart,
+int jend,
+float pold[n][m],
+float uold[n][m],
+float vold[n][m],
+float p[n][m],
+float u[n][m],
+float v[n][m],
+float pnew[n][m],
+float unew[n][m],
+float vnew[n][m],
+float dpdt[n][m],
+float dudt[n][m],
+float dvdt[n][m],
+int firststep,
+float tdt);
+
+void
+worker()
+{
+ int firststep, ncycle;
+ float tdt, time;
+ int i,j,ip,jp,jstart,jend;
+ int prv;
+ int nxt;
+
+ int msg_type;
+ int master_id, my_id;
+ int nprocs;
+ int nbytes;
+
+ float p[n][m]; /* Pressure (or free surface height) */
+ float u[n][m]; /* Zonal wind */
+ float v[n][m]; /* Meridional wind */
+ float psi[n][m]; /* Velocity streamfunction */
+ float pold[n][m];
+ float uold[n][m];
+ float vold[n][m];
+ float pnew[n][m];
+ float unew[n][m];
+ float vnew[n][m];
+ float dpdt[n][m];
+ float dudt[n][m]; /* Time tendency of u */
+ float dvdt[n][m];
+ float cu[n][m]; /* Mass weighted u */
+ float cv[n][m]; /* Mass weighted v */
+ float h[n][m];
+ float z[n][m]; /* Potential enstrophy */
+ float dummy1[m];
+ float dummy2[n];
+ float fsdx = 4./dx;
+ float fsdy = 4./dy;
+
+ int worker[4];
+ float p_start[m];
+ float u_start[m];
+ float v_start[m];
+ float psi_start[m];
+ float pold_start[m];
+ float uold_start[m];
+ float vold_start[m];
+ MPI_Datatype * res_type;
+ MPI_Status status;
+
+ /*
+ initialise control variables
+ */
+
+ firststep = 1;
+ ncycle = 0;
+ tdt = dt;
+ time = 0.;
+
+ /*
+ set up environment for worker
+ */
+
+ MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+ MPI_Comm_rank(MPI_COMM_WORLD, &my_id);
+
+ MPI_Recv(&worker, 4, MPI_INT, MPI_ANY_SOURCE, START_SIGNAL,
+ MPI_COMM_WORLD, &status);
+
+ prv = worker[PREV];
+ nxt = worker[NEXT];
+ jstart = worker[JSTART];
+ jend = worker[JEND];
+
+ /*
+ receive initialisation packets from master
+ */
+
+ for (i = 0; i < n; i++){
+ MPI_Recv(&p_start, m, MPI_FLOAT, 0, P_ROW,
+ MPI_COMM_WORLD, &status);
+ acopy_one_to_two(p_start, p, i);
+
+ MPI_Recv(&u_start, m, MPI_FLOAT, 0, U_ROW,
+ MPI_COMM_WORLD, &status);
+ acopy_one_to_two(u_start, u, i);
+
+ MPI_Recv(&v_start, m, MPI_FLOAT, 0, V_ROW,
+ MPI_COMM_WORLD, &status);
+ acopy_one_to_two(v_start, v, i);
+
+ MPI_Recv(&psi_start, m, MPI_FLOAT, 0, PSI_ROW,
+ MPI_COMM_WORLD, &status);
+ acopy_one_to_two(psi_start, psi, i);
+
+ MPI_Recv(&pold_start, m, MPI_FLOAT, 0, POLD_ROW,
+ MPI_COMM_WORLD, &status);
+ acopy_one_to_two(pold_start, pold, i);
+
+ MPI_Recv(&uold_start, m, MPI_FLOAT, 0, UOLD_ROW,
+ MPI_COMM_WORLD, &status);
+ acopy_one_to_two(uold_start, uold, i);
+
+ MPI_Recv(&vold_start, m, MPI_FLOAT, 0, VOLD_ROW,
+ MPI_COMM_WORLD, &status);
+ acopy_one_to_two(vold_start, vold, i);
+ }
+
+ while (ncycle < itmax) {
+ /*
+ loop over latitudes calculating U, V, z and h
+ do the block of latitudes from jstart to jend inclusive
+ */
+
+ calc_load(prv, nxt, my_id, jstart, jend, p, u,v);
+ calcuvzh(jstart, jend, p, u, v, cu, cv, h, z, fsdx, fsdy);
+ calc_unload(prv, nxt, my_id, jstart, jend, cv, z);
+
+
+ /*
+ Calculate time tendencies of p, u and v
+ */
+
+ time_load(prv, nxt, my_id, jstart, jend, cu, cv, h, z);
+ timetend(jstart, jend, dpdt, dudt, dvdt, cu, cv, h, z);
+ time_unload(prv, nxt, my_id, jstart, jend, dvdt);
+
+ if ((my_id == 1) && (ncycle%mprint==0)) {
+ diag(ncycle, time, p, u, v, h, z);
+ }
+
+ time += dt;
+
+ tstep(m, n, alpha,
+ jstart, jend, pold, uold, vold, p, u, v, pnew,
+ unew, vnew, dpdt, dudt, dvdt, firststep, tdt);
+
+ if ( firststep ) {
+ /* Double tdt because all future steps are leapfrog */
+ firststep = 0;
+ tdt = tdt+tdt;
+ }
+
+ ncycle++;
+ } /* End of time step loop */
+
+ /*
+ send local data structures (results) back to master
+ */
+
+ res_type = setup_res();
+
+ send_updated_ds(res_type, jstart, jend, p, P_ROW, 0);
+ send_updated_ds(res_type, jstart, jend, u, U_ROW, 0);
+ send_updated_ds(res_type, jstart, jend, v, V_ROW, 0);
+ send_updated_ds(res_type, jstart, jend, h, H_ROW, 0);
+ send_updated_ds(res_type, jstart, jend, z, Z_ROW, 0);
+
+ MPI_Recv(&worker, 4, MPI_INT, 0, END_SIGNAL,
+ MPI_COMM_WORLD, &status);
+
+ if (debug & debug_call) {
+ printf("worker %d sent TIDY_UP to master\n", my_id);
+ printf("worker %d got END_SIGNAL from master\n", my_id);
+ }
+}
+
+send_updated_ds(res_type, jstart, jend, ds, indx, master_id)
+ MPI_Datatype * res_type;
+ int jstart;
+ int jend;
+ float ds[n][m];
+ int indx;
+ int master_id;
+{
+ int j;
+ struct res res;
+ MPI_Request rq[2];
+ MPI_Status stat[2];
+
+ for (j = jstart; j <= jend; j++) {
+ acopy_two_to_one(ds, res.row, j);
+ res.indx = j;
+
+ MPI_Send(&res, 1, *res_type, master_id, indx,
+ MPI_COMM_WORLD);
+ }
+}
+
+/*
+this procedure does all the message passing before the call to _calcuvzh_
+*/
+calc_load(prv,nxt,my_id,jstart,jend,p,u,v)
+ int prv;
+ int nxt;
+ int my_id;
+ int jstart;
+ int jend;
+ float p[n][m];
+ float u[n][m];
+ float v[n][m];
+{
+ neighbour_send(prv, my_id, CALC1a, p, jstart);
+ neighbour_send(prv, my_id, CALC1b, u, jstart);
+ neighbour_send(prv, my_id, CALC1c, v, jstart);
+ neighbour_receive(nxt, my_id, CALC1a, p, (jend+1) % n);
+ neighbour_receive(nxt, my_id, CALC1b, u, (jend+1) % n);
+ neighbour_receive(nxt, my_id, CALC1c, v, (jend+1) % n);
+}
+
+/*
+this procedure does all the message passing after the call to _calcuvzh_
+*/
+calc_unload(prv,nxt,my_id,jstart,jend,cv,z)
+ int prv;
+ int nxt;
+ int my_id;
+ int jstart;
+ int jend;
+ float cv[n][m];
+ float z[n][m];
+{
+ neighbour_send(nxt, my_id, CALC2a, cv, (jend+1) % n);
+ neighbour_send(nxt, my_id, CALC2b, z, (jend+1) % n);
+ neighbour_receive(prv, my_id, CALC2a, cv, jstart);
+ neighbour_receive(prv, my_id, CALC2b, z, jstart);
+}
+
+/*
+this procedure does all the message passing before the call to _timetend_
+*/
+time_load(prv,nxt,my_id,jstart,jend,cu,cv,h,z)
+ int prv;
+ int nxt;
+ int my_id;
+ int jstart;
+ int jend;
+ float cu[n][m];
+ float cv[n][m];
+ float h[n][m];
+ float z[n][m];
+{
+ neighbour_send(prv, my_id, TIME1a, cu, jstart);
+ neighbour_send(prv, my_id, TIME1b, cv, jstart);
+ neighbour_send(prv, my_id, TIME1c, h, jstart);
+ neighbour_send(prv, my_id, TIME1d, z, jstart);
+ neighbour_receive(nxt, my_id, TIME1a, cu, (jend+1) % n);
+ neighbour_receive(nxt, my_id, TIME1b, cv, (jend+1) % n);
+ neighbour_receive(nxt, my_id, TIME1c, h, (jend+1) % n);
+ neighbour_receive(nxt, my_id, TIME1d, z, (jend+1) % n);
+}
+
+/*
+this procedure does all the message passing after the call to _timetend_
+*/
+time_unload(prv,nxt,tu_my_id,jstart,jend,dvdt)
+ int prv;
+ int nxt;
+ int tu_my_id;
+ int jstart;
+ int jend;
+ float dvdt[n][m];
+{
+ neighbour_send(nxt, tu_my_id, TIME2, dvdt, (jend+1) % n);
+ neighbour_receive(prv, tu_my_id, TIME2, dvdt, jstart);
+}
+
+/*
+this is a general purpose function for sending packets b/w workers
+*/
+neighbour_send(ns_neighbour,ns_my_id,ns_rec_id,ns_ds,ns_edge)
+ int ns_neighbour;
+ int ns_my_id;
+ int ns_rec_id;
+ float ns_ds[n][m];
+ int ns_edge;
+{
+ float ns_rec[m];
+ MPI_Request rq;
+
+ acopy_two_to_one(ns_ds, ns_rec, ns_edge);
+
+ MPI_Isend(&ns_rec, m, MPI_FLOAT, ns_neighbour, ns_rec_id,
+ MPI_COMM_WORLD, &rq);
+
+ if (debug & debug_worker)
+ printf("worker %d sent packet %d to worker %d\n", ns_my_id,
+ ns_rec_id, ns_neighbour);
+}
+
+/*
+this is a general purpose function for receiving packets b/w workers
+*/
+neighbour_receive(nr_neighbour,nr_my_id,nr_rec_id,nr_ds,nr_edge)
+ int nr_neighbour;
+ int nr_my_id;
+ int nr_rec_id;
+ float nr_ds[n][m];
+ int nr_edge;
+{
+ float nr_rec[m];
+ MPI_Status status;
+
+ MPI_Recv(&nr_rec, m, MPI_FLOAT, nr_neighbour, nr_rec_id,
+ MPI_COMM_WORLD, &status);
+
+ acopy_one_to_two(nr_rec, nr_ds, nr_edge);
+}