test18.c
来自「shpf 1.9一个并行编译器」· C语言 代码 · 共 926 行 · 第 1/2 页
C
926 行
// !hpf$ processors q(2, 3)
//
// !hpf$ template s(4, 100)
// !hpf$ distribute s(block, cyclic(6)) onto q
//
// integer a(80)
// real b(80)
// double precision c(80)
// logical m(80)
// !hpf$ align a(j) with s(2, 15 + j)
// !hpf$ align b(:) with a(:)
// !hpf$ align c(:) with a(:)
// !hpf$ align m(:) with a(:)
//
// do i = 1, 80
// if(i < 13) then
// a(i) = i
// b(i) = i
// c(i) = i
// else
// a(i) = 1
// b(i) = 1
// c(i) = 1
// endif
// m(i) = .false.
// enddo
//
// m(3) = .true.
// m(5) = .true.
// m(7) = .true.
// m(9) = .true.
//
// print "(i15,f15.2,f15.2)", maxval(a), maxval(b), maxval(c)
// print "(i15,f15.2,f15.2)", &
// & maxval(a, mask = m), maxval(b, mask = m), maxval(c, mask = m)
// print "(i15,f15.2,f15.2)", minval(a), minval(b), minval(c)
// print "(i15,f15.2,f15.2)", &
// & minval(a, mask = m), minval(b, mask = m), minval(c, mask = m)
// print "(i15,f15.2,f15.2)", sum(a), sum(b), sum(c)
// print "(i15,f15.2,f15.2)", &
// & sum(a, mask = m), sum(b, mask = m), sum(c, mask = m)
// print "(i15,f15.2,f15.2)", product(a), product(b), product(c)
// print "(i15,f15.2,f15.2)", &
// & product(a, mask = m), product(b, mask = m), product(c, mask = m)
// print "(i15,i15,i15)", maxloc(a), maxloc(b), maxloc(c)
// print "(i15,i15,i15)", &
// & maxloc(a, mask = m), maxloc(b, mask = m), maxloc(c, mask = m)
// print "(i15,i15,i15)", minloc(a), minloc(b), minloc(c)
// print "(i15,i15,i15)", &
// & minloc(a, mask = m), minloc(b, mask = m), minloc(c, mask = m)
//end
#include <stdio.h>
#include "ad++.h"
#include "admacros.h"
// Platform-dependent constants
// Largest and smallest values of arithmetic types
const int MOST_NEG_INT = 0x80000000 ;
const int MOST_POS_INT = 0x7fffffff ;
const float MOST_POS_FLOAT = 3.4028235E+38 ;
const float MOST_NEG_FLOAT = -3.4028235E+38 ;
const double MOST_POS_DOUBLE = 1.7976931348623157E+308 ;
const double MOST_NEG_DOUBLE = -1.7976931348623157E+308 ;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// //
// Arithmetic to support F90 array intrinsics. //
// //
// In principle these are platform-dependent because they assume a //
// particular mapping between Fortran and C arithmetic types. //
// //
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// Accumulation (under addition)...
static void ad_zeroInt(void* dat) {
*((int*) dat) = 0 ;
}
static void ad_zeroFloat(void* dat) {
*((float*) dat) = 0.0 ;
}
static void ad_zeroDouble(void* dat) {
*((double*) dat) = 0.0 ;
}
static void ad_zeroComplex(void* dat) {
float* fdat = (float*) dat ;
fdat [0] = 0.0 ;
fdat [1] = 0.0 ;
}
static void ad_accumInt(void* acc, void* val) {
*((int*) acc) += *((int*) val) ;
}
static void ad_accumFloat(void* acc, void* val) {
*((float*) acc) += *((float*) val) ;
}
static void ad_accumDouble(void* acc, void* val) {
*((double*) acc) += *((double*) val) ;
}
static void ad_accumComplex(void* acc, void* val) {
float* facc = (float*) acc ;
float* fval = (float*) val ;
facc [0] += fval [0] ;
facc [1] += fval [1] ;
}
static void ad_incrIfIntInt(void* acc, void* dum, void* msk) {
if(*((int*) msk)) (*((int*) acc))++ ;
}
static void ad_accumIfIntInt(void* acc, void* val, void* msk) {
if(*((int*) msk)) *((int*) acc) += *((int*) val) ;
}
static void ad_accumIfFloatInt(void* acc, void* val, void* msk) {
if(*((int*) msk)) *((float*) acc) += *((float*) val) ;
}
static void ad_accumIfDoubleInt(void* acc, void* val, void* msk) {
if(*((int*) msk)) *((double*) acc) += *((double*) val) ;
}
static void ad_accumIfComplexInt(void* acc, void* val, void* msk) {
if(*((int*) msk)) {
float* facc = (float*) acc ;
float* fval = (float*) val ;
facc [0] += fval [0] ;
facc [1] += fval [1] ;
}
}
// Multiplicative accumulation...
static void ad_unitInt(void* dat) {
*((int*) dat) = 1 ;
}
static void ad_unitFloat(void* dat) {
*((float*) dat) = 1.0 ;
}
static void ad_unitDouble(void* dat) {
*((double*) dat) = 1.0 ;
}
static void ad_unitComplex(void* dat) {
float* fdat = (float*) dat ;
fdat [0] = 1.0 ;
fdat [1] = 0.0 ;
}
static void ad_accumMulInt(void* acc, void* val) {
*((int*) acc) *= *((int*) val) ;
}
static void ad_accumMulFloat(void* acc, void* val) {
*((float*) acc) *= *((float*) val) ;
}
static void ad_accumMulDouble(void* acc, void* val) {
*((double*) acc) *= *((double*) val) ;
}
static void ad_accumMulComplex(void* acc, void* val) {
float* facc = (float*) acc ;
float* fval = (float*) val ;
facc [0] *= fval [0] ;
facc [1] *= fval [1] ;
}
static void ad_accumMulIfIntInt(void* acc, void* val, void* msk) {
if(*((int*) msk)) *((int*) acc) *= *((int*) val) ;
}
static void ad_accumMulIfFloatInt(void* acc, void* val, void* msk) {
if(*((int*) msk)) *((float*) acc) *= *((float*) val) ;
}
static void ad_accumMulIfDoubleInt(void* acc, void* val, void* msk) {
if(*((int*) msk)) *((double*) acc) *= *((double*) val) ;
}
static void ad_accumMulIfComplexInt(void* acc, void* val, void* msk) {
if(*((int*) msk)) {
float* facc = (float*) acc ;
float* fval = (float*) val ;
facc [0] *= fval [0] ;
facc [1] *= fval [1] ;
}
}
// Boolean accumulations...
static void ad_trueLogical(void* dat) {
*((int*) dat) = 1 ;
}
static void ad_accumAndLogical(void* acc, void* val) {
*((int*) acc) = *((int*) acc) && *((int*) val) ;
}
static void ad_falseLogical(void* dat) {
*((int*) dat) = 0 ;
}
static void ad_accumOrLogical(void* acc, void* val) {
*((int*) acc) = *((int*) acc) || *((int*) val) ;
}
// `Max' accumulation...
static void ad_mostNegInt(void* dat) {
*((int*) dat) = MOST_NEG_INT ;
}
static void ad_mostNegFloat(void* dat) {
*((float*) dat) = MOST_NEG_FLOAT ;
}
static void ad_mostNegDouble(void* dat) {
*((double*) dat) = MOST_NEG_DOUBLE ;
}
static int ad_accumMaxInt(void* acc, void* val) {
int* iacc = (int*) acc ;
int* ival = (int*) val ;
if(*ival >= *iacc) {
*iacc = *ival ;
return 1 ;
}
else
return 0 ;
}
static int ad_accumMaxFloat(void* acc, void* val) {
float* iacc = (float*) acc ;
float* ival = (float*) val ;
if(*ival >= *iacc) {
*iacc = *ival ;
return 1 ;
}
else
return 0 ;
}
static int ad_accumMaxDouble(void* acc, void* val) {
double* iacc = (double*) acc ;
double* ival = (double*) val ;
if(*ival >= *iacc) {
*iacc = *ival ;
return 1 ;
}
else
return 0 ;
}
static int ad_accumMaxIfIntInt(void* acc, void* val, void* msk) {
int* iacc = (int*) acc ;
int* ival = (int*) val ;
int* imsk = (int*) msk ;
if(*imsk && *ival >= *iacc) {
*iacc = *ival ;
return 1 ;
}
else
return 0 ;
}
static int ad_accumMaxIfFloatInt(void* acc, void* val, void* msk) {
float* iacc = (float*) acc ;
float* ival = (float*) val ;
int* imsk = (int*) msk ;
if(*imsk && *ival >= *iacc) {
*iacc = *ival ;
return 1 ;
}
else
return 0 ;
}
static int ad_accumMaxIfDoubleInt(void* acc, void* val, void* msk) {
double* iacc = (double*) acc ;
double* ival = (double*) val ;
int* imsk = (int*) msk ;
if(*imsk && *ival >= *iacc) {
*iacc = *ival ;
return 1 ;
}
else
return 0 ;
}
// `Min' accumulation...
static void ad_mostPosInt(void* dat) {
*((int*) dat) = MOST_POS_INT ;
}
static void ad_mostPosFloat(void* dat) {
*((float*) dat) = MOST_POS_FLOAT ;
}
static void ad_mostPosDouble(void* dat) {
*((double*) dat) = MOST_POS_DOUBLE ;
}
static int ad_accumMinInt(void* acc, void* val) {
int* iacc = (int*) acc ;
int* ival = (int*) val ;
if(*ival <= *iacc) {
*iacc = *ival ;
return 1 ;
}
else
return 0 ;
}
static int ad_accumMinFloat(void* acc, void* val) {
float* iacc = (float*) acc ;
float* ival = (float*) val ;
if(*ival <= *iacc) {
*iacc = *ival ;
return 1 ;
}
else
return 0 ;
}
static int ad_accumMinDouble(void* acc, void* val) {
double* iacc = (double*) acc ;
double* ival = (double*) val ;
if(*ival <= *iacc) {
*iacc = *ival ;
return 1 ;
}
else
return 0 ;
}
static int ad_accumMinIfIntInt(void* acc, void* val, void* msk) {
int* iacc = (int*) acc ;
int* ival = (int*) val ;
int* imsk = (int*) msk ;
if(*imsk && *ival <= *iacc) {
*iacc = *ival ;
return 1 ;
}
else
return 0 ;
}
static int ad_accumMinIfFloatInt(void* acc, void* val, void* msk) {
float* iacc = (float*) acc ;
float* ival = (float*) val ;
int* imsk = (int*) msk ;
if(*imsk && *ival <= *iacc) {
*iacc = *ival ;
return 1 ;
}
else
return 0 ;
}
static int ad_accumMinIfDoubleInt(void* acc, void* val, void* msk) {
double* iacc = (double*) acc ;
double* ival = (double*) val ;
int* imsk = (int*) msk ;
if(*imsk && *ival <= *iacc) {
*iacc = *ival ;
return 1 ;
}
else
return 0 ;
}
// ``Scalar product'' accumulation...
static void ad_accumProdIntInt(void* acc, void* arg1, void* arg2) {
*((int*) acc) += *((int*) arg1) * *((int*) arg2) ;
}
static void ad_accumProdIntFloat(void* acc, void* arg1, void* arg2) {
*((float*) acc) += *((int*) arg1) * *((float*) arg2) ;
}
static void ad_accumProdIntDouble(void* acc, void* arg1, void* arg2) {
*((double*) acc) += *((int*) arg1) * *((double*) arg2) ;
}
static void ad_accumProdIntComplex(void* acc, void* arg1, void* arg2) {
float* facc = (float*) acc ;
float* farg2 = (float*) arg2 ;
facc [0] += *((int*) arg1) * farg2 [0] ;
facc [1] += *((int*) arg1) * farg2 [1] ;
}
static void ad_accumProdFloatInt(void* acc, void* arg1, void* arg2) {
*((float*) acc) += *((float*) arg1) * *((int*) arg2) ;
}
static void ad_accumProdFloatFloat(void* acc, void* arg1, void* arg2) {
*((float*) acc) += *((float*) arg1) * *((float*) arg2) ;
}
static void ad_accumProdFloatDouble(void* acc, void* arg1, void* arg2) {
*((float*) acc) += *((float*) arg1) * *((double*) arg2) ;
}
static void ad_accumProdFloatComplex(void* acc, void* arg1, void* arg2) {
float* facc = (float*) acc ;
float* farg2 = (float*) arg2 ;
facc [0] += *((float*) arg1) * farg2 [0] ;
facc [1] += *((float*) arg1) * farg2 [1] ;
}
static void ad_accumProdDoubleInt(void* acc, void* arg1, void* arg2) {
*((double*) acc) += *((double*) arg1) * *((int*) arg2) ;
}
static void ad_accumProdDoubleFloat(void* acc, void* arg1, void* arg2) {
*((double*) acc) += *((double*) arg1) * *((float*) arg2) ;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?