LIBDVM2 (1158351), страница 18
Текст из файла (страница 18)
do 21 j = oiniti(1), olasti(1), ostep(1)
do 21 i = oiniti(2), olasti(2), ostep(2)
eps = max(eps, abs(bptr( bhdr(3)+1+i+bhdr(2)*j )
+ - bptr( ahdr(3)+1+i+ahdr(2)*j )))
bptr( ahdr(3) + 1 + i + ahdr(2) * j ) =
+ bptr( bhdr(3) + 1 + i + bhdr(2) * j )
21 continue
goto 99997
99996 dvm = endpl (plref)
C Calculation of reductional maximum
dvm = strtrd (rgref)
dvm = waitrd (rgref)
C Shadow edge exchange
dvm = strtsh (shgref)
dvm = waitsh (shgref)
C Parallel loop to calculate new values
C of the grid function in array bhdr
C (parallel loop with base array bhdr).
plref = crtpl (2)
dvm = mappl ( plref, bhdr, axis, coeff, const, lvaddr,
+ iiniti, ilasti, istep, oiniti, olasti, ostep)
99995 if (dopl (plref) .eq. 0) goto 99994
do 22 j = oiniti(1), olasti(1), ostep(1)
do 22 i = oiniti(2), olasti(2), ostep(2)
bptr(bhdr(3) + 1 + i + bhdr(2) * j) =
+ ( bptr(ahdr(3) + 1 + (i - 1) + ahdr(2) * j) +
+ bptr(ahdr(3) + 1 + i + ahdr(2) * (j - 1)) +
+ bptr(ahdr(3) + 1 + (i + 1) + ahdr(2) * j) +
+ bptr(ahdr(3) + 1 + i + ahdr(2) * (j + 1)) ) / 4.
22 continue
goto 99995
99994 dvm = endpl (plref)
C Printing current deviation of the grid function
if (tstio ()) print *,'IT = ',it,' EPS = ',eps
C Exit, if specified precision is achieved
if (eps .lt. maxeps) goto 3
2 continue
C END OF MAIN ITERATION LOOP
C End of dealing with Run-Time Library
3 dvm = lexit (0)
end
PROGRAM IN C LANGUAGE
#include "dvmlib.h"
int main(int argc, char *argv[])
{
long InitPar = 0, UserRes = 0;
long StaticMV = 0, StaticDA = 0, ReDistrDA = 0, StaticRV = 0,
DelRed = 0, StaticRG = 0, StaticShG = 0, FullShd = 0;
long i, j, it, Rank2 = 2, Long0 = 0, TypeSize = sizeof(float);
long RedFunc = rf_MAX, RVType = rt_FLOAT, RedArrayLength = 1;
AMRef amref;
PSRef psref;
AMViewRef mvref;
LoopRef plref;
RedGroupRef rgref;
RedRef redref;
ShadowGroupRef shgref;
AddrType lvaddr[2];
long amdim[2], disaxs[2], dispar[2];
long shwdth[2], axis[2], coeff[2], cnst[2];
long iiniti[2], ilasti[2], istep[2];
long oiniti[2], olasti[2], ostep[2];
DVMFILE *OutFile;
float eps; /* current precision of calculation */
long k = 8; /* a number of grid points by every dimension*/
float maxeps = 0.5e-2f; /* requied precision of calculation */
long itmax = 200; /* maximal number of iterations */
long Ahdr[3]; /* header of array with previous
values of the grid function */
long Bhdr[3]; /* header of array with next
values of the grid function */
rtl_init(InitPar, argc, argv); /* Run-Time Library initialization */
/* Creating abstract machine representation
and its mapping on processor subsystem */
amref = getam_ ();
psref = getps_ (&amref);
amdim[0] = k;
amdim[1] = k;
mvref = crtamv_ (&amref, &Rank2, amdim, &StaticMV);
disaxs[0] = 1;
disaxs[1] = 2;
dispar[0] = 0;
dispar[1] = 0;
distr_ (&mvref, &psref, &Rank2, disaxs, dispar);
/* Creation and distribution of arrays
with values of the grid function */
shwdth[0] = 1;
shwdth[1] = 1;
/* array with previous values of the grig function */
crtda_ (Ahdr, NULL, &Rank2, &TypeSize, amdim,
&StaticDA, &ReDistrDA,shwdth, shwdth);
/* array with next values of grid function */
crtda_ (Bhdr, NULL, &Rank2, &TypeSize, amdim,
&StaticDA, &ReDistrDA, shwdth, shwdth);
axis[0] = 1;
axis[1] = 2;
coeff[0] = 1;
coeff[1] = 1;
cnst[0] = 0;
cnst[1] = 0;
align_ (Ahdr,&mvref,axis,coeff,cnst);
align_ (Bhdr,&mvref,axis,coeff,cnst);
/* Parallel loop of initializing arrays
with values of the grid function
(parallel loop with base array Ahdr) */
plref = crtpl_ (&Rank2);
lvaddr[0] = (AddrType)&j;
lvaddr[1] = (AddrType)&i;
iiniti[0] = 0;
iiniti[1] = 0;
ilasti[0] = k - 1;
ilasti[1] = k - 1;
istep[0] = 1;
istep[1] = 1;
mappl_ (&plref, (PatternRef *)Ahdr, axis, coeff, cnst, lvaddr,
iiniti, ilasti, istep, oiniti, olasti, ostep);
while (dopl_ (&plref))
for ( j = oiniti[0]; j <= olasti[0]; j += ostep[0] )
for ( i = oiniti[1]; i <= olasti[1]; i += ostep[1] )
{ DAElm2(Ahdr, float, j, i) = 0.;
DAElm2(Bhdr, float, j, i) = 1.f + i + j;
}
endpl_ (&plref);
/* Creating reduction variable and reduction group
to calculate maximal deviation of the grid function for
two sequential iterations. */
redref = crtred_ (&RedFunc, &eps, &RVType, &RedArrayLength,
NULL, &Long0, &StaticRV);
rgref = crtrg_ (&StaticRG, &DelRed);
insred_ (&rgref, &redref);
/* Creating shadow edge group for renewing shadow edges */
shgref = crtshg_ (&StaticShG);
inssh_ (&shgref, Ahdr, shwdth, shwdth, &FullShd);
/* MAIN ITERATION LOOP */
for (it = 1; it <= itmax; it++)
{
/* Parallel loop to calculate maximal deviation
of the grid function in variable eps
(parallel loop with base array Ahdr). */
plref = crtpl_ (&Rank2);
iiniti[0] = 1;
iiniti[1] = 1;
ilasti[0] = k - 2;
ilasti[1] = k - 2;
mappl_ (&plref, (PatternRef *)Ahdr, axis, coeff, cnst, lvaddr,
iiniti, ilasti, istep, oiniti, olasti, ostep);
eps = 0.;
while (dopl_ (&plref))
for ( j = oiniti[0]; j <= olasti[0]; j += ostep[0] )
for ( i = oiniti[1]; i <= olasti[1]; i += ostep[1] )
{ eps = max(eps, dvm_abs( DAElm2(Bhdr,float,j,i) -
DAElm2(Ahdr,float,j,i) ));
DAElm2(Ahdr, float, j, i) =
DAElm2(Bhdr, float, j, i);
}
endpl_ (&plref);
/* Calculation of reductional maximum */
strtrd_ (&rgref);
waitrd_ (&rgref);
/* Shadow edges exchange */
strtsh_ (&shgref);
waitsh_ (&shgref);
/* Parallel loop to calculate new values
of the grid function in array bhdr
(parallel loop with base array Bhdr). */
plref = crtpl_ (&Rank2);
mappl_ (&plref, (PatternRef *)Bhdr, axis, coeff, cnst, lvaddr,
iiniti, ilasti, istep, oiniti, olasti, ostep);
while (dopl_ (&plref))
for ( j = oiniti[0]; j <= olasti[0]; j += ostep[0] )
for ( i = oiniti[1]; i <= olasti[1]; i += ostep[1] )
DAElm2(Bhdr, float, j, i) =
( DAElm2(Ahdr, float, j, i-1) +
DAElm2(Ahdr, float, j-1, i) +
DAElm2(Ahdr, float, j, i+1) +
DAElm2(Ahdr, float, j+1, i) ) / 4.f;
endpl_ (&plref);
/* Printing current deviation of grid function */
dvm_printf("IT = %ld EPS = %e\n", it, eps);
if (eps < maxeps)
break; /* exit, if specified precision is achieved */
}
/* END OF MAIN ITERATION LOOP */
/* Writing solution in the file and end of work with Run-Time Library */
OutFile = dvm_fopen("cross.dat", "w+b");
if(OutFile)
{ dvm_dfwrite(Bhdr, 0, OutFile);
dvm_fclose(OutFile);
}
lexit_ (&UserRes);
return (int)UserRes;
}.















