file_path stringlengths 19 84 | content stringlengths 235 1.29M |
|---|---|
./openacc-vv/serial_loop_reduction_multiply_general.F90 | #ifndef T1
!T1:serial,reduction,combined-constructs,loop,V:2.6-2.7
LOGICAL FUNCTION test1()
IMPLICIT NONE
INCLUDE "acc_testsuite.Fh"
REAL(8),DIMENSION(10):: a, b
REAL(8):: reduced, host_reduced
INTEGER:: errors, x, y
errors = 0
SEEDDIM(1) = 1
# ifdef SEED
SEEDDIM(1) = SEED
# endif
CALL RANDOM_SEED(PUT=SEEDDIM)
DO y = 1, LOOPCOUNT
CALL RANDOM_NUMBER(a)
CALL RANDOM_NUMBER(b)
reduced = 1
host_reduced = 1
DO x = 1, 10
host_reduced = host_reduced * (a(x) + b(x))
END DO
!$acc data copyin(a(1:10), b(1:10))
!$acc serial loop reduction(*:reduced)
DO x = 1, 10
reduced = reduced * (a(x) + b(x))
END DO
!$acc end data
IF (abs(host_reduced - reduced) .gt. PRECISION) THEN
errors = errors + 1
END IF
END DO
IF (errors .eq. 0) THEN
test1 = .FALSE.
ELSE
test1 = .TRUE.
END IF
END
#endif
PROGRAM main
IMPLICIT NONE
INTEGER :: failcode, testrun
LOGICAL :: failed
INCLUDE "acc_testsuite.Fh"
#ifndef T1
LOGICAL :: test1
#endif
failed = .FALSE.
failcode = 0
#ifndef T1
DO testrun = 1, NUM_TEST_CALLS
failed = failed .or. test1()
END DO
IF (failed) THEN
failcode = failcode + 2 ** 0
failed = .FALSE.
END IF
#endif
CALL EXIT (failcode)
END PROGRAM
|
./openacc-vv/atomic_x_eqv_expr_end.F90 | #ifndef T1
!T1:construct-independent,atomic,V:2.0-2.7
LOGICAL FUNCTION test1()
IMPLICIT NONE
INCLUDE "acc_testsuite.Fh"
INTEGER :: x, y !Iterators
REAL(8),DIMENSION(LOOPCOUNT, 10):: randoms
LOGICAL,DIMENSION(LOOPCOUNT, 10):: a !Data
LOGICAL,DIMENSION(LOOPCOUNT):: totals, totals_comparison
INTEGER :: errors = 0
!Initilization
SEEDDIM(1) = 1
# ifdef SEED
SEEDDIM(1) = SEED
# endif
CALL RANDOM_SEED(PUT=SEEDDIM)
CALL RANDOM_NUMBER(randoms)
DO x = 1, LOOPCOUNT
DO y = 1, 10
IF (randoms(x, y) > .5) THEN
a(x, y) = .TRUE.
ELSE
a(x, y) = .FALSE.
END IF
END DO
END DO
totals = .FALSE.
totals_comparison = .FALSE.
!$acc data copyin(a(1:LOOPCOUNT,1:10)) copy(totals(1:LOOPCOUNT))
!$acc parallel
!$acc loop
DO x = 1, LOOPCOUNT
DO y = 1, 10
!$acc atomic
totals(x) = totals(x) .EQV. a(x, y)
!$acc end atomic
END DO
END DO
!$acc end parallel
!$acc end data
DO x = 1, LOOPCOUNT
DO y = 1, 10
totals_comparison(x) = totals_comparison(x) .EQV. a(x, y)
END DO
END DO
DO x = 1, LOOPCOUNT
IF (totals_comparison(x) .NEQV. totals(x)) THEN
errors = errors + 1
WRITE(*, *) totals_comparison(x)
END IF
END DO
IF (errors .eq. 0) THEN
test1 = .FALSE.
ELSE
test1 = .TRUE.
END IF
END
#endif
PROGRAM main
IMPLICIT NONE
INTEGER :: failcode, testrun
LOGICAL :: failed
INCLUDE "acc_testsuite.Fh"
#ifndef T1
LOGICAL :: test1
#endif
failed = .FALSE.
failcode = 0
#ifndef T1
DO testrun = 1, NUM_TEST_CALLS
failed = failed .or. test1()
END DO
IF (failed) THEN
failcode = failcode + 2 ** 0
failed = .FALSE.
END IF
#endif
CALL EXIT (failcode)
END PROGRAM
|
./openacc-npb/CG/CG/cg.c | //-------------------------------------------------------------------------//
// //
// This benchmark is a serial C version of the NPB CG code. This C //
// version is developed by the Center for Manycore Programming at Seoul //
// National University and derived from the serial Fortran versions in //
// "NPB3.3-SER" developed by NAS. //
// //
// Permission to use, copy, distribute and modify this software for any //
// purpose with or without fee is hereby granted. This software is //
// provided "as is" without express or implied warranty. //
// //
// Information on NPB 3.3, including the technical report, the original //
// specifications, source code, results and information on how to submit //
// new results, is available at: //
// //
// http://www.nas.nasa.gov/Software/NPB/ //
// //
// Send comments or suggestions for this C version to cmp@aces.snu.ac.kr //
// //
// Center for Manycore Programming //
// School of Computer Science and Engineering //
// Seoul National University //
// Seoul 151-744, Korea //
// //
// E-mail: cmp@aces.snu.ac.kr //
// //
//-------------------------------------------------------------------------//
//-------------------------------------------------------------------------//
// Authors: Sangmin Seo, Jungwon Kim, Jun Lee, Jeongho Nah, Gangwon Jo, //
// and Jaejin Lee //
//-------------------------------------------------------------------------//
//-------------------------------------------------------------------------//
//// //
//// The OpenACC C version of the NAS CG code is developed by the //
//// HPCTools Group of University of Houston and derived from the serial //
//// C version developed by SNU and Fortran versions in "NPB3.3-SER" //
//// developed by NAS. //
//// //
//// Permission to use, copy, distribute and modify this software for any //
//// purpose with or without fee is hereby granted. This software is //
//// provided "as is" without express or implied warranty. //
//// //
//// Send comments or suggestions for this OpenACC version to //
//// hpctools@cs.uh.edu //
////
//// Information on NPB 3.3, including the technical report, the original //
//// specifications, source code, results and information on how to submit //
//// new results, is available at: //
//// //
//// http://www.nas.nasa.gov/Software/NPB/ //
//// //
////-------------------------------------------------------------------------//
//
////-------------------------------------------------------------------------//
//// Authors: Rengan Xu, Sunita Chandrasekaran, Barbara Chapman //
////-------------------------------------------------------------------------//
//---------------------------------------------------------------------
// NPB CG OpenACC version
//---------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "globals.h"
#include "randdp.h"
#include "timers.h"
#include "print_results.h"
#include <openacc.h>
//---------------------------------------------------------------------
unsigned int nz = (NA*(NONZER+1)*(NONZER+1));
unsigned int naz = (NA*(NONZER+1));
unsigned int na = NA;
/* common / main_int_mem / */
static int colidx[NZ];
static int rowstr[NA+1];
static int iv[NA];
static int arow[NA];
static int acol[NAZ];
/* common / main_flt_mem / */
static double aelt[NAZ];
static double a[NZ];
static double x[NA+2];
static double z[NA+2];
static double p[NA+2];
static double q[NA+2];
static double r[NA+2];
/* common / partit_size / */
static int naa;
static int nzz;
static int firstrow;
static int lastrow;
static int firstcol;
static int lastcol;
/* common /urando/ */
static double amult;
static double tran;
/* common /timers/ */
static logical timeron;
//---------------------------------------------------------------------
//---------------------------------------------------------------------
static void conj_grad(int colidx[],
int rowstr[],
double x[],
double z[],
double a[],
double p[],
double q[],
double r[],
double *rnorm);
static void makea(int n,
int nz,
double a[],
int colidx[],
int rowstr[],
int firstrow,
int lastrow,
int firstcol,
int lastcol,
int arow[],
int acol[][NONZER+1],
double aelt[][NONZER+1],
int iv[]);
static void sparse(double a[],
int colidx[],
int rowstr[],
int n,
int nz,
int nozer,
int arow[],
int acol[][NONZER+1],
double aelt[][NONZER+1],
int firstrow,
int lastrow,
int nzloc[],
double rcond,
double shift);
static void sprnvc(int n, int nz, int nn1, double v[], int iv[]);
static int icnvrt(double x, int ipwr2);
static void vecset(int n, double v[], int iv[], int *nzv, int i, double val);
static int conj_calls = 0;
static int loop_iter = 0;
//---------------------------------------------------------------------
int main(int argc, char *argv[])
{
int i, j, k, it;
int end;
double zeta;
double rnorm;
double norm_temp1, norm_temp2;
double t, mflops, tmax;
char Class;
int verified;
double zeta_verify_value, epsilon, err;
char *t_names[T_last];
acc_init(acc_device_default);
for (i = 0; i < T_last; i++) {
timer_clear(i);
}
FILE *fp;
if ((fp = fopen("timer.flag", "r")) != NULL) {
timeron = true;
t_names[T_init] = "init";
t_names[T_bench] = "benchmk";
t_names[T_conj_grad] = "conjgd";
fclose(fp);
} else {
timeron = false;
}
timer_start(T_init);
firstrow = 0;
lastrow = NA-1;
firstcol = 0;
lastcol = NA-1;
if (NA == 1400 && NONZER == 7 && NITER == 15 && SHIFT == 10) {
Class = 'S';
zeta_verify_value = 8.5971775078648;
} else if (NA == 7000 && NONZER == 8 && NITER == 15 && SHIFT == 12) {
Class = 'W';
zeta_verify_value = 10.362595087124;
} else if (NA == 14000 && NONZER == 11 && NITER == 15 && SHIFT == 20) {
Class = 'A';
zeta_verify_value = 17.130235054029;
} else if (NA == 75000 && NONZER == 13 && NITER == 75 && SHIFT == 60) {
Class = 'B';
zeta_verify_value = 22.712745482631;
} else if (NA == 150000 && NONZER == 15 && NITER == 75 && SHIFT == 110) {
Class = 'C';
zeta_verify_value = 28.973605592845;
} else if (NA == 1500000 && NONZER == 21 && NITER == 100 && SHIFT == 500) {
Class = 'D';
zeta_verify_value = 52.514532105794;
} else if (NA == 9000000 && NONZER == 26 && NITER == 100 && SHIFT == 1500) {
Class = 'E';
zeta_verify_value = 77.522164599383;
} else {
Class = 'U';
}
printf("\n\n NAS Parallel Benchmarks (NPB3.3-ACC-C) - CG Benchmark\n\n");
printf(" Size: %11d\n", NA);
printf(" Iterations: %5d\n", NITER);
printf("\n");
naa = NA;
nzz = NZ;
//---------------------------------------------------------------------
// Inialize random number generator
//---------------------------------------------------------------------
tran = 314159265.0;
amult = 1220703125.0;
zeta = randlc(&tran, amult);
//---------------------------------------------------------------------
//
//---------------------------------------------------------------------
makea(naa, nzz, a, colidx, rowstr,
firstrow, lastrow, firstcol, lastcol,
arow,
(int (*)[NONZER+1])(void*)acol,
(double (*)[NONZER+1])(void*)aelt,
iv);
//---------------------------------------------------------------------
// Note: as a result of the above call to makea:
// values of j used in indexing rowstr go from 0 --> lastrow-firstrow
// values of colidx which are col indexes go from firstcol --> lastcol
// So:
// Shift the col index vals from actual (firstcol --> lastcol )
// to local, i.e., (0 --> lastcol-firstcol)
//---------------------------------------------------------------------
for (j = 0; j < lastrow - firstrow + 1; j++) {
for (k = rowstr[j]; k < rowstr[j+1]; k++) {
colidx[k] = colidx[k] - firstcol;
}
}
#pragma acc data copyin(colidx[0:nz],a[0:nz], \
rowstr[0:na+1]) \
create(x[0:na+2],z[0:na+2], \
p[0:na+2],q[0:na+2], \
r[0:na+2])
{
//---------------------------------------------------------------------
// set starting vector to (1, 1, .... 1)
//---------------------------------------------------------------------
int na_gangs = NA+1;
#pragma acc kernels loop gang((na_gangs+127)/128) vector(128)
for (i = 0; i < NA+1; i++) {
x[i] = 1.0;
}
end = lastcol - firstcol + 1;
#pragma acc kernels loop gang((end+127)/128) vector(128)
for (j = 0; j < end; j++) {
q[j] = 0.0;
z[j] = 0.0;
r[j] = 0.0;
p[j] = 0.0;
}
zeta = 0.0;
//---------------------------------------------------------------------
//---->
// Do one iteration untimed to init all code and data page tables
//----> (then reinit, start timing, to niter its)
//---------------------------------------------------------------------
for (it = 1; it <= 1; it++) {
//---------------------------------------------------------------------
// The call to the conjugate gradient routine:
//---------------------------------------------------------------------
conj_grad(colidx, rowstr, x, z, a, p, q, r, &rnorm);
//---------------------------------------------------------------------
// zeta = shift + 1/(x.z)
// So, first: (x.z)
// Also, find norm of z
// So, first: (z.z)
//---------------------------------------------------------------------
norm_temp1 = 0.0;
norm_temp2 = 0.0;
#pragma acc parallel loop num_gangs((end+127)/128) num_workers(4) \
vector_length(32) reduction(+:norm_temp2)
for (j = 0; j < end; j++) {
//norm_temp1 = norm_temp1 + x[j] * z[j];
norm_temp2 = norm_temp2 + z[j] * z[j];
}
norm_temp2 = 1.0 / sqrt(norm_temp2);
//---------------------------------------------------------------------
// Normalize z to obtain x
//---------------------------------------------------------------------
#pragma acc kernels loop gang((end+127)/128) vector(128)
for (j = 0; j < end; j++) {
x[j] = norm_temp2 * z[j];
}
} // end of do one iteration untimed
//---------------------------------------------------------------------
// set starting vector to (1, 1, .... 1)
//---------------------------------------------------------------------
na_gangs = NA+1;
#pragma acc kernels loop gang((na_gangs+127)/128) vector(128)
for (i = 0; i < NA+1; i++) {
x[i] = 1.0;
}
zeta = 0.0;
timer_stop(T_init);
printf(" Initialization time = %15.3f seconds\n", timer_read(T_init));
timer_start(T_bench);
//---------------------------------------------------------------------
//---->
// Main Iteration for inverse power method
//---->
//---------------------------------------------------------------------
for (it = 1; it <= NITER; it++) {
//---------------------------------------------------------------------
// The call to the conjugate gradient routine:
//---------------------------------------------------------------------
conj_grad(colidx, rowstr, x, z, a, p, q, r, &rnorm);
//---------------------------------------------------------------------
// zeta = shift + 1/(x.z)
// So, first: (x.z)
// Also, find norm of z
// So, first: (z.z)
//---------------------------------------------------------------------
norm_temp1 = 0.0;
norm_temp2 = 0.0;
#pragma acc parallel loop gang worker vector num_gangs((end+127)/128) num_workers(4) \
vector_length(32) reduction(+:norm_temp1,norm_temp2)
for (j = 0; j < end; j++) {
norm_temp1 = norm_temp1 + x[j]*z[j];
norm_temp2 = norm_temp2 + z[j]*z[j];
}
norm_temp2 = 1.0 / sqrt(norm_temp2);
zeta = SHIFT + 1.0 / norm_temp1;
if (it == 1)
printf("\n iteration ||r|| zeta\n");
printf(" %5d %20.14E%20.13f\n", it, rnorm, zeta);
//---------------------------------------------------------------------
// Normalize z to obtain x
//---------------------------------------------------------------------
#pragma acc kernels loop gang((end+127)/128) vector(128)
for (j = 0; j < end; j++) {
x[j] = norm_temp2 * z[j];
}
} // end of main iter inv pow meth
timer_stop(T_bench);
}/*end acc data*/
//---------------------------------------------------------------------
// End of timed section
//---------------------------------------------------------------------
t = timer_read(T_bench);
printf(" Benchmark completed\n");
epsilon = 1.0e-10;
if (Class != 'U') {
err = fabs(zeta - zeta_verify_value) / zeta_verify_value;
if (err <= epsilon) {
verified = true;
printf(" VERIFICATION SUCCESSFUL\n");
printf(" Zeta is %20.13E\n", zeta);
printf(" Error is %20.13E\n", err);
} else {
verified = false;
printf(" VERIFICATION FAILED\n");
printf(" Zeta %20.13E\n", zeta);
printf(" The correct zeta is %20.13E\n", zeta_verify_value);
}
} else {
verified = false;
printf(" Problem size unknown\n");
printf(" NO VERIFICATION PERFORMED\n");
}
if (t != 0.0) {
mflops = (double)(2*NITER*NA)
* (3.0+(double)(NONZER*(NONZER+1))
+ 25.0*(5.0+(double)(NONZER*(NONZER+1)))
+ 3.0) / t / 1000000.0;
} else {
mflops = 0.0;
}
print_results("CG", Class, NA, 0, 0,
NITER, t,
mflops, " floating point",
verified, NPBVERSION, COMPILETIME,
CS1, CS2, CS3, CS4, CS5, CS6, CS7);
//---------------------------------------------------------------------
// More timers
//---------------------------------------------------------------------
if (timeron) {
tmax = timer_read(T_bench);
if (tmax == 0.0) tmax = 1.0;
printf(" SECTION Time (secs)\n");
for (i = 0; i < T_last; i++) {
t = timer_read(i);
if (i == T_init) {
printf(" %8s:%9.3f\n", t_names[i], t);
} else {
printf(" %8s:%9.3f (%6.2f%%)\n", t_names[i], t, t*100.0/tmax);
if (i == T_conj_grad) {
t = tmax - t;
printf(" --> %8s:%9.3f (%6.2f%%)\n", "rest", t, t*100.0/tmax);
}
}
}
}
acc_shutdown(acc_device_default);
printf("conj calls=%d, loop iter = %d. \n", conj_calls, loop_iter);
return 0;
}
//---------------------------------------------------------------------
// Floaging point arrays here are named as in NPB1 spec discussion of
// CG algorithm
//---------------------------------------------------------------------
static void conj_grad(int colidx[],
int rowstr[],
double x[],
double z[],
double a[],
double p[],
double q[],
double r[],
double *rnorm)
{
int j, k,tmp1,tmp2,tmp3;
int end;
int cgit, cgitmax = 25;
double d, sum, rho, rho0, alpha, beta;
double sum_array[NA+2];
conj_calls ++;
rho = 0.0;
unsigned int num_gangs = 0;
#pragma acc data present(colidx[0:nz], \
rowstr[0:na+1], \
x[0:na+2],z[0:na+2], \
a[0:nz],p[0:na+2], \
q[0:na+2],r[0:na+2])
{
//---------------------------------------------------------------------
// Initialize the CG algorithm:
//---------------------------------------------------------------------
#pragma acc kernels loop gang((naa+127)/128) vector(128) independent
for (j = 0; j < naa; j++) {
q[j] = 0.0;
z[j] = 0.0;
r[j] = x[j];
p[j] = r[j];
}
//---------------------------------------------------------------------
// rho = r.r
// Now, obtain the norm of r: First, sum squares of r elements locally...
//---------------------------------------------------------------------
//num_gangs = (lastcol - firstcol + 1)/128;
#pragma acc parallel loop gang worker vector num_gangs((lastcol-firstcol+1+127)/128) \
num_workers(4) vector_length(32) reduction(+:rho)
for (j = 0; j < lastcol - firstcol + 1; j++) {
rho = rho + r[j]*r[j];
}
//---------------------------------------------------------------------
//---->
// The conj grad iteration loop
//---->
//---------------------------------------------------------------------
//#pragma acc kernels loop private(cgit,j,k)
for (cgit = 1; cgit <= cgitmax; cgit++) {
//#pragma acc update host(p[0:NA+2])
//---------------------------------------------------------------------
// q = A.p
// The partition submatrix-vector multiply: use workspace w
//---------------------------------------------------------------------
//
// NOTE: this version of the multiply is actually (slightly: maybe %5)
// faster on the sp2 on 16 nodes than is the unrolled-by-2 version
// below. On the Cray t3d, the reverse is true, i.e., the
// unrolled-by-two version is some 10% faster.
// The unrolled-by-8 version below is significantly faster
// on the Cray t3d - overall speed of code is 1.5 times faster.
/*
for (j = 0; j < lastrow - firstrow + 1; j++) {
sum_array[j]=0.0;
}
for (j = 0; j < lastrow - firstrow + 1; j++) {
tmp1=rowstr[j];
tmp2=rowstr[j+1];
for (k = tmp1; k < tmp2; k++) {
tmp3=colidx[k];
sum_array[j] = sum_array[j] + a[k]*p[tmp3];
}
q[j] = sum_array[j];
}
*/
loop_iter ++;
//num_gangs = (lastrow - firstrow + 1)/128;
end = lastrow - firstrow + 1;
#pragma acc parallel num_gangs(end) num_workers(4) vector_length(32)
{
#pragma acc loop gang
for (j = 0; j < end; j++) {
tmp1 = rowstr[j];
tmp2 = rowstr[j+1];
sum = 0.0;
#pragma acc loop worker vector reduction(+:sum)
for (k = tmp1; k < tmp2; k++) {
tmp3 = colidx[k];
sum = sum + a[k]*p[tmp3];
}
q[j] = sum;
}
}
//---------------------------------------------------------------------
// Obtain p.q
//---------------------------------------------------------------------
d = 0.0;
end = lastcol - firstcol + 1;
#pragma acc parallel num_gangs((end+127)/128) num_workers(4) vector_length(32)
{
#pragma acc loop gang worker vector reduction(+:d)
for (j = 0; j < end; j++) {
d = d + p[j]*q[j];
}
}
//---------------------------------------------------------------------
// Obtain alpha = rho / (p.q)
//---------------------------------------------------------------------
alpha = rho / d;
//---------------------------------------------------------------------
// Save a temporary of rho
//---------------------------------------------------------------------
rho0 = rho;
//---------------------------------------------------------------------
// Obtain z = z + alpha*p
// and r = r - alpha*q
//---------------------------------------------------------------------
rho = 0.0;
#pragma acc kernels loop gang((end+1023)/1024) vector(1024) independent
for (j = 0; j < end; j++) {
z[j] = z[j] + alpha*p[j];
r[j] = r[j] - alpha*q[j];
}
//---------------------------------------------------------------------
// rho = r.r
// Now, obtain the norm of r: First, sum squares of r elements locally...
//---------------------------------------------------------------------
#pragma acc parallel num_gangs((end+127)/128) num_workers(4) vector_length(32)
{
#pragma acc loop gang worker vector reduction(+:rho)
for (j = 0; j < end; j++)
{
rho = rho + r[j]*r[j];
}
}
//---------------------------------------------------------------------
// Obtain beta:
//---------------------------------------------------------------------
beta = rho / rho0;
//---------------------------------------------------------------------
// p = r + beta*p
//---------------------------------------------------------------------
#pragma acc kernels loop gang((end+127)/128) vector(128) independent
for (j = 0; j < end; j++) {
p[j] = r[j] + beta*p[j];
}
} // end of do cgit=1,cgitmax
//---------------------------------------------------------------------
// Compute residual norm explicitly: ||r|| = ||x - A.z||
// First, form A.z
// The partition submatrix-vector multiply
//---------------------------------------------------------------------
end = lastrow - firstrow + 1;
//num_gangs = end/128;
#pragma acc parallel loop gang num_gangs(end) \
num_workers(4) vector_length(32)
for (j = 0; j < end; j++) {
tmp1=rowstr[j];
tmp2=rowstr[j+1];
d = 0.0;
#pragma acc loop worker vector reduction(+:d)
for (k = tmp1; k < tmp2; k++) {
tmp3=colidx[k];
d = d + a[k]*z[tmp3];
}
r[j] = d;
}
//---------------------------------------------------------------------
// At this point, r contains A.z
//---------------------------------------------------------------------
sum = 0.0;
//num_gangs = (lastcol-firstcol+1)/128;
#pragma acc parallel loop gang worker vector \
num_gangs((lastcol-firstcol+1+127)/128) \
num_workers(4) vector_length(32) \
reduction(+:sum)
for (j = 0; j < lastcol-firstcol+1; j++) {
d = x[j] - r[j];
sum = sum + d*d;
}
}/*end acc data*/
*rnorm = sqrt(sum);
}
//---------------------------------------------------------------------
// generate the test problem for benchmark 6
// makea generates a sparse matrix with a
// prescribed sparsity distribution
//
// parameter type usage
//
// input
//
// n i number of cols/rows of matrix
// nz i nonzeros as declared array size
// rcond r*8 condition number
// shift r*8 main diagonal shift
//
// output
//
// a r*8 array for nonzeros
// colidx i col indices
// rowstr i row pointers
//
// workspace
//
// iv, arow, acol i
// aelt r*8
//---------------------------------------------------------------------
static void makea(int n,
int nz,
double a[],
int colidx[],
int rowstr[],
int firstrow,
int lastrow,
int firstcol,
int lastcol,
int arow[],
int acol[][NONZER+1],
double aelt[][NONZER+1],
int iv[])
{
int iouter, ivelt, nzv, nn1;
int ivc[NONZER+1];
double vc[NONZER+1];
//---------------------------------------------------------------------
// nonzer is approximately (int(sqrt(nnza /n)));
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// nn1 is the smallest power of two not less than n
//---------------------------------------------------------------------
nn1 = 1;
do {
nn1 = 2 * nn1;
} while (nn1 < n);
//---------------------------------------------------------------------
// Generate nonzero positions and save for the use in sparse.
//---------------------------------------------------------------------
for (iouter = 0; iouter < n; iouter++) {
nzv = NONZER;
sprnvc(n, nzv, nn1, vc, ivc);
vecset(n, vc, ivc, &nzv, iouter+1, 0.5);
arow[iouter] = nzv;
for (ivelt = 0; ivelt < nzv; ivelt++) {
acol[iouter][ivelt] = ivc[ivelt] - 1;
aelt[iouter][ivelt] = vc[ivelt];
}
}
//---------------------------------------------------------------------
// ... make the sparse matrix from list of elements with duplicates
// (iv is used as workspace)
//---------------------------------------------------------------------
sparse(a, colidx, rowstr, n, nz, NONZER, arow, acol,
aelt, firstrow, lastrow,
iv, RCOND, SHIFT);
}
//---------------------------------------------------------------------
// rows range from firstrow to lastrow
// the rowstr pointers are defined for nrows = lastrow-firstrow+1 values
//---------------------------------------------------------------------
static void sparse(double a[],
int colidx[],
int rowstr[],
int n,
int nz,
int nozer,
int arow[],
int acol[][NONZER+1],
double aelt[][NONZER+1],
int firstrow,
int lastrow,
int nzloc[],
double rcond,
double shift)
{
int nrows;
//---------------------------------------------------
// generate a sparse matrix from a list of
// [col, row, element] tri
//---------------------------------------------------
int i, j, j1, j2, nza, k, kk, nzrow, jcol;
double size, scale, ratio, va;
logical cont40;
//---------------------------------------------------------------------
// how many rows of result
//---------------------------------------------------------------------
nrows = lastrow - firstrow + 1;
//---------------------------------------------------------------------
// ...count the number of triples in each row
//---------------------------------------------------------------------
for (j = 0; j < nrows+1; j++) {
rowstr[j] = 0;
}
for (i = 0; i < n; i++) {
for (nza = 0; nza < arow[i]; nza++) {
j = acol[i][nza] + 1;
rowstr[j] = rowstr[j] + arow[i];
}
}
rowstr[0] = 0;
for (j = 1; j < nrows+1; j++) {
rowstr[j] = rowstr[j] + rowstr[j-1];
}
nza = rowstr[nrows] - 1;
//---------------------------------------------------------------------
// ... rowstr(j) now is the location of the first nonzero
// of row j of a
//---------------------------------------------------------------------
if (nza > nz) {
printf("Space for matrix elements exceeded in sparse\n");
printf("nza, nzmax = %d, %d\n", nza, nz);
exit(EXIT_FAILURE);
}
//---------------------------------------------------------------------
// ... preload data pages
//---------------------------------------------------------------------
for (j = 0; j < nrows; j++) {
for (k = rowstr[j]; k < rowstr[j+1]; k++) {
a[k] = 0.0;
colidx[k] = -1;
}
nzloc[j] = 0;
}
//---------------------------------------------------------------------
// ... generate actual values by summing duplicates
//---------------------------------------------------------------------
size = 1.0;
ratio = pow(rcond, (1.0 / (double)(n)));
for (i = 0; i < n; i++) {
for (nza = 0; nza < arow[i]; nza++) {
j = acol[i][nza];
scale = size * aelt[i][nza];
for (nzrow = 0; nzrow < arow[i]; nzrow++) {
jcol = acol[i][nzrow];
va = aelt[i][nzrow] * scale;
//--------------------------------------------------------------------
// ... add the identity * rcond to the generated matrix to bound
// the smallest eigenvalue from below by rcond
//--------------------------------------------------------------------
if (jcol == j && j == i) {
va = va + rcond - shift;
}
cont40 = false;
for (k = rowstr[j]; k < rowstr[j+1]; k++) {
if (colidx[k] > jcol) {
//----------------------------------------------------------------
// ... insert colidx here orderly
//----------------------------------------------------------------
for (kk = rowstr[j+1]-2; kk >= k; kk--) {
if (colidx[kk] > -1) {
a[kk+1] = a[kk];
colidx[kk+1] = colidx[kk];
}
}
colidx[k] = jcol;
a[k] = 0.0;
cont40 = true;
break;
} else if (colidx[k] == -1) {
colidx[k] = jcol;
cont40 = true;
break;
} else if (colidx[k] == jcol) {
//--------------------------------------------------------------
// ... mark the duplicated entry
//--------------------------------------------------------------
nzloc[j] = nzloc[j] + 1;
cont40 = true;
break;
}
}
if (cont40 == false) {
printf("internal error in sparse: i=%d\n", i);
exit(EXIT_FAILURE);
}
a[k] = a[k] + va;
}
}
size = size * ratio;
}
//---------------------------------------------------------------------
// ... remove empty entries and generate final results
//---------------------------------------------------------------------
for (j = 1; j < nrows; j++) {
nzloc[j] = nzloc[j] + nzloc[j-1];
}
for (j = 0; j < nrows; j++) {
if (j > 0) {
j1 = rowstr[j] - nzloc[j-1];
} else {
j1 = 0;
}
j2 = rowstr[j+1] - nzloc[j];
nza = rowstr[j];
for (k = j1; k < j2; k++) {
a[k] = a[nza];
colidx[k] = colidx[nza];
nza = nza + 1;
}
}
for (j = 1; j < nrows+1; j++) {
rowstr[j] = rowstr[j] - nzloc[j-1];
}
nza = rowstr[nrows] - 1;
}
//---------------------------------------------------------------------
// generate a sparse n-vector (v, iv)
// having nzv nonzeros
//
// mark(i) is set to 1 if position i is nonzero.
// mark is all zero on entry and is reset to all zero before exit
// this corrects a performance bug found by John G. Lewis, caused by
// reinitialization of mark on every one of the n calls to sprnvc
//---------------------------------------------------------------------
static void sprnvc(int n, int nz, int nn1, double v[], int iv[])
{
int nzv, ii, i;
double vecelt, vecloc;
nzv = 0;
while (nzv < nz) {
vecelt = randlc(&tran, amult);
//---------------------------------------------------------------------
// generate an integer between 1 and n in a portable manner
//---------------------------------------------------------------------
vecloc = randlc(&tran, amult);
i = icnvrt(vecloc, nn1) + 1;
if (i > n) continue;
//---------------------------------------------------------------------
// was this integer generated already?
//---------------------------------------------------------------------
logical was_gen = false;
for (ii = 0; ii < nzv; ii++) {
if (iv[ii] == i) {
was_gen = true;
break;
}
}
if (was_gen) continue;
v[nzv] = vecelt;
iv[nzv] = i;
nzv = nzv + 1;
}
}
//---------------------------------------------------------------------
// scale a double precision number x in (0,1) by a power of 2 and chop it
//---------------------------------------------------------------------
static int icnvrt(double x, int ipwr2)
{
return (int)(ipwr2 * x);
}
//---------------------------------------------------------------------
// set ith element of sparse vector (v, iv) with
// nzv nonzeros to val
//---------------------------------------------------------------------
static void vecset(int n, double v[], int iv[], int *nzv, int i, double val)
{
int k;
logical set;
set = false;
for (k = 0; k < *nzv; k++) {
if (iv[k] == i) {
v[k] = val;
set = true;
}
}
if (set == false) {
v[*nzv] = val;
iv[*nzv] = i;
*nzv = *nzv + 1;
}
}
|
./openacc-vv/wait_if.cpp | #include "acc_testsuite.h"
#ifndef T1
//T1:parallel,wait,async,if,V:2.7-3.3
int test1(){
int err = 0;
srand(SEED);
real_t *a = new real_t[n];
real_t *b = new real_t[n];
real_t *c = new real_t[n];
real_t *d = new real_t[n];
real_t *e = new real_t[n];
real_t *f = new real_t[n];
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
b[x] = rand() / (real_t)(RAND_MAX / 10);
c[x] = 0.0;
d[x] = rand() / (real_t)(RAND_MAX / 10);
e[x] = rand() / (real_t)(RAND_MAX / 10);
f[x] = 0.0;
}
#pragma acc data copyin(a[0:n], b[0:n], d[0:n], e[0:n]) create(c[0:n], f[0:n])
{
#pragma acc parallel async(1)
{
#pragma acc loop
for (int x = 0; x < n; ++x){
c[x] = a[x] + b[x];
}
}
#pragma acc parallel async(2)
{
#pragma acc loop
for (int x = 0; x < n; ++x){
f[x] = d[x] + e[x];
}
}
#pragma acc update host(c[0:n], f[0:n]) wait(1, 2) if(true)
}
for (int x = 0; x < n; ++x){
if (abs(c[x] - (a[x] + b[x])) > PRECISION){
err++;
}
if (abs(f[x] - (d[x] + e[x])) > PRECISION){
err++;
}
}
return err;
}
#endif
#ifndef T2
//T2:parallel,wait,async,if,V:2.7-3.3
int test2(){
int err = 0;
srand(SEED);
real_t *a = new real_t[n];
real_t *b = new real_t[n];
real_t *c = new real_t[n];
real_t *d = new real_t[n];
real_t *e = new real_t[n];
real_t *f = new real_t[n];
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
b[x] = rand() / (real_t)(RAND_MAX / 10);
c[x] = 0.0;
d[x] = rand() / (real_t)(RAND_MAX / 10);
e[x] = rand() / (real_t)(RAND_MAX / 10);
f[x] = 0.0;
}
#pragma acc data copyin(a[0:n], b[0:n], d[0:n], e[0:n]) create(c[0:n], f[0:n])
{
#pragma acc parallel async(1)
{
#pragma acc loop
for (int x = 0; x < n; ++x){
c[x] = a[x] + b[x];
}
}
#pragma acc parallel async(2)
{
#pragma acc loop
for (int x = 0; x < n; ++x){
f[x] = d[x] + e[x];
}
}
#pragma acc update host(c[0:n], f[0:n]) wait(1) if(true)
#pragma acc update host(c[0:n], f[0:n]) wait(2) if(true)
}
for (int x = 0; x < n; ++x){
if (abs(c[x] - (a[x] + b[x])) > PRECISION){
err++;
}
if (abs(f[x] - (d[x] + e[x])) > PRECISION){
err++;
}
}
return err;
}
#endif
#ifndef T3
//T3:parallel,wait,async,if,V:2.7-3.3
int test3(){
int err = 0;
srand(time(NULL));
real_t *a = new real_t[n];
real_t *b = new real_t[n];
real_t *c = new real_t[n];
real_t *d = new real_t[n];
real_t *e = new real_t[n];
real_t *f = new real_t[n];
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
b[x] = rand() / (real_t)(RAND_MAX / 10);
c[x] = 0.0;
d[x] = rand() / (real_t)(RAND_MAX / 10);
e[x] = rand() / (real_t)(RAND_MAX / 10);
f[x] = 0.0;
}
#pragma acc data copyin(a[0:n], b[0:n], d[0:n], e[0:n]) create(c[0:n], f[0:n])
{
#pragma acc parallel async(1)
{
#pragma acc loop
for (int x = 0; x < n; ++x){
c[x] = a[x] + b[x];
}
}
#pragma acc parallel async(2)
{
#pragma acc loop
for (int x = 0; x < n; ++x){
f[x] = d[x] + e[x];
}
}
#pragma acc update host(c[0:n], f[0:n]) wait(1, 2) if(false)
}
for (int x = 0; x < n; ++x){
if (c[x] > PRECISION){
err++;
}
if (f[x] > PRECISION){
err++;
}
}
return err;
}
#endif
#ifndef T4
//T4:parallel,wait,async,if,V:2.7-3.3
int test4(){
int err = 0;
srand(time(NULL));
real_t *a = new real_t[n];
real_t *b = new real_t[n];
real_t *c = new real_t[n];
real_t *d = new real_t[n];
real_t *e = new real_t[n];
real_t *f = new real_t[n];
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
b[x] = rand() / (real_t)(RAND_MAX / 10);
c[x] = 0.0;
d[x] = rand() / (real_t)(RAND_MAX / 10);
e[x] = rand() / (real_t)(RAND_MAX / 10);
f[x] = 0.0;
}
#pragma acc data copyin(a[0:n], b[0:n], d[0:n], e[0:n]) create(c[0:n], f[0:n])
{
#pragma acc parallel async(1)
{
#pragma acc loop
for (int x = 0; x < n; ++x){
c[x] = a[x] + b[x];
}
}
#pragma acc parallel async(2)
{
#pragma acc loop
for (int x = 0; x < n; ++x){
f[x] = d[x] + e[x];
}
}
#pragma acc update host(c[0:n], f[0:n]) wait(1) if(false)
#pragma acc update host(c[0:n], f[0:n]) wait(2) if(false)
}
for (int x = 0; x < n; ++x){
if (c[x] > PRECISION){
err++;
}
if (f[x] > PRECISION){
err++;
}
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed += test1();
}
if (failed){
failcode += (1 << 0);
}
#endif
#ifndef T2
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed += test2();
}
if (failed){
failcode += (1 << 1);
}
#endif
#ifndef T3
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed += test3();
}
if (failed){
failcode += (1 << 2);
}
#endif
#ifndef T4
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed += test4();
}
if (failed){
failcode += (1 << 3);
}
#endif
return failcode;
}
|
./openacc-vv/atomic_expr_minus_x.cpp | #include "acc_testsuite.h"
bool possible_result(real_t * remaining_combinations, int length, real_t current_value, real_t test_value){
if (length == 0){
if (fabs(current_value - test_value) > PRECISION){
return true;
}
else {
return false;
}
}
real_t * passed = new real_t[(length - 1)];
for (int x = 0; x < length; ++x){
for (int y = 0; y < x; ++y){
passed[y] = remaining_combinations[y];
}
for (int y = x + 1; y < length; ++y){
passed[y - 1] = remaining_combinations[y];
}
if (possible_result(passed, length - 1, remaining_combinations[x] - current_value, test_value)){
delete[] passed;
return true;
}
}
delete[] passed;
return false;
}
#ifndef T1
//T1:atomic,construct-independent,V:2.0-2.7
int test1(){
int err = 0;
srand(SEED);
real_t *a = new real_t[n];
real_t *totals = new real_t[((n/10) + 1)];
int indexer = 0;
real_t * passed = new real_t[10];
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
}
for (int x = 0; x < (n/10) + 1; ++x){
totals[x] = 0;
}
#pragma acc data copyin(a[0:n]) copy(totals[0:(n/10) + 1])
{
#pragma acc parallel
{
#pragma acc loop
for (int x = 0; x < n; ++x){
#pragma acc atomic
totals[x%((int) (n/10) + 1)] = a[x] - totals[x%((int) (n/10) + 1)];
}
}
}
for (int x = 0; x < (n/10) + 1; ++x){
indexer = x;
while (indexer < n){
passed[indexer/((int) (n/10) + 1)] = a[indexer];
indexer += (n/10) + 1;
}
if (!(possible_result(passed, 10, 0, totals[x]))){
err += 1;
}
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test1();
}
if (failed != 0){
failcode = failcode + (1 << 0);
}
#endif
return failcode;
}
|
./openacc-vv/parallel_reduction.F90 | #ifndef T1
!T1:parallel,reduction,V:1.0-2.7
LOGICAL FUNCTION test1()
IMPLICIT NONE
INCLUDE "acc_testsuite.Fh"
INTEGER :: x !Iterators
REAL(8),DIMENSION(LOOPCOUNT):: a !Data
REAL(8) :: results = 0
INTEGER :: errors = 0
!Initilization
SEEDDIM(1) = 1
# ifdef SEED
SEEDDIM(1) = SEED
# endif
CALL RANDOM_SEED(PUT=SEEDDIM)
CALL RANDOM_NUMBER(a)
!$acc data copyin(a(1:LOOPCOUNT))
!$acc parallel reduction(+:results)
!$acc loop
DO x = 1, LOOPCOUNT
results = results + a(x)
END DO
!$acc end parallel
!$acc end data
DO x = 1, LOOPCOUNT
results = results - a(x)
END DO
IF (abs(results) .gt. PRECISION) THEN
errors = errors + 1
END IF
IF (errors .eq. 0) THEN
test1 = .FALSE.
ELSE
test1 = .TRUE.
END IF
END
#endif
PROGRAM main
IMPLICIT NONE
INTEGER :: failcode, testrun
LOGICAL :: failed
INCLUDE "acc_testsuite.Fh"
#ifndef T1
LOGICAL :: test1
#endif
failed = .FALSE.
failcode = 0
#ifndef T1
DO testrun = 1, NUM_TEST_CALLS
failed = failed .or. test1()
END DO
IF (failed) THEN
failcode = failcode + 2 ** 0
failed = .FALSE.
END IF
#endif
CALL EXIT (failcode)
END PROGRAM
|
./openacc-vv/atomic_plus_equals.c | #include "acc_testsuite.h"
#ifndef T1
//T1:atomic,construct-independent,V:2.0-2.7
int test1(){
int err = 0;
srand(SEED);
real_t *a = (real_t *)malloc(n * sizeof(real_t));
real_t *b = (real_t *)malloc(n * sizeof(real_t));
real_t *totals = (real_t *)malloc((n/10 + 1) * sizeof(real_t));
real_t *totals_comparison = (real_t *)malloc((n/10 + 1) * sizeof(real_t));
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
b[x] = rand() / (real_t)(RAND_MAX / 10);
}
for (int x = 0; x < n/10 + 1; ++x){
totals[x] = 0;
totals_comparison[x] = 0;
}
#pragma acc data copyin(a[0:n], b[0:n]) copy(totals[0:n/10 + 1])
{
#pragma acc parallel
{
#pragma acc loop
for (int x = 0; x < n; ++x){
#pragma acc atomic
totals[x%(n/10 + 1)] += a[x] * b[x];
}
}
}
for (int x = 0; x < n; ++x){
totals_comparison[x%(n/10 + 1)] += a[x] * b[x];
}
for (int x = 0; x < n/10 + 1; ++x){
if (fabs(totals_comparison[x] - totals[x]) > (n/10 + 1) * PRECISION){
err += 1;
break;
}
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test1();
}
if (failed != 0){
failcode = failcode + (1 << 0);
}
#endif
return failcode;
}
|
./openacc-vv/atomic_update_min_expr_list_x_end.F90 | #ifndef T1
!T1:construct-independent,atomic,V:2.0-2.7
LOGICAL FUNCTION test1()
IMPLICIT NONE
INCLUDE "acc_testsuite.Fh"
INTEGER :: x, y !Iterators
REAL(8),DIMENSION(LOOPCOUNT):: a, b !Data
REAL(8),DIMENSION(LOOPCOUNT/10 + 1):: totals, totals_comparison
INTEGER :: errors = 0
!Initilization
SEEDDIM(1) = 1
# ifdef SEED
SEEDDIM(1) = SEED
# endif
CALL RANDOM_SEED(PUT=SEEDDIM)
CALL RANDOM_NUMBER(a)
CALL RANDOM_NUMBER(b)
totals = 1
totals_comparison = 1
!$acc data copyin(a(1:LOOPCOUNT), b(1:LOOPCOUNT)) copy(totals(1:(LOOPCOUNT/10 + 1)))
!$acc parallel
!$acc loop
DO x = 1, LOOPCOUNT
!$acc atomic update
totals(MOD(x, LOOPCOUNT/10 + 1) + 1) = min(a(x), b(x), totals(MOD(x, LOOPCOUNT/10 + 1) + 1))
!$acc end atomic
END DO
!$acc end parallel
!$acc end data
DO x = 1, LOOPCOUNT
totals_comparison(MOD(x, LOOPCOUNT/10 + 1) + 1) = min(totals_comparison(MOD(x, LOOPCOUNT/10 + 1) + 1), a(x), b(x))
END DO
DO x = 1, LOOPCOUNT/10 + 1
IF (totals_comparison(x) .NE. totals(x)) THEN
errors = errors + 1
WRITE(*, *) totals_comparison(x)
END IF
END DO
IF (errors .eq. 0) THEN
test1 = .FALSE.
ELSE
test1 = .TRUE.
END IF
END
#endif
PROGRAM main
IMPLICIT NONE
INTEGER :: failcode, testrun
LOGICAL :: failed
INCLUDE "acc_testsuite.Fh"
#ifndef T1
LOGICAL :: test1
#endif
failed = .FALSE.
failcode = 0
#ifndef T1
DO testrun = 1, NUM_TEST_CALLS
failed = failed .or. test1()
END DO
IF (failed) THEN
failcode = failcode + 2 ** 0
failed = .FALSE.
END IF
#endif
CALL EXIT (failcode)
END PROGRAM
|
./openacc-vv/exit_data_copyout_reference_counts.F90 | #ifndef T1
!T1:data,executable-data,devonly,construct-independent,V:2.0-2.7
LOGICAL FUNCTION test1()
IMPLICIT NONE
INCLUDE "acc_testsuite.Fh"
INTEGER :: x !Iterators
REAL(8),DIMENSION(LOOPCOUNT):: a, b, c !Data
INTEGER :: errors = 0
INTEGER,DIMENSION(1):: devtest
devtest(1) = 1
!$acc enter data copyin(devtest(1:1))
!$acc parallel present(devtest(1:1))
devtest(1) = 0
!$acc end parallel
!Initilization
SEEDDIM(1) = 1
# ifdef SEED
SEEDDIM(1) = SEED
# endif
CALL RANDOM_SEED(PUT=SEEDDIM)
CALL RANDOM_NUMBER(a)
CALL RANDOM_NUMBER(b)
c = 0
IF (devtest(1) .eq. 1) THEN
!$acc enter data copyin(a(1:LOOPCOUNT), b(1:LOOPCOUNT), c(1:LOOPCOUNT))
!$acc data copyin(c(1:LOOPCOUNT))
!$acc parallel
!$acc loop
DO x = 1, LOOPCOUNT
c(x) = c(x) + a(x) + b(x)
END DO
!$acc end parallel
!$acc exit data delete(a(1:LOOPCOUNT), b(1:LOOPCOUNT)) copyout(c(1:LOOPCOUNT))
!$acc end data
DO x = 1, LOOPCOUNT
IF (abs(c(x)) .gt. PRECISION) THEN
errors = errors + 1
EXIT
END IF
END DO
END IF
IF (errors .eq. 0) THEN
test1 = .FALSE.
ELSE
test1 = .TRUE.
END IF
END
#endif
#ifndef T2
!T2:data,executable-data,devonly,construct-independent,V:2.0-2.7
LOGICAL FUNCTION test2()
IMPLICIT NONE
INCLUDE "acc_testsuite.Fh"
INTEGER :: x !Iterators
REAL(8),DIMENSION(LOOPCOUNT):: a, b, c !Data
INTEGER :: errors = 0
INTEGER,DIMENSION(1):: devtest
devtest(1) = 1
!$acc enter data copyin(devtest(1:1))
!$acc parallel present(devtest(1:1))
devtest(1) = 0
!$acc end parallel
!Initilization
SEEDDIM(1) = 1
# ifdef SEED
SEEDDIM(1) = SEED
# endif
CALL RANDOM_SEED(PUT=SEEDDIM)
CALL RANDOM_NUMBER(a)
CALL RANDOM_NUMBER(b)
c = 0
!$acc enter data copyin(a(1:LOOPCOUNT), b(1:LOOPCOUNT), c(1:LOOPCOUNT))
!$acc data copyin(c(1:LOOPCOUNT))
!$acc parallel
!$acc loop
DO x = 1, LOOPCOUNT
c(x) = c(x) + a(x) + b(x)
END DO
!$acc end parallel
!$acc end data
!$acc exit data copyout(c(1:LOOPCOUNT)) delete(a(1:LOOPCOUNT), b(1:LOOPCOUNT))
DO x = 1, LOOPCOUNT
IF (abs(c(x) - (a(x) + b(x))) .gt. PRECISION) THEN
errors = errors + 2
EXIT
END IF
END DO
IF (errors .eq. 0) THEN
test2 = .FALSE.
ELSE
test2 = .TRUE.
END IF
END
#endif
#ifndef T3
!T3:data,executable-data,devonly,construct-independent,V:2.0-2.7
LOGICAL FUNCTION test3()
IMPLICIT NONE
INCLUDE "acc_testsuite.Fh"
INTEGER :: x !Iterators
REAL(8),DIMENSION(LOOPCOUNT):: a, b, c !Data
INTEGER :: errors = 0
INTEGER,DIMENSION(1):: devtest
devtest(1) = 1
!$acc enter data copyin(devtest(1:1))
!$acc parallel present(devtest(1:1))
devtest(1) = 0
!$acc end parallel
!Initilization
SEEDDIM(1) = 1
# ifdef SEED
SEEDDIM(1) = SEED
# endif
CALL RANDOM_SEED(PUT=SEEDDIM)
CALL RANDOM_NUMBER(a)
CALL RANDOM_NUMBER(b)
c = 0
!$acc enter data copyin(a(1:LOOPCOUNT), b(1:LOOPCOUNT), c(1:LOOPCOUNT))
!$acc enter data copyin(c(1:LOOPCOUNT))
!$acc parallel
!$acc loop
DO x = 1, LOOPCOUNT
c(x) = c(x) + a(x) + b(x)
END DO
!$acc end parallel
!$acc exit data delete(c(1:LOOPCOUNT))
!$acc exit data delete(a(1:LOOPCOUNT), b(1:LOOPCOUNT)) copyout(c(1:LOOPCOUNT))
DO x = 1, LOOPCOUNT
IF (abs(c(x) - (a(x) + b(x))) .gt. PRECISION) THEN
errors = errors + 4
EXIT
END IF
END DO
IF (errors .eq. 0) THEN
test3 = .FALSE.
ELSE
test3 = .TRUE.
END IF
END
#endif
PROGRAM main
IMPLICIT NONE
INTEGER :: failcode, testrun
LOGICAL :: failed
INCLUDE "acc_testsuite.Fh"
#ifndef T1
LOGICAL :: test1
#endif
#ifndef T2
LOGICAL :: test2
#endif
#ifndef T3
LOGICAL :: test3
#endif
failed = .FALSE.
failcode = 0
#ifndef T1
DO testrun = 1, NUM_TEST_CALLS
failed = failed .or. test1()
END DO
IF (failed) THEN
failcode = failcode + 2 ** 0
failed = .FALSE.
END IF
#endif
#ifndef T2
DO testrun = 1, NUM_TEST_CALLS
failed = failed .or. test2()
END DO
IF (failed) THEN
failcode = failcode + 2 ** 1
failed = .FALSE.
END IF
#endif
#ifndef T3
DO testrun = 1, NUM_TEST_CALLS
failed = failed .or. test3()
END DO
IF (failed) THEN
failcode = failcode + 2 ** 2
failed = .FALSE.
END IF
#endif
CALL EXIT (failcode)
END PROGRAM
|
./openacc-vv/atomic_update_preincrement.c | #include "acc_testsuite.h"
#ifndef T1
//T1:atomic,construct-independent,V:2.0-2.7
int test1(){
int err = 0;
srand(SEED);
real_t *a = (real_t *)malloc(n * sizeof(real_t));
real_t *b = (real_t *)malloc(n * sizeof(real_t));
int *distribution = (int *)malloc(10 * sizeof(int));
int *distribution_comparison = (int *)malloc(10 * sizeof(int));
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
b[x] = rand() / (real_t)(RAND_MAX / 10);
}
for (int x = 0; x < 10; ++x){
distribution[x] = 0;
distribution_comparison[x] = 0;
}
#pragma acc data copyin(a[0:n], b[0:n]) copy(distribution[0:10])
{
#pragma acc parallel
{
#pragma acc loop
for (int x = 0; x < n; ++x){
#pragma acc loop
for (int y = 0; y < n; ++y){
#pragma acc atomic update
++distribution[(int) (a[x]*b[y]/10)];
}
}
}
}
for (int x = 0; x < n; ++x){
for (int y = 0; y < n; ++y){
distribution_comparison[(int) (a[x]*b[y]/10)]++;
}
}
for (int x = 0; x < 10; ++x){
if (distribution_comparison[x] != distribution[x]){
err += 1;
break;
}
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test1();
}
if (failed != 0){
failcode = failcode + (1 << 0);
}
#endif
return failcode;
}
|
./SPECaccel/benchspec/ACCEL/557.pcsp/src/error.c | //-------------------------------------------------------------------------//
// //
// This benchmark is a serial C version of the NPB SP code. This C //
// version is developed by the Center for Manycore Programming at Seoul //
// National University and derived from the serial Fortran versions in //
// "NPB3.3-SER" developed by NAS. //
// //
// Permission to use, copy, distribute and modify this software for any //
// purpose with or without fee is hereby granted. This software is //
// provided "as is" without express or implied warranty. //
// //
// Information on NPB 3.3, including the technical report, the original //
// specifications, source code, results and information on how to submit //
// new results, is available at: //
// //
// http://www.nas.nasa.gov/Software/NPB/ //
// //
// Send comments or suggestions for this C version to cmp@aces.snu.ac.kr //
// //
// Center for Manycore Programming //
// School of Computer Science and Engineering //
// Seoul National University //
// Seoul 151-744, Korea //
// //
// E-mail: cmp@aces.snu.ac.kr //
// //
//-------------------------------------------------------------------------//
//-------------------------------------------------------------------------//
// Authors: Sangmin Seo, Jungwon Kim, Jun Lee, Jeongho Nah, Gangwon Jo, //
// and Jaejin Lee //
//-------------------------------------------------------------------------//
#include "header.h"
#include <math.h>
//---------------------------------------------------------------------
// this function computes the norm of the difference between the
// computed solution and the exact solution
//---------------------------------------------------------------------
void error_norm(double rms[5])
{
int i, j, k, m, d;
double xi, eta, zeta, u_exact[5], add;
for (m = 0; m < 5; m++) {
rms[m] = 0.0;
}
for (k = 0; k <= grid_points[2]-1; k++) {
zeta = (double)k * dnzm1;
for (j = 0; j <= grid_points[1]-1; j++) {
eta = (double)j * dnym1;
for (i = 0; i <= grid_points[0]-1; i++) {
xi = (double)i * dnxm1;
exact_solution(xi, eta, zeta, u_exact);
for (m = 0; m < 5; m++) {
add = u[m][k][j][i]-u_exact[m];
rms[m] = rms[m] + add*add;
}
}
}
}
for (m = 0; m < 5; m++) {
for (d = 0; d < 3; d++) {
rms[m] = rms[m] / (double)(grid_points[d]-2);
}
rms[m] = sqrt(rms[m]);
}
}
void rhs_norm(double rms[5])
{
int i, j, k, d, m;
double add;
double rms0, rms1,rms2,rms3,rms4;
rms0=0.0;
rms1=0.0;
rms2=0.0;
rms3=0.0;
rms4=0.0;
#pragma omp target map(tofrom: rms0,rms1,rms2,rms3,rms4) //present(rhs)
#ifdef SPEC_USE_INNER_SIMD
#pragma omp teams distribute parallel for collapse(2) private(i) reduction(+:rms0,rms1,rms2,rms3,rms4)
#else
#pragma omp teams distribute parallel for simd collapse(3) reduction(+:rms0,rms1,rms2,rms3,rms4) private(add)
#endif
for (k = 1; k <= nz2; k++) {
for (j = 1; j <= ny2; j++) {
#ifdef SPEC_USE_INNER_SIMD
#pragma omp simd reduction(+:rms0,rms1,rms2,rms3,rms4) private(add)
#endif
for (i = 1; i <= nx2; i++) {
add = rhs[0][k][j][i];
rms0 = rms0 + add*add;
add = rhs[1][k][j][i];
rms1 = rms1 + add*add;
add = rhs[2][k][j][i];
rms2 = rms2 + add*add;
add = rhs[3][k][j][i];
rms3 = rms3 + add*add;
add = rhs[4][k][j][i];
rms4 = rms4 + add*add;
}
}
}
rms[0]=rms0;
rms[1]=rms1;
rms[2]=rms2;
rms[3]=rms3;
rms[4]=rms4;
for (m = 0; m < 5; m++) {
for (d = 0; d < 3; d++) {
rms[m] = rms[m] / (double)(grid_points[d]-2);
}
rms[m] = sqrt(rms[m]);
}
}
|
./openacc-vv/serial_loop_reduction_bitxor_loop.c | #include "acc_testsuite.h"
#ifndef T1
//T1:serial,loop,reduction,combined-constructs,V:2.6-3.2
int test1(){
int err = 0;
srand(SEED);
unsigned int * a = (unsigned int *)malloc(10 * n * sizeof(unsigned int));
unsigned int * b = (unsigned int *)malloc(10 * n * sizeof(unsigned int));
unsigned int * b_copy = (unsigned int *)malloc(10 * n * sizeof(unsigned int));
unsigned int * c = (unsigned int *)malloc(10 * sizeof(unsigned int));
unsigned int temp = 0;
for (int x = 0; x < 10*n; ++x){
b[x] = (unsigned int) rand() / (real_t)(RAND_MAX / 1000);
b_copy[x] = b[x];
a[x] = (unsigned int) rand() / (real_t)(RAND_MAX / 1000);
}
for (int x = 0; x < 10; ++x){
c[x] = 0;
}
#pragma acc data copyin(a[0:10*n]) copy(b[0:10*n], c[0:10])
{
#pragma acc serial loop private(temp)
for (int x = 0; x < 10; ++x){
temp = 0;
#pragma acc loop worker reduction(^:temp)
for (int y = 0; y < n; ++y){
temp = temp ^ a[x * n + y];
}
c[x] = temp;
#pragma acc loop worker
for (int y = 0; y < n; ++y){
b[x * n + y] = b[x * n + y] + c[x];
}
}
}
for (int x = 0; x < 10; ++x){
temp = 0;
for (int y = 0; y < n; ++y){
temp = temp ^ a[x * n + y];
}
if (temp != c[x]){
err += 1;
}
for (int y = 0; y < n; ++y){
if (b[x * n + y] != b_copy[x * n + y] + c[x]){
err += 1;
}
}
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test1();
}
if (failed != 0){
failcode = failcode + (1 << 0);
}
#endif
return failcode;
}
|
./openacc-vv/serial_loop_seq.c | #include "acc_testsuite.h"
#ifndef T1
//T1:serial,loop,combined-constructs,V:2.6-2.7
int test1(){
int err = 0;
srand(SEED);
real_t * a = (real_t *)malloc(n * sizeof(real_t));
real_t * b = (real_t *)malloc(n * sizeof(real_t));
real_t temp = 0.0;
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
b[x] = 0.0;
}
#pragma acc data copyin(a[0:n]) copy(b[0:n])
{
#pragma acc serial loop seq
for (int x = 1; x < n; ++x){
b[x] = b[x-1] + a[x];
}
}
for (int x = 1; x < n; ++x){
temp += a[x];
if (fabs(b[x] - temp) > PRECISION){
err = 1;
}
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test1();
}
if (failed != 0){
failcode = failcode + (1 << 0);
}
#endif
return failcode;
}
|
./openacc-vv/serial_loop_reduction_bitor_general.cpp | #include "acc_testsuite.h"
#ifndef T1
//T1:serial,loop,reduction,combined-constructs,V:2.6-2.7
int test1(){
int err = 0;
srand(SEED);
unsigned int * a = (unsigned int *)malloc(n * sizeof(unsigned int));
unsigned int b = 0;
unsigned int host_b;
real_t false_margin = pow(exp(1), log(.5)/n);
unsigned int temp = 1;
for (int x = 0; x < n; ++x){
for (int y = 0; y < 16; ++y){
if (rand() / (real_t) RAND_MAX > false_margin){
for (int z = 0; z < y; ++z){
temp *= 2;
}
a[x] += temp;
temp = 1;
}
}
}
#pragma acc data copyin(a[0:n])
{
#pragma acc serial loop reduction(|:b)
for (int x = 0; x < n; ++x){
b = b | a[x];
}
}
host_b = a[0];
for (int x = 1; x < n; ++x){
host_b = host_b | a[x];
}
if (b != host_b){
err = 1;
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test1();
}
if (failed != 0){
failcode = failcode + (1 << 0);
}
#endif
return failcode;
}
|
./PhysiCell_GPU/sample_projects/virus_macrophage/config/PhysiCell_settings.xml | <?xml version="1.0" encoding="UTF-8"?>
<!--
/*
###############################################################################
# If you use PhysiCell in your project, please cite PhysiCell and the version #
# number, such as below: #
# #
# We implemented and solved the model using PhysiCell (Version x.y.z) [1]. #
# #
# [1] A Ghaffarizadeh, R Heiland, SH Friedman, SM Mumenthaler, and P Macklin, #
# PhysiCell: an Open Source Physics-Based Cell Simulator for Multicellu- #
# lar Systems, PLoS Comput. Biol. 14(2): e1005991, 2018 #
# DOI: 10.1371/journal.pcbi.1005991 #
# #
# See VERSION.txt or call get_PhysiCell_version() to get the current version #
# x.y.z. Call display_citations() to get detailed information on all cite-#
# able software used in your PhysiCell application. #
# #
# Because PhysiCell extensively uses BioFVM, we suggest you also cite BioFVM #
# as below: #
# #
# We implemented and solved the model using PhysiCell (Version x.y.z) [1], #
# with BioFVM [2] to solve the transport equations. #
# #
# [1] A Ghaffarizadeh, R Heiland, SH Friedman, SM Mumenthaler, and P Macklin, #
# PhysiCell: an Open Source Physics-Based Cell Simulator for Multicellu- #
# lar Systems, PLoS Comput. Biol. 14(2): e1005991, 2018 #
# DOI: 10.1371/journal.pcbi.1005991 #
# #
# [2] A Ghaffarizadeh, SH Friedman, and P Macklin, BioFVM: an efficient para- #
# llelized diffusive transport solver for 3-D biological simulations, #
# Bioinformatics 32(8): 1256-8, 2016. DOI: 10.1093/bioinformatics/btv730 #
# #
###############################################################################
# #
# BSD 3-Clause License (see https://opensource.org/licenses/BSD-3-Clause) #
# #
# Copyright (c) 2015-2019, Paul Macklin and the PhysiCell Project #
# All rights reserved. #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions are met: #
# #
# 1. Redistributions of source code must retain the above copyright notice, #
# this list of conditions and the following disclaimer. #
# #
# 2. Redistributions in binary form must reproduce the above copyright #
# notice, this list of conditions and the following disclaimer in the #
# documentation and/or other materials provided with the distribution. #
# #
# 3. Neither the name of the copyright holder nor the names of its #
# contributors may be used to endorse or promote products derived from this #
# software without specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" #
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE #
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE #
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE #
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR #
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF #
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS #
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN #
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) #
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE #
# POSSIBILITY OF SUCH DAMAGE. #
# #
###############################################################################
*/
-->
<!--
<user_details />
-->
<PhysiCell_settings version="devel-version">
<domain>
<x_min>-500</x_min>
<x_max>500</x_max>
<y_min>-500</y_min>
<y_max>500</y_max>
<z_min>-10</z_min>
<z_max>10</z_max>
<dx>20</dx>
<dy>20</dy>
<dz>20</dz>
<use_2D>true</use_2D>
</domain>
<overall>
<max_time units="min">1440</max_time> <!-- 5 days * 24 h * 60 min -->
<time_units>min</time_units>
<space_units>micron</space_units>
</overall>
<parallel>
<omp_num_threads>4</omp_num_threads>
</parallel>
<save>
<folder>output</folder> <!-- use . for root -->
<full_data>
<interval units="min">60</interval>
<enable>true</enable>
</full_data>
<SVG>
<interval units="min">10</interval>
<enable>true</enable>
</SVG>
<legacy_data>
<enable>false</enable>
</legacy_data>
</save>
<microenvironment_setup>
<variable name="virus" units="particles/micron^3" ID="0">
<physical_parameter_set>
<diffusion_coefficient units="micron^2/min">1000</diffusion_coefficient>
<decay_rate units="1/min">0</decay_rate>
</physical_parameter_set>
<initial_condition units="particles/micron^3">0</initial_condition>
<Dirichlet_boundary_condition units="particles/micron^3" enabled="false">0</Dirichlet_boundary_condition>
</variable>
<options>
<calculate_gradients>true</calculate_gradients>
<track_internalized_substrates_in_each_agent>true</track_internalized_substrates_in_each_agent>
<!-- not yet supported -->
<initial_condition type="matlab" enabled="false">
<filename>./config/initial.mat</filename>
</initial_condition>
<!-- not yet supported -->
<dirichlet_nodes type="matlab" enabled="false">
<filename>./config/dirichlet.mat</filename>
</dirichlet_nodes>
</options>
</microenvironment_setup>
<user_parameters>
<random_seed type="int" units="dimensionless" hidden="true">0</random_seed>
<!-- example parameters from the template -->
<!-- virus properties -->
<viral_replication_rate type="double" units="viral particles/min" description="rate at which infected cells create new viral particles">0.4167</viral_replication_rate>
<min_virion_count type="double" units="none" description="minimum number of virions to start replication">1</min_virion_count>
<burst_virion_count type="double" units="none" description="max virion load, where infected cells lyse to release viral particles">100</burst_virion_count>
<viral_internalization_rate type="double" units="1/min" description="internalization rate for viral particles">10</viral_internalization_rate>
<viral_diffusion_coefficient type="double" units="micron^2/min" description="diffusion coefficient for viral particles">1e3</viral_diffusion_coefficient>
<number_of_infected_cells type="int" units="none" description="initial number of infected cells">1</number_of_infected_cells>
<!-- virus diffusion coefficient ~ 1e3 micron^2/min : https://bionumbers.hms.harvard.edu/bionumber.aspx?id=105894 -->
<!-- macrophage properties -->
<number_of_macrophages type="int" units="none" description="initial number of macrophages">50</number_of_macrophages>
<min_virion_detection_threshold type="double" units="none" description="minimal viral load for microphages to detect as infected">1</min_virion_detection_threshold>
<virus_digestion_rate type="double" units="1/min" description="rate that macrophages digest internalized viral particles">0.01</virus_digestion_rate>
<macrophage_persistence_time type="double" units="min">15</macrophage_persistence_time>
<macrophage_migration_speed type="double" units="micron/min">1</macrophage_migration_speed>
<macrophage_migration_bias type="double" units="dimensionless">0.1</macrophage_migration_bias>
<macrophage_relative_adhesion type="double" units="dimensionless">0.05</macrophage_relative_adhesion>
</user_parameters>
</PhysiCell_settings>
|
./SPECaccel/benchspec/ACCEL/551.ppalm/data/test/input/ENVPAR | &envpar run_identifier = 'acc_small', host = 'unknown',
write_binary = 'false', tasks_per_node = 1,
maximum_cpu_time_allowed = 999999.,
revision = 'Rev: ',
local_dvrserver_running = .FALSE. /
|
./openacc-vv/atomic_structured_divided_equals_assign.cpp | #include "acc_testsuite.h"
bool is_possible(real_t* a, real_t* b, real_t* c, int length, real_t prev){
if (length == 0){
return true;
}
real_t *passed_a = new real_t[(length - 1)];
real_t *passed_b = new real_t[(length - 1)];
real_t *passed_c = new real_t[(length - 1)];
for (int x = 0; x < length; ++x){
if (fabs(c[x] - (prev / (a[x] + b[x]))) < PRECISION){
for (int y = 0; y < x; ++y){
passed_a[y] = a[y];
passed_b[y] = b[y];
passed_c[y] = c[y];
}
for (int y = x + 1; y < length; ++y){
passed_a[y - 1] = a[y];
passed_b[y - 1] = b[y];
passed_c[y - 1] = c[y];
}
if (is_possible(passed_a, passed_b, passed_c, length - 1, c[x])){
delete[] passed_a;
delete[] passed_b;
delete[] passed_c;
return true;
}
}
}
delete[] passed_a;
delete[] passed_b;
delete[] passed_c;
return false;
}
#ifndef T1
//T1:atomic,construct-independent,V:2.0-2.7
int test1(){
int err = 0;
srand(SEED);
real_t *a = new real_t[n];
real_t *b = new real_t[n];
real_t *c = new real_t[n];
real_t *totals = new real_t[(n/10 + 1)];
real_t *totals_comparison = new real_t[(n/10 + 1)];
real_t *temp_a = new real_t[10];
real_t *temp_b = new real_t[10];
real_t *temp_c = new real_t[10];
int temp_iterator;
int ab_iterator;
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
b[x] = rand() / (real_t)(RAND_MAX / 10);
c[x] = 0;
}
for (int x = 0; x < n/10 + 1; ++x){
totals[x] = 1;
totals_comparison[x] = 1;
}
#pragma acc data copyin(a[0:n], b[0:n]) copy(totals[0:n/10 + 1]) copyout(c[0:n])
{
#pragma acc parallel
{
#pragma acc loop
for (int x = 0; x < n; ++x){
#pragma acc atomic capture
{
totals[x/10] /= (a[x] + b[x]);
c[x] = totals[x/10];
}
}
}
}
for (int x = 0; x < n; ++x){
totals_comparison[x/10] /= a[x] + b[x];
}
for (int x = 0; x < 10; ++x){
if (fabs(totals_comparison[x] - totals[x]) > PRECISION){
err += 1;
break;
}
}
for (int x = 0; x < n; x = x + 10){
temp_iterator = 0;
for (ab_iterator = x; ab_iterator < n && ab_iterator < x + 10; ab_iterator+= 1){
temp_a[temp_iterator] = a[ab_iterator];
temp_b[temp_iterator] = b[ab_iterator];
temp_c[temp_iterator] = c[ab_iterator];
temp_iterator++;
}
if (!(is_possible(temp_a, temp_b, temp_c, temp_iterator, 1))){
err++;
}
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test1();
}
if (failed != 0){
failcode = failcode + (1 << 0);
}
#endif
return failcode;
}
|
./openacc-vv/atomic_capture_rshift_equals.cpp | #include "acc_testsuite.h"
bool is_possible(unsigned int a, unsigned int* b, int length, unsigned int prev){
if (length == 0){
return true;
}
unsigned int passed_a = 0;
unsigned int *passed_b = (unsigned int *)malloc((length - 1) * sizeof(unsigned int));
for (int x = 0; x < length; ++x){
if ((b[x] == prev>>1 && ((a>>x)%2)==1) || ((a>>x)%2==0 && b[x] == prev)){
for (int y = 0; y < x; ++y){
if ((a>>y)%2 == 1){
passed_a += 1<<y;
}
passed_b[y] = b[y];
}
for (int y = x + 1; y < length; ++y){
if ((a>>y) % 2 == 1){
passed_a += 1<<(y - 1);
}
passed_b[y - 1] = b[y];
}
if (is_possible(passed_a, passed_b, length - 1, b[x])){
delete[] passed_b;
return true;
}
}
}
delete[] passed_b;
return false;
}
#ifndef T1
//T1:atomic,construct-independent,V:2.0-2.7
int test1(){
int err = 0;
srand(SEED);
unsigned int *a = (unsigned int *)malloc(n * sizeof(int));
unsigned int *b = (unsigned int *)malloc(n * sizeof(int));
unsigned int *c = (unsigned int *)malloc(7 * n * sizeof(int));
unsigned int passed = 1<<8;
for (int x = 0; x < n; ++x){
a[x] = 1<<8;
for (int y = 0; y < 7; ++y){
if ((rand()/(real_t) (RAND_MAX)) > .5){
b[x] += 1<<y;
}
}
}
#pragma acc data copyin(b[0:n]) copy(a[0:n]) copyout(c[0:7*n])
{
#pragma acc parallel
{
#pragma acc loop
for (int x = 0; x < n; ++x){
#pragma acc loop
for (int y = 0; y < 7; ++y){
c[x * 7 + y] = a[x];
if ((b[x]>>y)%2 == 1){
#pragma acc atomic capture
c[x * 7 + y] = a[x] >>= 1;
}
}
}
}
}
for (int x = 0; x < n; ++x){
for (int y = 0; y < 7; ++y){
if ((b[x]>>y)%2 == 1){
a[x] <<= 1;
}
}
if (a[x] != 1<<8){
err += 1;
}
}
for (int x = 0; x < n; ++x){
if (!is_possible(b[x], &(c[x * 7]), 7, passed)){
err++;
}
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test1();
}
if (failed != 0){
failcode = failcode + (1 << 0);
}
#endif
return failcode;
}
|
./PhysiCell_GPU/unit_tests/substrate_internalization/config/PhysiCell_settings.xml | <?xml version="1.0" encoding="UTF-8"?>
<!--
/*
###############################################################################
# If you use PhysiCell in your project, please cite PhysiCell and the version #
# number, such as below: #
# #
# We implemented and solved the model using PhysiCell (Version x.y.z) [1]. #
# #
# [1] A Ghaffarizadeh, R Heiland, SH Friedman, SM Mumenthaler, and P Macklin, #
# PhysiCell: an Open Source Physics-Based Cell Simulator for Multicellu- #
# lar Systems, PLoS Comput. Biol. 14(2): e1005991, 2018 #
# DOI: 10.1371/journal.pcbi.1005991 #
# #
# See VERSION.txt or call get_PhysiCell_version() to get the current version #
# x.y.z. Call display_citations() to get detailed information on all cite-#
# able software used in your PhysiCell application. #
# #
# Because PhysiCell extensively uses BioFVM, we suggest you also cite BioFVM #
# as below: #
# #
# We implemented and solved the model using PhysiCell (Version x.y.z) [1], #
# with BioFVM [2] to solve the transport equations. #
# #
# [1] A Ghaffarizadeh, R Heiland, SH Friedman, SM Mumenthaler, and P Macklin, #
# PhysiCell: an Open Source Physics-Based Cell Simulator for Multicellu- #
# lar Systems, PLoS Comput. Biol. 14(2): e1005991, 2018 #
# DOI: 10.1371/journal.pcbi.1005991 #
# #
# [2] A Ghaffarizadeh, SH Friedman, and P Macklin, BioFVM: an efficient para- #
# llelized diffusive transport solver for 3-D biological simulations, #
# Bioinformatics 32(8): 1256-8, 2016. DOI: 10.1093/bioinformatics/btv730 #
# #
###############################################################################
# #
# BSD 3-Clause License (see https://opensource.org/licenses/BSD-3-Clause) #
# #
# Copyright (c) 2015-2018, Paul Macklin and the PhysiCell Project #
# All rights reserved. #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions are met: #
# #
# 1. Redistributions of source code must retain the above copyright notice, #
# this list of conditions and the following disclaimer. #
# #
# 2. Redistributions in binary form must reproduce the above copyright #
# notice, this list of conditions and the following disclaimer in the #
# documentation and/or other materials provided with the distribution. #
# #
# 3. Neither the name of the copyright holder nor the names of its #
# contributors may be used to endorse or promote products derived from this #
# software without specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" #
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE #
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE #
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE #
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR #
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF #
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS #
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN #
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) #
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE #
# POSSIBILITY OF SUCH DAMAGE. #
# #
###############################################################################
*/
-->
<!--
<user_details />
-->
<PhysiCell_settings version="devel-version">
<domain>
<x_min>-500</x_min>
<x_max>500</x_max>
<y_min>-500</y_min>
<y_max>500</y_max>
<z_min>-10</z_min>
<z_max>10</z_max>
<dx>20</dx>
<dy>20</dy>
<dz>20</dz>
<use_2D>true</use_2D>
</domain>
<overall>
<max_time units="min">1440</max_time> <!-- 5 days * 24 h * 60 min -->
<time_units>min</time_units>
<space_units>micron</space_units>
</overall>
<parallel>
<omp_num_threads>4</omp_num_threads>
</parallel>
<save>
<folder>output</folder> <!-- use . for root -->
<full_data>
<interval units="min">60</interval>
<enable>true</enable>
</full_data>
<SVG>
<interval units="min">6</interval>
<enable>true</enable>
</SVG>
<legacy_data>
<enable>false</enable>
</legacy_data>
</save>
<user_parameters>
<random_seed type="int" units="dimensionless">0</random_seed>
<!-- example parameters from the template -->
<!-- motile cell type parameters -->
<motile_cell_persistence_time type="double" units="min">15</motile_cell_persistence_time>
<motile_cell_migration_speed type="double" units="micron/min">0.5</motile_cell_migration_speed>
<motile_cell_relative_adhesion type="double" units="dimensionless">0.05</motile_cell_relative_adhesion>
<motile_cell_apoptosis_rate type="double" units="1/min">0.0</motile_cell_apoptosis_rate>
<motile_cell_relative_cycle_entry_rate type="double" units="dimensionless">0.1</motile_cell_relative_cycle_entry_rate>
</user_parameters>
</PhysiCell_settings>
|
./SPEChpc/benchspec/HPC/628.pot3d_s/src/hdf5/H5HFiblock.c | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*-------------------------------------------------------------------------
*
* Created: H5HFiblock.c
* Apr 10 2006
* Quincey Koziol <koziol@ncsa.uiuc.edu>
*
* Purpose: Indirect block routines for fractal heaps.
*
*-------------------------------------------------------------------------
*/
/****************/
/* Module Setup */
/****************/
#include "H5HFmodule.h" /* This source code file is part of the H5HF module */
/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5Fprivate.h" /* File access */
#include "H5HFpkg.h" /* Fractal heaps */
#include "H5MFprivate.h" /* File memory management */
#include "H5VMprivate.h" /* Vectors and arrays */
/****************/
/* Local Macros */
/****************/
/******************/
/* Local Typedefs */
/******************/
/********************/
/* Package Typedefs */
/********************/
/********************/
/* Local Prototypes */
/********************/
static herr_t H5HF__iblock_pin(H5HF_indirect_t *iblock);
static herr_t H5HF__iblock_unpin(H5HF_indirect_t *iblock);
static herr_t H5HF__man_iblock_root_halve(H5HF_indirect_t *root_iblock);
static herr_t H5HF__man_iblock_root_revert(H5HF_indirect_t *root_iblock);
/*********************/
/* Package Variables */
/*********************/
/* Declare a free list to manage the H5HF_indirect_t struct */
H5FL_DEFINE(H5HF_indirect_t);
/* Declare a free list to manage the H5HF_indirect_ent_t sequence information */
H5FL_SEQ_DEFINE(H5HF_indirect_ent_t);
/* Declare a free list to manage the H5HF_indirect_filt_ent_t sequence information */
H5FL_SEQ_DEFINE(H5HF_indirect_filt_ent_t);
/* Declare a free list to manage the H5HF_indirect_t * sequence information */
H5FL_SEQ_DEFINE(H5HF_indirect_ptr_t);
/*****************************/
/* Library Private Variables */
/*****************************/
/*******************/
/* Local Variables */
/*******************/
/*-------------------------------------------------------------------------
* Function: H5HF__iblock_pin
*
* Purpose: Pin an indirect block in memory
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@hdfgroup.org
* Aug 17 2006
*
*-------------------------------------------------------------------------
*/
static herr_t
H5HF__iblock_pin(H5HF_indirect_t *iblock)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_STATIC
/* Sanity checks */
HDassert(iblock);
/* Mark block as un-evictable */
if(H5AC_pin_protected_entry(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTPIN, FAIL, "unable to pin fractal heap indirect block")
/* If this indirect block has a parent, update it's child iblock pointer */
if(iblock->parent) {
H5HF_indirect_t *par_iblock = iblock->parent; /* Parent indirect block */
unsigned indir_idx; /* Index in parent's child iblock pointer array */
/* Sanity check */
HDassert(par_iblock->child_iblocks);
HDassert(iblock->par_entry >= (iblock->hdr->man_dtable.max_direct_rows
* iblock->hdr->man_dtable.cparam.width));
/* Compute index in parent's child iblock pointer array */
indir_idx = iblock->par_entry - (iblock->hdr->man_dtable.max_direct_rows
* iblock->hdr->man_dtable.cparam.width);
/* Set pointer to pinned indirect block in parent */
HDassert(par_iblock->child_iblocks[indir_idx] == NULL);
par_iblock->child_iblocks[indir_idx] = iblock;
} /* end if */
else {
/* Check for pinning the root indirect block */
if(iblock->block_off == 0) {
/* Sanity check - shouldn't be recursively pinning root indirect block */
HDassert(0 == (iblock->hdr->root_iblock_flags & H5HF_ROOT_IBLOCK_PINNED));
/* Check if we should set the root iblock pointer */
if(0 == iblock->hdr->root_iblock_flags) {
HDassert(NULL == iblock->hdr->root_iblock);
iblock->hdr->root_iblock = iblock;
} /* end if */
/* Indicate that the root indirect block is pinned */
iblock->hdr->root_iblock_flags |= H5HF_ROOT_IBLOCK_PINNED;
} /* end if */
} /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__iblock_pin() */
/*-------------------------------------------------------------------------
* Function: H5HF__iblock_unpin
*
* Purpose: Unpin an indirect block in the metadata cache
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@hdfgroup.org
* Aug 17 2006
*
*-------------------------------------------------------------------------
*/
static herr_t
H5HF__iblock_unpin(H5HF_indirect_t *iblock)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_STATIC
/* Sanity check */
HDassert(iblock);
/* Mark block as evictable again */
if(H5AC_unpin_entry(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTUNPIN, FAIL, "unable to unpin fractal heap indirect block")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__iblock_unpin() */
/*-------------------------------------------------------------------------
* Function: H5HF_iblock_incr
*
* Purpose: Increment reference count on shared indirect block
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Mar 27 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF_iblock_incr(H5HF_indirect_t *iblock)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
/* Sanity checks */
HDassert(iblock);
HDassert(iblock->block_off == 0 || iblock->parent);
/* Mark block as un-evictable when a child block is depending on it */
if(iblock->rc == 0)
if(H5HF__iblock_pin(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTPIN, FAIL, "unable to pin fractal heap indirect block")
/* Increment reference count on shared indirect block */
iblock->rc++;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_iblock_incr() */
/*-------------------------------------------------------------------------
* Function: H5HF__iblock_decr
*
* Purpose: Decrement reference count on shared indirect block
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Mar 27 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF__iblock_decr(H5HF_indirect_t *iblock)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Sanity check */
HDassert(iblock);
/* Decrement reference count on shared indirect block */
iblock->rc--;
/* Check for last reference to block */
if(iblock->rc == 0) {
/* If this indirect block has a parent, reset it's child iblock pointer */
if(iblock->parent) {
H5HF_indirect_t *par_iblock = iblock->parent; /* Parent indirect block */
unsigned indir_idx; /* Index in parent's child iblock pointer array */
/* Sanity check */
HDassert(par_iblock->child_iblocks);
HDassert(iblock->par_entry >= (iblock->hdr->man_dtable.max_direct_rows
* iblock->hdr->man_dtable.cparam.width));
/* Compute index in parent's child iblock pointer array */
indir_idx = iblock->par_entry - (iblock->hdr->man_dtable.max_direct_rows
* iblock->hdr->man_dtable.cparam.width);
/* Reset pointer to pinned child indirect block in parent */
HDassert(par_iblock->child_iblocks[indir_idx]);
par_iblock->child_iblocks[indir_idx] = NULL;
} /* end if */
else {
/* Check for root indirect block */
if(iblock->block_off == 0) {
/* Sanity check - shouldn't be recursively unpinning root indirect block */
HDassert(iblock->hdr->root_iblock_flags & H5HF_ROOT_IBLOCK_PINNED);
/* Check if we should reset the root iblock pointer */
if(H5HF_ROOT_IBLOCK_PINNED == iblock->hdr->root_iblock_flags) {
HDassert(NULL != iblock->hdr->root_iblock);
iblock->hdr->root_iblock = NULL;
} /* end if */
/* Indicate that the root indirect block is unpinned */
iblock->hdr->root_iblock_flags &= (unsigned)(~(H5HF_ROOT_IBLOCK_PINNED));
} /* end if */
} /* end else */
/* Check if the block is still in the cache */
if(!iblock->removed_from_cache) {
/* Unpin the indirect block, making it evictable again */
if(H5HF__iblock_unpin(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTUNPIN, FAIL, "unable to unpin fractal heap indirect block")
} /* end if */
else {
/* Destroy the indirect block */
if(H5HF_man_iblock_dest(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to destroy fractal heap indirect block")
} /* end else */
} /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__iblock_decr() */
/*-------------------------------------------------------------------------
* Function: H5HF_iblock_dirty
*
* Purpose: Mark indirect block as dirty
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Mar 21 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF_iblock_dirty(H5HF_indirect_t *iblock)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
/* Sanity check */
HDassert(iblock);
/* Mark indirect block as dirty in cache */
if(H5AC_mark_entry_dirty(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTMARKDIRTY, FAIL, "unable to mark fractal heap indirect block as dirty")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_iblock_dirty() */
/*-------------------------------------------------------------------------
* Function: H5HF__man_iblock_root_create
*
* Purpose: Create root indirect block
*
* Return: SUCCEED/FAIL
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* May 2 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF__man_iblock_root_create(H5HF_hdr_t *hdr, size_t min_dblock_size)
{
H5HF_indirect_t *iblock; /* Pointer to indirect block */
haddr_t iblock_addr; /* Indirect block's address */
hsize_t acc_dblock_free; /* Accumulated free space in direct blocks */
hbool_t have_direct_block; /* Flag to indicate a direct block already exists */
hbool_t did_protect; /* Whether we protected the indirect block or not */
unsigned nrows; /* Number of rows for root indirect block */
unsigned u; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check for allocating entire root indirect block initially */
if(hdr->man_dtable.cparam.start_root_rows == 0)
nrows = hdr->man_dtable.max_root_rows;
else {
unsigned rows_needed; /* Number of rows needed to get to direct block size */
unsigned block_row_off; /* Row offset from larger block sizes */
nrows = hdr->man_dtable.cparam.start_root_rows;
block_row_off = H5VM_log2_of2((uint32_t)min_dblock_size) - H5VM_log2_of2((uint32_t)hdr->man_dtable.cparam.start_block_size);
if(block_row_off > 0)
block_row_off++; /* Account for the pair of initial rows of the initial block size */
rows_needed = 1 + block_row_off;
if(nrows < rows_needed)
nrows = rows_needed;
} /* end else */
/* Allocate root indirect block */
if(H5HF__man_iblock_create(hdr, NULL, 0, nrows, hdr->man_dtable.max_root_rows, &iblock_addr) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "can't allocate fractal heap indirect block")
/* Move current direct block (used as root) into new indirect block */
/* Lock new indirect block */
if(NULL == (iblock = H5HF__man_iblock_protect(hdr, iblock_addr, nrows, NULL, 0, FALSE, H5AC__NO_FLAGS_SET, &did_protect)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect fractal heap indirect block")
/* Check if there's already a direct block as root) */
have_direct_block = H5F_addr_defined(hdr->man_dtable.table_addr);
if(have_direct_block) {
H5HF_direct_t *dblock; /* Pointer to direct block to query */
/* Lock first (root) direct block */
if(NULL == (dblock = H5HF__man_dblock_protect(hdr, hdr->man_dtable.table_addr, hdr->man_dtable.cparam.start_block_size, NULL, 0, H5AC__NO_FLAGS_SET)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect fractal heap direct block")
/* Attach direct block to new root indirect block */
dblock->parent = iblock;
dblock->par_entry = 0;
/* Destroy flush dependency between direct block and header */
if(H5AC_destroy_flush_dependency(dblock->fd_parent, dblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTUNDEPEND, FAIL, "unable to destroy flush dependency")
dblock->fd_parent = NULL;
/* Create flush dependency between direct block and new root indirect block */
if(H5AC_create_flush_dependency(iblock, dblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDEPEND, FAIL, "unable to create flush dependency")
dblock->fd_parent = iblock;
if(H5HF_man_iblock_attach(iblock, 0, hdr->man_dtable.table_addr) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTATTACH, FAIL, "can't attach root direct block to parent indirect block")
/* Check for I/O filters on this heap */
if(hdr->filter_len > 0) {
/* Set the pipeline filter information from the header */
iblock->filt_ents[0].size = hdr->pline_root_direct_size;
iblock->filt_ents[0].filter_mask = hdr->pline_root_direct_filter_mask;
/* Reset the header's pipeline information */
hdr->pline_root_direct_size = 0;
hdr->pline_root_direct_filter_mask = 0;
} /* end if */
/* Scan free space sections to set any 'parent' pointers to new indirect block */
if(H5HF__space_create_root(hdr, iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTSET, FAIL, "can't set free space section info to new root indirect block")
/* Unlock first (previously the root) direct block */
if(H5AC_unprotect(hdr->f, H5AC_FHEAP_DBLOCK, hdr->man_dtable.table_addr, dblock, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap direct block")
dblock = NULL;
} /* end if */
/* Start iterator at correct location */
if(H5HF_hdr_start_iter(hdr, iblock, (hsize_t)(have_direct_block ? hdr->man_dtable.cparam.start_block_size : 0), have_direct_block) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't initialize block iterator")
/* Check for skipping over direct blocks, in order to get to large enough block */
if(min_dblock_size > hdr->man_dtable.cparam.start_block_size)
/* Add skipped blocks to heap's free space */
if(H5HF__hdr_skip_blocks(hdr, iblock, have_direct_block,
((nrows - 1) * hdr->man_dtable.cparam.width) - have_direct_block) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't add skipped blocks to heap's free space")
/* Mark indirect block as modified */
if(H5HF_iblock_dirty(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, FAIL, "can't mark indirect block as dirty")
/* Unprotect root indirect block (it's pinned by the iterator though) */
if(H5HF__man_iblock_unprotect(iblock, H5AC__DIRTIED_FLAG, did_protect) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap indirect block")
iblock = NULL;
/* Point heap header at new indirect block */
hdr->man_dtable.curr_root_rows = nrows;
hdr->man_dtable.table_addr = iblock_addr;
/* Compute free space in direct blocks referenced from entries in root indirect block */
acc_dblock_free = 0;
for(u = 0; u < nrows; u++)
acc_dblock_free += hdr->man_dtable.row_tot_dblock_free[u] * hdr->man_dtable.cparam.width;
/* Account for potential initial direct block */
if(have_direct_block)
acc_dblock_free -= hdr->man_dtable.row_tot_dblock_free[0];
/* Extend heap to cover new root indirect block */
if(H5HF_hdr_adjust_heap(hdr, hdr->man_dtable.row_block_off[nrows], (hssize_t)acc_dblock_free) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTEXTEND, FAIL, "can't increase space to cover root direct block")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__man_iblock_root_create() */
/*-------------------------------------------------------------------------
* Function: H5HF__man_iblock_root_double
*
* Purpose: Double size of root indirect block
*
* Return: SUCCEED/FAIL
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Apr 17 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF__man_iblock_root_double(H5HF_hdr_t *hdr, size_t min_dblock_size)
{
H5HF_indirect_t *iblock; /* Pointer to root indirect block */
haddr_t new_addr; /* New address of indirect block */
hsize_t acc_dblock_free; /* Accumulated free space in direct blocks */
hsize_t next_size; /* The previous value of the "next size" for the new block iterator */
hsize_t old_iblock_size; /* Old size of indirect block */
unsigned next_row; /* The next row to allocate block in */
unsigned next_entry; /* The previous value of the "next entry" for the new block iterator */
unsigned new_next_entry = 0;/* The new value of the "next entry" for the new block iterator */
unsigned min_nrows = 0; /* Min. # of direct rows */
unsigned old_nrows; /* Old # of rows */
unsigned new_nrows; /* New # of rows */
hbool_t skip_direct_rows = FALSE; /* Whether we are skipping direct rows */
size_t u; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Get "new block" iterator information */
if(H5HF_man_iter_curr(&hdr->next_block, &next_row, NULL, &next_entry, &iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "unable to retrieve current block iterator location")
next_size = hdr->man_dtable.row_block_size[next_row];
/* Make certain the iterator is at the root indirect block */
HDassert(iblock->parent == NULL);
HDassert(iblock->block_off == 0);
/* Keep this for later */
old_nrows = iblock->nrows;
/* Check for skipping over direct block rows */
if(iblock->nrows < hdr->man_dtable.max_direct_rows && min_dblock_size > next_size) {
/* Sanity check */
HDassert(min_dblock_size > hdr->man_dtable.cparam.start_block_size);
/* Set flag */
skip_direct_rows = TRUE;
/* Make certain we allocate at least the required row for the block requested */
min_nrows = 1 + H5HF_dtable_size_to_row(&hdr->man_dtable, min_dblock_size);
/* Set the information for the next block, of the appropriate size */
new_next_entry = (min_nrows - 1) * hdr->man_dtable.cparam.width;
} /* end if */
/* Compute new # of rows in indirect block */
new_nrows = MAX(min_nrows, MIN(2 * iblock->nrows, iblock->max_rows));
/* Check if the indirect block is NOT currently allocated in temp. file space */
/* (temp. file space does not need to be freed) */
if(!H5F_IS_TMP_ADDR(hdr->f, iblock->addr))
/* Free previous indirect block disk space */
if(H5MF_xfree(hdr->f, H5FD_MEM_FHEAP_IBLOCK, iblock->addr, (hsize_t)iblock->size) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to free fractal heap indirect block file space")
/* Compute size of buffer needed for new indirect block */
iblock->nrows = new_nrows;
old_iblock_size = iblock->size;
iblock->size = H5HF_MAN_INDIRECT_SIZE(hdr, iblock->nrows);
/* Allocate [temporary] space for the new indirect block on disk */
if(H5F_USE_TMP_SPACE(hdr->f)) {
if(HADDR_UNDEF == (new_addr = H5MF_alloc_tmp(hdr->f, (hsize_t)iblock->size)))
HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "file allocation failed for fractal heap indirect block")
} /* end if */
else {
if(HADDR_UNDEF == (new_addr = H5MF_alloc(hdr->f, H5FD_MEM_FHEAP_IBLOCK, (hsize_t)iblock->size)))
HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "file allocation failed for fractal heap indirect block")
} /* end else */
/* Resize pinned indirect block in the cache, if its changed size */
if(old_iblock_size != iblock->size) {
if(H5AC_resize_entry(iblock, (size_t)iblock->size) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTRESIZE, FAIL, "unable to resize fractal heap indirect block")
} /* end if */
/* Move object in cache, if it actually was relocated */
if(H5F_addr_ne(iblock->addr, new_addr)) {
if(H5AC_move_entry(hdr->f, H5AC_FHEAP_IBLOCK, iblock->addr, new_addr) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTMOVE, FAIL, "unable to move fractal heap root indirect block")
iblock->addr = new_addr;
} /* end if */
/* Re-allocate child block entry array */
if(NULL == (iblock->ents = H5FL_SEQ_REALLOC(H5HF_indirect_ent_t, iblock->ents, (size_t)(iblock->nrows * hdr->man_dtable.cparam.width))))
HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "memory allocation failed for direct entries")
/* Check for skipping over rows and add free section for skipped rows */
if(skip_direct_rows)
/* Add skipped blocks to heap's free space */
if(H5HF__hdr_skip_blocks(hdr, iblock, next_entry, (new_next_entry - next_entry)) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't add skipped blocks to heap's free space")
/* Initialize new direct block entries in rows added */
acc_dblock_free = 0;
for(u = (old_nrows * hdr->man_dtable.cparam.width); u < (iblock->nrows * hdr->man_dtable.cparam.width); u++) {
unsigned row = (unsigned)(u / hdr->man_dtable.cparam.width); /* Row for current entry */
iblock->ents[u].addr = HADDR_UNDEF;
acc_dblock_free += hdr->man_dtable.row_tot_dblock_free[row];
} /* end for */
/* Check for needing to re-allocate filtered entry array */
if(hdr->filter_len > 0 && old_nrows < hdr->man_dtable.max_direct_rows) {
unsigned dir_rows; /* Number of direct rows in this indirect block */
/* Compute the number of direct rows for this indirect block */
dir_rows = MIN(iblock->nrows, hdr->man_dtable.max_direct_rows);
HDassert(dir_rows > old_nrows);
/* Re-allocate filtered direct block entry array */
if(NULL == (iblock->filt_ents = H5FL_SEQ_REALLOC(H5HF_indirect_filt_ent_t, iblock->filt_ents, (size_t)(dir_rows * hdr->man_dtable.cparam.width))))
HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "memory allocation failed for filtered direct entries")
/* Initialize new entries allocated */
for(u = (old_nrows * hdr->man_dtable.cparam.width); u < (dir_rows * hdr->man_dtable.cparam.width); u++) {
iblock->filt_ents[u].size = 0;
iblock->filt_ents[u].filter_mask = 0;
} /* end for */
} /* end if */
/* Check for needing to re-allocate child iblock pointer array */
if(iblock->nrows > hdr->man_dtable.max_direct_rows) {
unsigned indir_rows; /* Number of indirect rows in this indirect block */
unsigned old_indir_rows; /* Previous number of indirect rows in this indirect block */
/* Compute the number of direct rows for this indirect block */
indir_rows = iblock->nrows - hdr->man_dtable.max_direct_rows;
/* Re-allocate child indirect block array */
if(NULL == (iblock->child_iblocks = H5FL_SEQ_REALLOC(H5HF_indirect_ptr_t, iblock->child_iblocks, (size_t)(indir_rows * hdr->man_dtable.cparam.width))))
HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "memory allocation failed for filtered direct entries")
/* Compute the previous # of indirect rows in this block */
if(old_nrows < hdr->man_dtable.max_direct_rows)
old_indir_rows = 0;
else
old_indir_rows = old_nrows - hdr->man_dtable.max_direct_rows;
/* Initialize new entries allocated */
for(u = (old_indir_rows * hdr->man_dtable.cparam.width); u < (indir_rows * hdr->man_dtable.cparam.width); u++)
iblock->child_iblocks[u] = NULL;
} /* end if */
/* Mark indirect block as dirty */
if(H5HF_iblock_dirty(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, FAIL, "can't mark indirect block as dirty")
/* Update other shared header info */
hdr->man_dtable.curr_root_rows = new_nrows;
hdr->man_dtable.table_addr = new_addr;
/* Extend heap to cover new root indirect block */
if(H5HF_hdr_adjust_heap(hdr, 2 * hdr->man_dtable.row_block_off[new_nrows - 1], (hssize_t)acc_dblock_free) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTEXTEND, FAIL, "can't increase space to cover root direct block")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__man_iblock_root_double() */
/*-------------------------------------------------------------------------
* Function: H5HF__man_iblock_root_halve
*
* Purpose: Halve size of root indirect block
*
* Return: SUCCEED/FAIL
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Jun 12 2006
*
*-------------------------------------------------------------------------
*/
static herr_t
H5HF__man_iblock_root_halve(H5HF_indirect_t *iblock)
{
H5HF_hdr_t *hdr = iblock->hdr; /* Pointer to heap header */
haddr_t new_addr; /* New address of indirect block */
hsize_t acc_dblock_free; /* Accumulated free space in direct blocks */
hsize_t old_size; /* Old size of indirect block */
unsigned max_child_row; /* Row for max. child entry */
unsigned old_nrows; /* Old # of rows */
unsigned new_nrows; /* New # of rows */
unsigned u; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_STATIC
/* Sanity check */
HDassert(iblock);
HDassert(iblock->parent == NULL);
HDassert(hdr);
/* Compute maximum row used by child of indirect block */
max_child_row = iblock->max_child / hdr->man_dtable.cparam.width;
/* Compute new # of rows in root indirect block */
new_nrows = (unsigned)1 << (1 + H5VM_log2_gen((uint64_t)max_child_row));
/* Check if the indirect block is NOT currently allocated in temp. file space */
/* (temp. file space does not need to be freed) */
if(!H5F_IS_TMP_ADDR(hdr->f, iblock->addr))
/* Free previous indirect block disk space */
if(H5MF_xfree(hdr->f, H5FD_MEM_FHEAP_IBLOCK, iblock->addr, (hsize_t)iblock->size) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to free fractal heap indirect block file space")
/* Compute free space in rows to delete */
acc_dblock_free = 0;
for(u = new_nrows; u < iblock->nrows; u++)
acc_dblock_free += hdr->man_dtable.row_tot_dblock_free[u] * hdr->man_dtable.cparam.width;
/* Compute size of buffer needed for new indirect block */
old_nrows = iblock->nrows;
iblock->nrows = new_nrows;
old_size = iblock->size;
iblock->size = H5HF_MAN_INDIRECT_SIZE(hdr, iblock->nrows);
/* Allocate [temporary] space for the new indirect block on disk */
if(H5F_USE_TMP_SPACE(hdr->f)) {
if(HADDR_UNDEF == (new_addr = H5MF_alloc_tmp(hdr->f, (hsize_t)iblock->size)))
HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "file allocation failed for fractal heap indirect block")
} /* end if */
else {
if(HADDR_UNDEF == (new_addr = H5MF_alloc(hdr->f, H5FD_MEM_FHEAP_IBLOCK, (hsize_t)iblock->size)))
HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "file allocation failed for fractal heap indirect block")
} /* end else */
/* Resize pinned indirect block in the cache, if it has changed size */
if(old_size != iblock->size) {
if(H5AC_resize_entry(iblock, (size_t)iblock->size) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTRESIZE, FAIL, "unable to resize fractal heap indirect block")
} /* end if */
/* Move object in cache, if it actually was relocated */
if(H5F_addr_ne(iblock->addr, new_addr)) {
if(H5AC_move_entry(hdr->f, H5AC_FHEAP_IBLOCK, iblock->addr, new_addr) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTSPLIT, FAIL, "unable to move fractal heap root indirect block")
iblock->addr = new_addr;
} /* end if */
/* Re-allocate child block entry array */
if(NULL == (iblock->ents = H5FL_SEQ_REALLOC(H5HF_indirect_ent_t, iblock->ents, (size_t)(iblock->nrows * hdr->man_dtable.cparam.width))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for direct entries")
/* Check for needing to re-allocate filtered entry array */
if(hdr->filter_len > 0 && new_nrows < hdr->man_dtable.max_direct_rows) {
/* Re-allocate filtered direct block entry array */
if(NULL == (iblock->filt_ents = H5FL_SEQ_REALLOC(H5HF_indirect_filt_ent_t, iblock->filt_ents, (size_t)(iblock->nrows * hdr->man_dtable.cparam.width))))
HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "memory allocation failed for filtered direct entries")
} /* end if */
/* Check for needing to re-allocate child iblock pointer array */
if(old_nrows > hdr->man_dtable.max_direct_rows) {
/* Check for shrinking away child iblock pointer array */
if(iblock->nrows > hdr->man_dtable.max_direct_rows) {
unsigned indir_rows; /* Number of indirect rows in this indirect block */
/* Compute the number of direct rows for this indirect block */
indir_rows = iblock->nrows - hdr->man_dtable.max_direct_rows;
/* Re-allocate child indirect block array */
if(NULL == (iblock->child_iblocks = H5FL_SEQ_REALLOC(H5HF_indirect_ptr_t, iblock->child_iblocks, (size_t)(indir_rows * hdr->man_dtable.cparam.width))))
HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "memory allocation failed for filtered direct entries")
} /* end if */
else
iblock->child_iblocks = (H5HF_indirect_ptr_t *)H5FL_SEQ_FREE(H5HF_indirect_ptr_t, iblock->child_iblocks);
} /* end if */
/* Mark indirect block as dirty */
if(H5HF_iblock_dirty(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, FAIL, "can't mark indirect block as dirty")
/* Update other shared header info */
hdr->man_dtable.curr_root_rows = new_nrows;
hdr->man_dtable.table_addr = new_addr;
/* Shrink heap to only cover new root indirect block */
if(H5HF_hdr_adjust_heap(hdr, 2 * hdr->man_dtable.row_block_off[new_nrows - 1], -(hssize_t)acc_dblock_free) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTSHRINK, FAIL, "can't reduce space to cover root direct block")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__man_iblock_root_halve() */
/*-------------------------------------------------------------------------
* Function: H5HF__man_iblock_root_revert
*
* Purpose: Revert root indirect block back to root direct block
*
* Note: Any sections left pointing to the old root indirect block
* will be cleaned up by the free space manager
*
* Return: SUCCEED/FAIL
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* May 31 2006
*
*-------------------------------------------------------------------------
*/
static herr_t
H5HF__man_iblock_root_revert(H5HF_indirect_t *root_iblock)
{
H5HF_hdr_t *hdr; /* Pointer to heap's header */
H5HF_direct_t *dblock = NULL; /* Pointer to new root indirect block */
haddr_t dblock_addr; /* Direct block's address in the file */
size_t dblock_size; /* Direct block's size */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_STATIC
/*
* Check arguments.
*/
HDassert(root_iblock);
/* Set up local convenience variables */
hdr = root_iblock->hdr;
dblock_addr = root_iblock->ents[0].addr;
dblock_size = hdr->man_dtable.cparam.start_block_size;
/* Get pointer to last direct block */
if(NULL == (dblock = H5HF__man_dblock_protect(hdr, dblock_addr, dblock_size, root_iblock, 0, H5AC__NO_FLAGS_SET)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect fractal heap direct block")
HDassert(dblock->parent == root_iblock);
HDassert(dblock->par_entry == 0);
/* Check for I/O filters on this heap */
if(hdr->filter_len > 0) {
/* Set the header's pipeline information from the indirect block */
hdr->pline_root_direct_size = root_iblock->filt_ents[0].size;
hdr->pline_root_direct_filter_mask = root_iblock->filt_ents[0].filter_mask;
} /* end if */
/* Destroy flush dependency between old root iblock and new root direct block */
if(H5AC_destroy_flush_dependency(dblock->fd_parent, dblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTUNDEPEND, FAIL, "unable to destroy flush dependency")
dblock->fd_parent = NULL;
/* Detach direct block from parent */
if(H5HF__man_iblock_detach(dblock->parent, 0) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTATTACH, FAIL, "can't detach direct block from parent indirect block")
dblock->parent = NULL;
dblock->par_entry = 0;
/* Create flush dependency between header and new root direct block */
if(H5AC_create_flush_dependency(hdr, dblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDEPEND, FAIL, "unable to create flush dependency")
dblock->fd_parent = hdr;
/* Point root at direct block */
hdr->man_dtable.curr_root_rows = 0;
hdr->man_dtable.table_addr = dblock_addr;
/* Reset 'next block' iterator */
if(H5HF_hdr_reset_iter(hdr, (hsize_t)dblock_size) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't reset block iterator")
/* Extend heap to just cover first direct block */
if(H5HF_hdr_adjust_heap(hdr, (hsize_t)hdr->man_dtable.cparam.start_block_size, (hssize_t)hdr->man_dtable.row_tot_dblock_free[0]) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTEXTEND, FAIL, "can't increase space to cover root direct block")
/* Scan free space sections to reset any 'parent' pointers */
if(H5HF__space_revert_root(hdr) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTRESET, FAIL, "can't reset free space section info")
done:
if(dblock && H5AC_unprotect(hdr->f, H5AC_FHEAP_DBLOCK, dblock_addr, dblock, H5AC__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap direct block")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__man_iblock_root_revert() */
/*-------------------------------------------------------------------------
* Function: H5HF__man_iblock_alloc_row
*
* Purpose: Allocate a "single" section for an object, out of a
* "row" section.
*
* Note: Creates necessary direct & indirect blocks
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* July 6 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF__man_iblock_alloc_row(H5HF_hdr_t *hdr, H5HF_free_section_t **sec_node)
{
H5HF_indirect_t *iblock = NULL; /* Pointer to indirect block */
H5HF_free_section_t *old_sec_node = *sec_node; /* Pointer to old indirect section node */
unsigned dblock_entry; /* Entry for direct block */
hbool_t iblock_held = FALSE; /* Flag to indicate that indirect block is held */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/*
* Check arguments.
*/
HDassert(hdr);
HDassert(sec_node && old_sec_node);
HDassert(old_sec_node->u.row.row < hdr->man_dtable.max_direct_rows);
/* Check for serialized row section, or serialized / deleted indirect
* section under it. */
if(old_sec_node->sect_info.state == H5FS_SECT_SERIALIZED
|| (H5FS_SECT_SERIALIZED == old_sec_node->u.row.under->sect_info.state)
|| (TRUE == old_sec_node->u.row.under->u.indirect.u.iblock->removed_from_cache))
/* Revive row and / or indirect section */
if(H5HF__sect_row_revive(hdr, old_sec_node) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTREVIVE, FAIL, "can't revive indirect section")
/* Get a pointer to the indirect block covering the section */
if(NULL == (iblock = H5HF_sect_row_get_iblock(old_sec_node)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't retrieve indirect block for row section")
/* Hold indirect block in memory, until direct block can point to it */
if(H5HF_iblock_incr(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, FAIL, "can't increment reference count on shared indirect block")
iblock_held = TRUE;
/* Reduce (& possibly re-add) 'row' section */
if(H5HF__sect_row_reduce(hdr, old_sec_node, &dblock_entry) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTSHRINK, FAIL, "can't reduce row section node")
/* Create direct block & single section */
if(H5HF__man_dblock_create(hdr, iblock, dblock_entry, NULL, sec_node) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "can't allocate fractal heap direct block")
done:
/* Release hold on indirect block */
if(iblock_held)
if(H5HF__iblock_decr(iblock) < 0)
HDONE_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't decrement reference count on shared indirect block")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__man_iblock_alloc_row() */
/*-------------------------------------------------------------------------
* Function: H5HF__man_iblock_create
*
* Purpose: Allocate & initialize a managed indirect block
*
* Return: SUCCEED/FAIL
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Mar 6 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF__man_iblock_create(H5HF_hdr_t *hdr, H5HF_indirect_t *par_iblock,
unsigned par_entry, unsigned nrows, unsigned max_rows, haddr_t *addr_p)
{
H5HF_indirect_t *iblock = NULL; /* Pointer to indirect block */
size_t u; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/*
* Check arguments.
*/
HDassert(hdr);
HDassert(nrows > 0);
HDassert(addr_p);
/*
* Allocate file and memory data structures.
*/
if(NULL == (iblock = H5FL_MALLOC(H5HF_indirect_t)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for fractal heap indirect block")
/* Reset the metadata cache info for the heap header */
HDmemset(&iblock->cache_info, 0, sizeof(H5AC_info_t));
/* Share common heap information */
iblock->hdr = hdr;
if(H5HF_hdr_incr(hdr) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, FAIL, "can't increment reference count on shared heap header")
/* Set info for indirect block */
iblock->rc = 0;
iblock->nrows = nrows;
iblock->max_rows = max_rows;
iblock->removed_from_cache = FALSE;
/* Compute size of buffer needed for indirect block */
iblock->size = H5HF_MAN_INDIRECT_SIZE(hdr, iblock->nrows);
/* Allocate child block entry array */
if(NULL == (iblock->ents = H5FL_SEQ_MALLOC(H5HF_indirect_ent_t, (size_t)(iblock->nrows * hdr->man_dtable.cparam.width))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for block entries")
/* Initialize indirect block entry tables */
for(u = 0; u < (iblock->nrows * hdr->man_dtable.cparam.width); u++)
iblock->ents[u].addr = HADDR_UNDEF;
/* Check for I/O filters to apply to this heap */
if(hdr->filter_len > 0) {
unsigned dir_rows; /* Number of direct rows in this indirect block */
/* Compute the number of direct rows for this indirect block */
dir_rows = MIN(iblock->nrows, hdr->man_dtable.max_direct_rows);
/* Allocate & initialize indirect block filtered entry array */
if(NULL == (iblock->filt_ents = H5FL_SEQ_CALLOC(H5HF_indirect_filt_ent_t, (size_t)(dir_rows * hdr->man_dtable.cparam.width))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for block entries")
} /* end if */
else
iblock->filt_ents = NULL;
/* Check if we have any indirect block children */
if(iblock->nrows > hdr->man_dtable.max_direct_rows) {
unsigned indir_rows; /* Number of indirect rows in this indirect block */
/* Compute the number of indirect rows for this indirect block */
indir_rows = iblock->nrows - hdr->man_dtable.max_direct_rows;
/* Allocate & initialize child indirect block pointer array */
if(NULL == (iblock->child_iblocks = H5FL_SEQ_CALLOC(H5HF_indirect_ptr_t, (size_t)(indir_rows * hdr->man_dtable.cparam.width))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for block entries")
} /* end if */
else
iblock->child_iblocks = NULL;
/* Allocate [temporary] space for the indirect block on disk */
if(H5F_USE_TMP_SPACE(hdr->f)) {
if(HADDR_UNDEF == (*addr_p = H5MF_alloc_tmp(hdr->f, (hsize_t)iblock->size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "file allocation failed for fractal heap indirect block")
} /* end if */
else {
if(HADDR_UNDEF == (*addr_p = H5MF_alloc(hdr->f, H5FD_MEM_FHEAP_IBLOCK, (hsize_t)iblock->size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "file allocation failed for fractal heap indirect block")
} /* end else */
iblock->addr = *addr_p;
/* Attach to parent indirect block, if there is one */
iblock->parent = par_iblock;
iblock->par_entry = par_entry;
if(iblock->parent) {
/* Attach new block to parent */
if(H5HF_man_iblock_attach(iblock->parent, par_entry, *addr_p) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTATTACH, FAIL, "can't attach indirect block to parent indirect block")
/* Compute the indirect block's offset in the heap's address space */
/* (based on parent's block offset) */
iblock->block_off = par_iblock->block_off;
iblock->block_off += hdr->man_dtable.row_block_off[par_entry / hdr->man_dtable.cparam.width];
iblock->block_off += hdr->man_dtable.row_block_size[par_entry / hdr->man_dtable.cparam.width] * (par_entry % hdr->man_dtable.cparam.width);
/* Set indirect block parent as flush dependency parent */
iblock->fd_parent = par_iblock;
} /* end if */
else {
iblock->block_off = 0; /* Must be the root indirect block... */
/* Set heap header as flush dependency parent */
iblock->fd_parent = hdr;
} /* end else */
/* Update indirect block's statistics */
iblock->nchildren = 0;
iblock->max_child = 0;
/* Cache the new indirect block */
if(H5AC_insert_entry(hdr->f, H5AC_FHEAP_IBLOCK, *addr_p, iblock, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't add fractal heap indirect block to cache")
done:
if(ret_value < 0)
if(iblock)
if(H5HF_man_iblock_dest(iblock) < 0)
HDONE_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to destroy fractal heap indirect block")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__man_iblock_create() */
/*-------------------------------------------------------------------------
* Function: H5HF__man_iblock_protect
*
* Purpose: Convenience wrapper around H5AC_protect on an indirect block
*
* Return: Pointer to indirect block on success, NULL on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Apr 17 2006
*
*-------------------------------------------------------------------------
*/
H5HF_indirect_t *
H5HF__man_iblock_protect(H5HF_hdr_t *hdr, haddr_t iblock_addr,
unsigned iblock_nrows, H5HF_indirect_t *par_iblock, unsigned par_entry,
hbool_t must_protect, unsigned flags, hbool_t *did_protect)
{
H5HF_parent_t par_info; /* Parent info for loading block */
H5HF_indirect_t *iblock = NULL; /* Indirect block from cache */
hbool_t should_protect = FALSE; /* Whether we should protect the indirect block or not */
H5HF_indirect_t *ret_value = NULL; /* Return value */
FUNC_ENTER_PACKAGE
/*
* Check arguments.
*/
HDassert(hdr);
HDassert(H5F_addr_defined(iblock_addr));
HDassert(iblock_nrows > 0);
HDassert(did_protect);
/* only H5AC__READ_ONLY_FLAG may appear in flags */
HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0);
/* Check if we are allowed to use existing pinned iblock pointer */
if(!must_protect) {
/* Check for this block already being pinned */
if(par_iblock) {
unsigned indir_idx; /* Index in parent's child iblock pointer array */
/* Sanity check */
HDassert(par_iblock->child_iblocks);
HDassert(par_entry >= (hdr->man_dtable.max_direct_rows
* hdr->man_dtable.cparam.width));
/* Compute index in parent's child iblock pointer array */
indir_idx = par_entry - (hdr->man_dtable.max_direct_rows
* hdr->man_dtable.cparam.width);
/* Check for pointer to pinned indirect block in parent */
if(par_iblock->child_iblocks[indir_idx])
iblock = par_iblock->child_iblocks[indir_idx];
else
should_protect = TRUE;
} /* end if */
else {
/* Check for root indirect block */
if(H5F_addr_eq(iblock_addr, hdr->man_dtable.table_addr)) {
/* Check for valid pointer to pinned indirect block in root */
if(H5HF_ROOT_IBLOCK_PINNED == hdr->root_iblock_flags) {
/* Sanity check */
HDassert(NULL != hdr->root_iblock);
/* Return the pointer to the pinned root indirect block */
iblock = hdr->root_iblock;
} /* end if */
else {
/* Sanity check */
HDassert(NULL == hdr->root_iblock);
should_protect = TRUE;
} /* end else */
} /* end if */
else
should_protect = TRUE;
} /* end else */
} /* end if */
/* Check for protecting indirect block */
if(must_protect || should_protect) {
H5HF_iblock_cache_ud_t cache_udata; /* User-data for callback */
/* Set up parent info */
par_info.hdr = hdr;
par_info.iblock = par_iblock;
par_info.entry = par_entry;
/* Set up user data for protect call */
cache_udata.f = hdr->f;
cache_udata.par_info = &par_info;
cache_udata.nrows = &iblock_nrows;
/* Protect the indirect block */
if(NULL == (iblock = (H5HF_indirect_t *)H5AC_protect(hdr->f, H5AC_FHEAP_IBLOCK, iblock_addr, &cache_udata, flags)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, NULL, "unable to protect fractal heap indirect block")
/* Set the indirect block's address */
iblock->addr = iblock_addr;
/* Check for root indirect block */
if(iblock->block_off == 0) {
/* Sanity check - shouldn't be recursively protecting root indirect block */
HDassert(0 == (hdr->root_iblock_flags & H5HF_ROOT_IBLOCK_PROTECTED));
/* Check if we should set the root iblock pointer */
if(0 == hdr->root_iblock_flags) {
HDassert(NULL == hdr->root_iblock);
hdr->root_iblock = iblock;
} /* end if */
/* Indicate that the root indirect block is protected */
hdr->root_iblock_flags |= H5HF_ROOT_IBLOCK_PROTECTED;
} /* end if */
/* Indicate that the indirect block was protected */
*did_protect = TRUE;
} /* end if */
else
/* Indicate that the indirect block was _not_ protected */
*did_protect = FALSE;
/* Set the return value */
ret_value = iblock;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__man_iblock_protect() */
/*-------------------------------------------------------------------------
* Function: H5HF__man_iblock_unprotect
*
* Purpose: Convenience wrapper around H5AC_unprotect on an indirect block
*
* Return: SUCCEED/FAIL
*
* Programmer: Quincey Koziol
* koziol@hdfgroup.org
* Aug 17 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF__man_iblock_unprotect(H5HF_indirect_t *iblock, unsigned cache_flags,
hbool_t did_protect)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/*
* Check arguments.
*/
HDassert(iblock);
/* Check if we previously protected this indirect block */
/* (as opposed to using an existing pointer to a pinned child indirect block) */
if(did_protect) {
/* Check for root indirect block */
if(iblock->block_off == 0) {
/* Sanity check - shouldn't be recursively unprotecting root indirect block */
HDassert(iblock->hdr->root_iblock_flags & H5HF_ROOT_IBLOCK_PROTECTED);
/* Check if we should reset the root iblock pointer */
if(H5HF_ROOT_IBLOCK_PROTECTED == iblock->hdr->root_iblock_flags) {
HDassert(NULL != iblock->hdr->root_iblock);
iblock->hdr->root_iblock = NULL;
} /* end if */
/* Indicate that the root indirect block is unprotected */
iblock->hdr->root_iblock_flags &= (unsigned)(~(H5HF_ROOT_IBLOCK_PROTECTED));
} /* end if */
/* Unprotect the indirect block */
if(H5AC_unprotect(iblock->hdr->f, H5AC_FHEAP_IBLOCK, iblock->addr, iblock, cache_flags) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap indirect block")
} /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__man_iblock_unprotect() */
/*-------------------------------------------------------------------------
* Function: H5HF_man_iblock_attach
*
* Purpose: Attach a child block (direct or indirect) to an indirect block
*
* Return: SUCCEED/FAIL
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* May 30 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF_man_iblock_attach(H5HF_indirect_t *iblock, unsigned entry, haddr_t child_addr)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
/*
* Check arguments.
*/
HDassert(iblock);
HDassert(H5F_addr_defined(child_addr));
HDassert(!H5F_addr_defined(iblock->ents[entry].addr));
/* Increment the reference count on this indirect block */
if(H5HF_iblock_incr(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, FAIL, "can't increment reference count on shared indirect block")
/* Point at the child block */
iblock->ents[entry].addr = child_addr;
/* Check for I/O filters on this heap */
if(iblock->hdr->filter_len > 0) {
unsigned row; /* Row for entry */
/* Sanity check */
HDassert(iblock->filt_ents);
/* Compute row for entry */
row = entry / iblock->hdr->man_dtable.cparam.width;
/* If this is a direct block, set its initial size */
if(row < iblock->hdr->man_dtable.max_direct_rows)
iblock->filt_ents[entry].size = iblock->hdr->man_dtable.row_block_size[row];
} /* end if */
/* Check for max. entry used */
if(entry > iblock->max_child)
iblock->max_child = entry;
/* Increment the # of child blocks */
iblock->nchildren++;
/* Mark indirect block as modified */
if(H5HF_iblock_dirty(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, FAIL, "can't mark indirect block as dirty")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_man_iblock_attach() */
/*-------------------------------------------------------------------------
* Function: H5HF__man_iblock_detach
*
* Purpose: Detach a child block (direct or indirect) from an indirect block
*
* Return: SUCCEED/FAIL
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* May 31 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF__man_iblock_detach(H5HF_indirect_t *iblock, unsigned entry)
{
H5HF_hdr_t *hdr; /* Fractal heap header */
H5HF_indirect_t *del_iblock = NULL; /* Pointer to protected indirect block, when deleting */
unsigned row; /* Row for entry */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/*
* Check arguments.
*/
HDassert(iblock);
HDassert(iblock->nchildren);
/* Set up convenience variables */
hdr = iblock->hdr;
/* Reset address of entry */
iblock->ents[entry].addr = HADDR_UNDEF;
/* Compute row for entry */
row = entry / hdr->man_dtable.cparam.width;
/* Check for I/O filters on this heap */
if(hdr->filter_len > 0) {
/* Sanity check */
HDassert(iblock->filt_ents);
/* If this is a direct block, reset its initial size */
if(row < hdr->man_dtable.max_direct_rows) {
iblock->filt_ents[entry].size = 0;
iblock->filt_ents[entry].filter_mask = 0;
} /* end if */
} /* end if */
/* Check for indirect block being detached */
if(row >= hdr->man_dtable.max_direct_rows) {
unsigned indir_idx; /* Index in parent's child iblock pointer array */
/* Sanity check */
HDassert(iblock->child_iblocks);
/* Compute index in child iblock pointer array */
indir_idx = entry - (hdr->man_dtable.max_direct_rows * hdr->man_dtable.cparam.width);
/* Sanity check */
HDassert(iblock->child_iblocks[indir_idx]);
/* Reset pointer to child indirect block in parent */
iblock->child_iblocks[indir_idx] = NULL;
} /* end if */
/* Decrement the # of child blocks */
/* (If the number of children drop to 0, the indirect block will be
* removed from the heap when its ref. count drops to zero and the
* metadata cache calls the indirect block destructor)
*/
iblock->nchildren--;
/* Reduce the max. entry used, if necessary */
if(entry == iblock->max_child) {
if(iblock->nchildren > 0)
while(!H5F_addr_defined(iblock->ents[iblock->max_child].addr))
iblock->max_child--;
else
iblock->max_child = 0;
} /* end if */
/* If this is the root indirect block handle some special cases */
if(iblock->block_off == 0) {
/* If the number of children drops to 1, and that child is the first
* direct block in the heap, convert the heap back to using a root
* direct block
*/
if(iblock->nchildren == 1 && H5F_addr_defined(iblock->ents[0].addr))
if(H5HF__man_iblock_root_revert(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTSHRINK, FAIL, "can't convert root indirect block back to root direct block")
/* If the indirect block wasn't removed already (by reverting it) */
if(!iblock->removed_from_cache) {
/* Check for reducing size of root indirect block */
if(iblock->nchildren > 0 && hdr->man_dtable.cparam.start_root_rows != 0
&& entry > iblock->max_child) {
unsigned max_child_row; /* Row for max. child entry */
/* Compute information needed for determining whether to reduce size of root indirect block */
max_child_row = iblock->max_child / hdr->man_dtable.cparam.width;
/* Check if the root indirect block should be reduced */
if(iblock->nrows > 1 && max_child_row <= (iblock->nrows / 2))
if(H5HF__man_iblock_root_halve(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTSHRINK, FAIL, "can't reduce size of root indirect block")
} /* end if */
} /* end if */
} /* end if */
/* If the indirect block wasn't removed already (by reverting it) */
if(!iblock->removed_from_cache) {
/* Mark indirect block as modified */
if(H5HF_iblock_dirty(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, FAIL, "can't mark indirect block as dirty")
/* Check for last child being removed from indirect block */
if(iblock->nchildren == 0) {
hbool_t did_protect = FALSE; /* Whether the indirect block was protected */
/* If this indirect block's refcount is >1, then it's being deleted
* from the fractal heap (since its nchildren == 0), but is still
* referred to from free space sections in the heap (refcount >1).
* Its space in the file needs to be freed now, and it also needs
* to be removed from the metadata cache now, in case the space in
* the file is reused by another piece of metadata that is inserted
* into the cache before the indirect block's entry is evicted
* (having two entries at the same address would be an error, from
* the cache's perspective).
*/
/* Lock indirect block for deletion */
if(NULL == (del_iblock = H5HF__man_iblock_protect(hdr, iblock->addr, iblock->nrows, iblock->parent, iblock->par_entry, TRUE, H5AC__NO_FLAGS_SET, &did_protect)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect fractal heap indirect block")
HDassert(did_protect == TRUE);
/* Check for deleting root indirect block (and no root direct block) */
if(iblock->block_off == 0 && hdr->man_dtable.curr_root_rows > 0)
/* Reset header information back to "empty heap" state */
if(H5HF__hdr_empty(hdr) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTSHRINK, FAIL, "can't make heap empty")
/* Detach from parent indirect block */
if(iblock->parent) {
/* Destroy flush dependency between indirect block and parent */
if(H5AC_destroy_flush_dependency(iblock->fd_parent, iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTUNDEPEND, FAIL, "unable to destroy flush dependency")
iblock->fd_parent = NULL;
/* Detach from parent indirect block */
if(H5HF__man_iblock_detach(iblock->parent, iblock->par_entry) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTATTACH, FAIL, "can't detach from parent indirect block")
iblock->parent = NULL;
iblock->par_entry = 0;
} /* end if */
} /* end if */
} /* end if */
/* Decrement the reference count on this indirect block if we're not deleting it */
/* (should be after iblock needs to be modified, so that potential 'unpin'
* on this indirect block doesn't invalidate the 'iblock' variable, if it's
* not being deleted)
*/
if(H5HF__iblock_decr(iblock) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't decrement reference count on shared indirect block")
iblock = NULL;
/* Delete indirect block from cache, if appropriate */
if(del_iblock) {
unsigned cache_flags = H5AC__NO_FLAGS_SET; /* Flags for unprotect */
hbool_t took_ownership = FALSE; /* Flag to indicate that block ownership has transitioned */
/* If the refcount is still >0, unpin the block and take ownership
* from the cache, otherwise let the cache destroy it.
*/
if(del_iblock->rc > 0) {
cache_flags |= (H5AC__DELETED_FLAG | H5AC__TAKE_OWNERSHIP_FLAG);
cache_flags |= H5AC__UNPIN_ENTRY_FLAG;
took_ownership = TRUE;
} /* end if */
else {
/* Entry should be removed from the cache */
cache_flags |= H5AC__DELETED_FLAG;
/* If the indirect block is in real file space, tell
* the cache to free its file space as well.
*/
if(!H5F_IS_TMP_ADDR(hdr->f, del_iblock->addr))
cache_flags |= H5AC__FREE_FILE_SPACE_FLAG;
} /* end else */
/* Unprotect the indirect block, with appropriate flags */
if(H5HF__man_iblock_unprotect(del_iblock, cache_flags, TRUE) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap indirect block")
/* if took ownership, free file space & mark block as removed from cache */
if(took_ownership) {
/* Free indirect block disk space, if it's in real space */
if(!H5F_IS_TMP_ADDR(hdr->f, del_iblock->addr))
if(H5MF_xfree(hdr->f, H5FD_MEM_FHEAP_IBLOCK, del_iblock->addr, (hsize_t)del_iblock->size) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to free fractal heap indirect block file space")
del_iblock->addr = HADDR_UNDEF;
/* Mark block as removed from the cache */
del_iblock->removed_from_cache = TRUE;
} /* end if */
} /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__man_iblock_detach() */
/*-------------------------------------------------------------------------
* Function: H5HF_man_iblock_entry_addr
*
* Purpose: Retrieve the address of an indirect block's child
*
* Return: SUCCEED/FAIL
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* July 10 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF_man_iblock_entry_addr(H5HF_indirect_t *iblock, unsigned entry, haddr_t *child_addr)
{
FUNC_ENTER_NOAPI_NOINIT_NOERR
/*
* Check arguments.
*/
HDassert(iblock);
HDassert(child_addr);
/* Retrieve address of entry */
*child_addr = iblock->ents[entry].addr;
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5HF_man_iblock_entry_addr() */
/*-------------------------------------------------------------------------
* Function: H5HF__man_iblock_delete
*
* Purpose: Delete a managed indirect block
*
* Note: This routine does _not_ modify any indirect block that points
* to this indirect block, it is assumed that the whole heap is
* being deleted in a top-down fashion.
*
* Return: SUCCEED/FAIL
*
* Programmer: Quincey Koziol
* koziol@hdfgroup.org
* Aug 7 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF__man_iblock_delete(H5HF_hdr_t *hdr, haddr_t iblock_addr,
unsigned iblock_nrows, H5HF_indirect_t *par_iblock, unsigned par_entry)
{
H5HF_indirect_t *iblock; /* Pointer to indirect block */
unsigned row, col; /* Current row & column in indirect block */
unsigned entry; /* Current entry in row */
unsigned cache_flags = H5AC__NO_FLAGS_SET; /* Flags for unprotecting indirect block */
hbool_t did_protect; /* Whether we protected the indirect block or not */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/*
* Check arguments.
*/
HDassert(hdr);
HDassert(H5F_addr_defined(iblock_addr));
HDassert(iblock_nrows > 0);
/* Lock indirect block */
if(NULL == (iblock = H5HF__man_iblock_protect(hdr, iblock_addr, iblock_nrows, par_iblock, par_entry, TRUE, H5AC__NO_FLAGS_SET, &did_protect)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to protect fractal heap indirect block")
HDassert(iblock->nchildren > 0);
HDassert(did_protect == TRUE);
/* Iterate over rows in this indirect block */
entry = 0;
for(row = 0; row < iblock->nrows; row++) {
/* Iterate over entries in this row */
for(col = 0; col < hdr->man_dtable.cparam.width; col++, entry++) {
/* Check for child entry at this position */
if(H5F_addr_defined(iblock->ents[entry].addr)) {
/* Are we in a direct or indirect block row */
if(row < hdr->man_dtable.max_direct_rows) {
hsize_t dblock_size; /* Size of direct block on disk */
/* Check for I/O filters on this heap */
if(hdr->filter_len > 0)
dblock_size = iblock->filt_ents[entry].size;
else
dblock_size = hdr->man_dtable.row_block_size[row];
/* Delete child direct block */
if(H5HF__man_dblock_delete(hdr->f, iblock->ents[entry].addr, dblock_size) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to release fractal heap child direct block")
} /* end if */
else {
hsize_t row_block_size; /* The size of blocks in this row */
unsigned child_nrows; /* Number of rows in new indirect block */
/* Get the row's block size */
row_block_size = (hsize_t)hdr->man_dtable.row_block_size[row];
/* Compute # of rows in next child indirect block to use */
child_nrows = H5HF_dtable_size_to_rows(&hdr->man_dtable, row_block_size);
/* Delete child indirect block */
if(H5HF__man_iblock_delete(hdr, iblock->ents[entry].addr, child_nrows, iblock, entry) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to release fractal heap child indirect block")
} /* end else */
} /* end if */
} /* end for */
} /* end row */
#ifndef NDEBUG
{
unsigned iblock_status = 0; /* Indirect block's status in the metadata cache */
/* Check the indirect block's status in the metadata cache */
if(H5AC_get_entry_status(hdr->f, iblock_addr, &iblock_status) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "unable to check metadata cache status for indirect block")
/* Check if indirect block is pinned */
HDassert(!(iblock_status & H5AC_ES__IS_PINNED));
}
#endif /* NDEBUG */
/* Indicate that the indirect block should be deleted */
cache_flags |= H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG;
/* If the indirect block is in real file space, tell
* the cache to free its file space as well.
*/
if (!H5F_IS_TMP_ADDR(hdr->f, iblock_addr))
cache_flags |= H5AC__FREE_FILE_SPACE_FLAG;
done:
/* Unprotect the indirect block, with appropriate flags */
if(iblock && H5HF__man_iblock_unprotect(iblock, cache_flags, did_protect) < 0)
HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap indirect block")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__man_iblock_delete() */
/*-------------------------------------------------------------------------
*
* Function: H5HF__man_iblock_size
*
* Purpose: Gather storage used for the indirect block in fractal heap
*
* Return: non-negative on success, negative on error
*
* Programmer: Vailin Choi
* July 12 2007
*-------------------------------------------------------------------------
*/
herr_t
H5HF__man_iblock_size(H5F_t *f, H5HF_hdr_t *hdr, haddr_t iblock_addr,
unsigned nrows, H5HF_indirect_t *par_iblock, unsigned par_entry, hsize_t *heap_size)
{
H5HF_indirect_t *iblock = NULL; /* Pointer to indirect block */
hbool_t did_protect; /* Whether we protected the indirect block or not */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/*
* Check arguments.
*/
HDassert(f);
HDassert(hdr);
HDassert(H5F_addr_defined(iblock_addr));
HDassert(heap_size);
/* Protect the indirect block */
if(NULL == (iblock = H5HF__man_iblock_protect(hdr, iblock_addr, nrows, par_iblock, par_entry, FALSE, H5AC__READ_ONLY_FLAG, &did_protect)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load fractal heap indirect block")
/* Accumulate size of this indirect block */
*heap_size += iblock->size;
/* Indirect entries in this indirect block */
if(iblock->nrows > hdr->man_dtable.max_direct_rows) {
unsigned first_row_bits; /* Number of bits used bit addresses in first row */
unsigned num_indirect_rows; /* Number of rows of blocks in each indirect block */
unsigned entry; /* Current entry in row */
size_t u; /* Local index variable */
entry = hdr->man_dtable.max_direct_rows * hdr->man_dtable.cparam.width;
first_row_bits = H5VM_log2_of2((uint32_t)hdr->man_dtable.cparam.start_block_size) +
H5VM_log2_of2(hdr->man_dtable.cparam.width);
num_indirect_rows =
(H5VM_log2_gen(hdr->man_dtable.row_block_size[hdr->man_dtable.max_direct_rows]) - first_row_bits) + 1;
for(u = hdr->man_dtable.max_direct_rows; u < iblock->nrows; u++, num_indirect_rows++) {
size_t v; /* Local index variable */
for(v = 0; v < hdr->man_dtable.cparam.width; v++, entry++)
if(H5F_addr_defined(iblock->ents[entry].addr))
if(H5HF__man_iblock_size(f, hdr, iblock->ents[entry].addr, num_indirect_rows, iblock, entry, heap_size) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to get fractal heap storage info for indirect block")
} /* end for */
} /* end if */
done:
/* Release the indirect block */
if(iblock && H5HF__man_iblock_unprotect(iblock, H5AC__NO_FLAGS_SET, did_protect) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap indirect block")
iblock = NULL;
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__man_iblock_size() */
/*-------------------------------------------------------------------------
*
* Function: H5HF_man_iblock_parent_info
*
* Purpose: Determine the parent block's offset and entry location
* (within it's parent) of an indirect block, given its offset
* within the heap.
*
* Return: Non-negative on success / Negative on failure
*
* Programmer: Quincey Koziol
* koziol@lbl.gov
* Jan 14 2018
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF__man_iblock_parent_info(const H5HF_hdr_t *hdr, hsize_t block_off,
hsize_t *ret_par_block_off, unsigned *ret_entry)
{
hsize_t par_block_off; /* Offset of parent within heap */
hsize_t prev_par_block_off; /* Offset of previous parent block within heap */
unsigned row, col; /* Row & column for block */
unsigned prev_row = 0, prev_col = 0;/* Previous row & column for block */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/*
* Check arguments.
*/
HDassert(hdr);
HDassert(block_off > 0);
HDassert(ret_entry);
/* Look up row & column for object */
if(H5HF_dtable_lookup(&hdr->man_dtable, block_off, &row, &col) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTCOMPUTE, FAIL, "can't compute row & column of block")
/* Sanity check - first lookup must be an indirect block */
HDassert(row >= hdr->man_dtable.max_direct_rows);
/* Traverse down, until a direct block at the offset is found, then
* use previous (i.e. parent's) offset, row, and column.
*/
prev_par_block_off = par_block_off = 0;
while(row >= hdr->man_dtable.max_direct_rows) {
/* Retain previous parent block offset */
prev_par_block_off = par_block_off;
/* Compute the new parent indirect block's offset in the heap's address space */
/* (based on previous block offset) */
par_block_off += hdr->man_dtable.row_block_off[row];
par_block_off += hdr->man_dtable.row_block_size[row] * col;
/* Preserve current row & column */
prev_row = row;
prev_col = col;
/* Look up row & column in new indirect block for object */
if(H5HF_dtable_lookup(&hdr->man_dtable, (block_off - par_block_off), &row, &col) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTCOMPUTE, FAIL, "can't compute row & column of block")
} /* end while */
/* Sanity check */
HDassert(row == 0);
HDassert(col == 0);
/* Set return parameters */
*ret_par_block_off = prev_par_block_off;
*ret_entry = (prev_row * hdr->man_dtable.cparam.width) + prev_col;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF__man_iblock_par_info() */
/*-------------------------------------------------------------------------
* Function: H5HF_man_iblock_dest
*
* Purpose: Destroys a fractal heap indirect block in memory.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Mar 6 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF_man_iblock_dest(H5HF_indirect_t *iblock)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
/*
* Check arguments.
*/
HDassert(iblock);
HDassert(iblock->rc == 0);
/* Decrement reference count on shared info */
HDassert(iblock->hdr);
if(H5HF_hdr_decr(iblock->hdr) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't decrement reference count on shared heap header")
if(iblock->parent)
if(H5HF__iblock_decr(iblock->parent) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't decrement reference count on shared indirect block")
/* Release entry tables */
if(iblock->ents)
iblock->ents = H5FL_SEQ_FREE(H5HF_indirect_ent_t, iblock->ents);
if(iblock->filt_ents)
iblock->filt_ents = H5FL_SEQ_FREE(H5HF_indirect_filt_ent_t, iblock->filt_ents);
if(iblock->child_iblocks)
iblock->child_iblocks = H5FL_SEQ_FREE(H5HF_indirect_ptr_t, iblock->child_iblocks);
/* Free fractal heap indirect block info */
iblock = H5FL_FREE(H5HF_indirect_t, iblock);
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_man_iblock_dest() */
|
./openacc-vv/serial_copy.c | #include "acc_testsuite.h"
#ifndef T1
//T1:serial,data,data-region,V:2.6-2.7
int test1(){
int err = 0;
srand(SEED);
real_t * a = (real_t *)malloc(n * sizeof(real_t));
real_t * a_host = (real_t *)malloc(n * sizeof(real_t));
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
a_host[x] = a[x];
}
#pragma acc serial copy(a[0:n])
{
#pragma acc loop
for (int x = 0; x < n; ++x){
a[x] = 2 * a[x];
}
}
for (int x = 0; x < n; ++x){
if (fabs(a[x] - (2 * a_host[x])) > PRECISION){
err = 1;
}
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test1();
}
if (failed != 0){
failcode = failcode + (1 << 0);
}
#endif
return failcode;
}
|
./openacc-vv/acc_async_test.cpp | #include "acc_testsuite.h"
#ifndef T1
//T1:async,runtime,construct-independent,V:2.0-2.7
int test1(){
int err = 0;
real_t *a = new real_t[n];
real_t *b = new real_t[n];
real_t *c = new real_t[n];
real_t *d = new real_t[n];
real_t *e = new real_t[n];
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
b[x] = rand() / (real_t)(RAND_MAX / 10);
c[x] = 0;
d[x] = rand() / (real_t)(RAND_MAX / 10);
e[x] = 0;
}
#pragma acc enter data copyin(a[0:n], b[0:n]) create(c[0:n]) async(1)
#pragma acc enter data copyin(d[0:n]) create(e[0:n]) async(2)
#pragma acc parallel present(a[0:n], b[0:n], c[0:n]) async(1)
{
#pragma acc loop
for (int x = 0; x < n; ++x){
c[x] = a[x] + b[x];
}
}
#pragma acc parallel present(c[0:n], d[0:n], e[0:n]) async(1) wait(2)
{
#pragma acc loop
for (int x = 0; x < n; ++x){
e[x] = c[x] + d[x];
}
}
#pragma acc exit data copyout(e[0:n]) async(1)
while (!acc_async_test(1));
for (int x = 0; x < n; ++x){
if (fabs(e[x] - (a[x] + b[x] + d[x])) > PRECISION){
err += 1;
}
}
return err;
}
#endif
#ifndef T2
//T2:async,runtime,construct-independent,V:1.0-2.7
int test2(){
int err = 0;
real_t *a = new real_t[n];
real_t *b = new real_t[n];
real_t *c = new real_t[n];
real_t *d = new real_t[n];
real_t *e = new real_t[n];
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
b[x] = rand() / (real_t)(RAND_MAX / 10);
c[x] = 0;
d[x] = rand() / (real_t)(RAND_MAX / 10);
e[x] = 0;
}
#pragma acc data copyin(a[0:n], b[0:n], d[0:n]) create(c[0:n]) copyout(e[0:n])
{
#pragma acc parallel present(a[0:n], b[0:n], c[0:n]) async(1)
{
#pragma acc loop
for (int x = 0; x < n; ++x) {
c[x] = a[x] + b[x];
}
}
#pragma acc parallel present(c[0:n], d[0:n], e[0:n]) async(1)
{
#pragma acc loop
for (int x = 0; x < n; ++x) {
e[x] = c[x] + d[x];
}
}
while (!acc_async_test(1));
}
for (int x = 0; x < n; ++x) {
if (fabs(e[x] - (a[x] + b[x] + d[x])) > PRECISION) {
err += 1;
}
}
return err;
}
#endif
#ifndef T3
//T3:async,runtime,construct-independent,V:2.5-2.7
int test3() {
int err = 0;
real_t* a = new real_t[n];
real_t* b = new real_t[n];
real_t* c = new real_t[n];
real_t* d = new real_t[n];
real_t* e = new real_t[n];
int async_val = acc_get_default_async();
for (int x = 0; x < n; ++x) {
a[x] = rand() / (real_t)(RAND_MAX / 10);
b[x] = rand() / (real_t)(RAND_MAX / 10);
c[x] = 0;
d[x] = rand() / (real_t)(RAND_MAX / 10);
e[x] = 0;
}
#pragma acc data copyin(a[0:n], b[0:n], d[0:n]) create(c[0:n]) copyout(e[0:n])
{
#pragma acc parallel present(a[0:n], b[0:n], c[0:n]) async
{
#pragma acc loop
for (int x = 0; x < n; ++x) {
c[x] = a[x] + b[x];
}
}
#pragma acc parallel present(c[0:n], d[0:n], e[0:n]) async
{
#pragma acc loop
for (int x = 0; x < n; ++x) {
e[x] = c[x] + d[x];
}
}
while (!acc_async_test(async_val));
}
for (int x = 0; x < n; ++x) {
if (fabs(e[x] - (a[x] + b[x] + d[x])) > PRECISION) {
err += 1;
}
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test1();
}
if (failed != 0){
failcode = failcode + (1 << 0);
}
#endif
#ifndef T2
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test2();
}
if (failed != 0){
failcode = failcode + (1 << 1);
}
#endif
#ifndef T3
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x) {
failed = failed + test3();
}
if (failed != 0) {
failcode = failcode + (1 << 2);
}
#endif
return failcode;
}
|
./openacc-vv/kernels_loop_vector_blocking.c | #include "acc_testsuite.h"
#ifndef T1
//T1:kernels,loop,V:1.0-2.7
int test1(){
int err = 0;
srand(SEED);
real_t * a = (real_t *)malloc(n * sizeof(real_t));
real_t * b = (real_t *)malloc(n * sizeof(real_t));
real_t * c = (real_t *)malloc(n * sizeof(real_t));
real_t multiplyer = 1;
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
b[x] = rand() / (real_t)(RAND_MAX / 10);
c[x] = 0.0;
}
#pragma acc data copyin(a[0:n], b[0:n]) copyout(c[0:n])
{
#pragma acc kernels
{
#pragma acc loop vector
for (int x = 0; x < n; ++x){
c[x] = (a[x] + b[x]) * multiplyer;
}
multiplyer += 1;
#pragma acc loop vector
for (int x = 0; x < n; ++x){
c[x] += (a[x] + b[x]) * multiplyer;
}
}
}
for (int x = 0; x < n; ++x){
if (fabs(c[x] - 3 * (a[x] + b[x])) > PRECISION){
err + 1;
break;
}
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test1();
}
if (failed != 0){
failcode = failcode + (1 << 0);
}
#endif
return failcode;
}
|
./openacc-vv/atomic_structured_predecrement_assign.c | #include "acc_testsuite.h"
#ifndef T1
//T1:atomic,construct-independent,V:2.0-2.7
int test1(){
int err = 0;
srand(SEED);
real_t *a = (real_t *)malloc(n * sizeof(real_t));
real_t *b = (real_t *)malloc(n * sizeof(real_t));
int *c = (int *)malloc(n * sizeof(int));
int *distribution = (int *)malloc(10 * sizeof(int));
int *distribution_comparison = (int *)malloc(10 * sizeof(int));
bool found = false;
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
b[x] = rand() / (real_t)(RAND_MAX / 10);
}
for (int x = 0; x < 10; ++x){
distribution[x] = 0;
distribution_comparison[x] = 0;
}
#pragma acc data copyin(a[0:n], b[0:n]) copy(distribution[0:10]) copyout(c[0:n])
{
#pragma acc parallel
{
#pragma acc loop
for (int x = 0; x < n; ++x){
#pragma acc atomic capture
{
--distribution[(int) (a[x]*b[x]/10)];
c[x] = distribution[(int) (a[x]*b[x]/10)];
}
}
}
}
for (int x = 0; x < n; ++x){
distribution_comparison[(int) (a[x]*b[x]/10)]--;
}
for (int x = 0; x < 10; ++x){
if (distribution_comparison[x] != distribution[x]){
err += 1;
break;
}
}
for (int x = 0; x < 10; ++x){
for (int y = 0; y > distribution[x]; --y){
for (int z = 0; z < n; ++z){
if (c[z] == y - 1 && x == (int) (a[z] * b[z] / 10)){
found = true;
break;
}
}
if (!found){
err++;
}
found = false;
}
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test1();
}
if (failed != 0){
failcode = failcode + (1 << 0);
}
#endif
return failcode;
}
|
./openacc-vv/atomic_capture_expr_minus_x.c | #include "acc_testsuite.h"
bool is_possible(real_t* a, real_t* b, int length, real_t prev){
if (length == 0){
return true;
}
real_t *passed_a = (real_t *)malloc((length - 1) * sizeof(real_t));
real_t *passed_b = (real_t *)malloc((length - 1) * sizeof(real_t));
for (int x = 0; x < length; ++x){
if (fabs(b[x] - (a[x] - prev)) < PRECISION){
for (int y = 0; y < x; ++y){
passed_a[y] = a[y];
passed_b[y] = b[y];
}
for (int y = x + 1; y < length; ++y){
passed_a[y - 1] = a[y];
passed_b[y - 1] = b[y];
}
if (is_possible(passed_a, passed_b, length - 1, b[x])){
free(passed_a);
free(passed_b);
return true;
}
}
}
free(passed_a);
free(passed_b);
return false;
}
bool possible_result(real_t * remaining_combinations, int length, real_t current_value, real_t test_value){
if (length == 0){
if (fabs(current_value - test_value) > PRECISION){
return true;
}
else {
return false;
}
}
real_t * passed = (real_t *)malloc((length - 1) * sizeof(real_t));
for (int x = 0; x < length; ++x){
for (int y = 0; y < x; ++y){
passed[y] = remaining_combinations[y];
}
for (int y = x + 1; y < length; ++y){
passed[y - 1] = remaining_combinations[y];
}
if (possible_result(passed, length - 1, remaining_combinations[x] - current_value, test_value)){
free(passed);
return true;
}
}
free(passed);
return false;
}
#ifndef T1
//T1:atomic,construct-independent,V:2.0-2.7
int test1(){
int err = 0;
srand(SEED);
real_t *a = (real_t *)malloc(n * sizeof(real_t));
real_t *b = (real_t *)malloc(n * sizeof(real_t));
real_t *totals = (real_t *)malloc(((n/10) + 1) * sizeof(real_t));
int indexer = 0;
real_t * passed = (real_t *)malloc(10 * sizeof(real_t));
real_t *passed_a = (real_t *)malloc(10 * sizeof(real_t));
real_t *passed_b = (real_t *)malloc(10 * sizeof(real_t));
int passed_indexer;
int absolute_indexer;
for (int x = 0; x < n; ++x){
a[x] = rand() / (real_t)(RAND_MAX / 10);
}
for (int x = 0; x < (n/10) + 1; ++x){
totals[x] = 0;
}
#pragma acc data copyin(a[0:n]) copy(totals[0:(n/10) + 1]) copyout(b[0:n])
{
#pragma acc parallel
{
#pragma acc loop
for (int x = 0; x < n; ++x){
#pragma acc atomic capture
b[x] = totals[x%((int) (n/10) + 1)] = a[x] - totals[x%((int) (n/10) + 1)];
}
}
}
for (int x = 0; x < (n/10) + 1; ++x){
indexer = x;
while (indexer < n){
passed[indexer/((int) (n/10) + 1)] = a[indexer];
indexer += (n/10) + 1;
}
if (!(possible_result(passed, 10, 0, totals[x]))){
err += 1;
}
}
for (int x = 0; x < n/10 + 1; ++x){
for (passed_indexer = 0, absolute_indexer = x; absolute_indexer < n; passed_indexer++, absolute_indexer += n/10 + 1){
passed_a[passed_indexer] = a[absolute_indexer];
passed_b[passed_indexer] = b[absolute_indexer];
}
if (!is_possible(passed_a, passed_b, passed_indexer, 0)){
err += 1;
}
break;
}
return err;
}
#endif
int main(){
int failcode = 0;
int failed;
#ifndef T1
failed = 0;
for (int x = 0; x < NUM_TEST_CALLS; ++x){
failed = failed + test1();
}
if (failed != 0){
failcode = failcode + (1 << 0);
}
#endif
return failcode;
}
|
./SPECaccel/benchspec/ACCEL/351.palm/src/cpu_statistics.F90 | SUBROUTINE cpu_statistics
!--------------------------------------------------------------------------------!
! This file is part of PALM.
!
! PALM is free software: you can redistribute it and/or modify it under the terms
! of the GNU General Public License as published by the Free Software Foundation,
! either version 3 of the License, or (at your option) any later version.
!
! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
! A PARTICULAR PURPOSE. See the GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License along with
! PALM. If not, see <http://www.gnu.org/licenses/>.
!
! Copyright 1997-2012 Leibniz University Hannover
!--------------------------------------------------------------------------------!
!
! Current revisions:
! -----------------
!
!
! Former revisions:
! -----------------
! $Id: cpu_statistics.f90 1112 2013-03-09 00:34:37Z raasch $
!
! 1111 2013-03-08 23:54:10Z raasch
! output of grid point numbers and average CPU time per grid point and timestep
!
! 1092 2013-02-02 11:24:22Z raasch
! unused variables removed
!
! 1036 2012-10-22 13:43:42Z raasch
! code put under GPL (PALM 3.9)
!
! 1015 2012-09-27 09:23:24Z raasch
! output of accelerator board information
!
! 683 2011-02-09 14:25:15Z raasch
! output of handling of ghostpoint exchange
!
! 622 2010-12-10 08:08:13Z raasch
! output of handling of collective operations
!
! 222 2009-01-12 16:04:16Z letzel
! Bugfix for nonparallel execution
!
! 197 2008-09-16 15:29:03Z raasch
! Format adjustments in order to allow CPU# > 999,
! data are collected from PE0 in an ordered sequence which seems to avoid
! hanging of processes on SGI-ICE
!
! 82 2007-04-16 15:40:52Z raasch
! Preprocessor directives for old systems removed
!
! RCS Log replace by Id keyword, revision history cleaned up
!
! Revision 1.13 2006/04/26 12:10:51 raasch
! Output of number of threads per task, max = min in case of 1 PE
!
! Revision 1.1 1997/07/24 11:11:11 raasch
! Initial revision
!
!
! Description:
! ------------
! Analysis and output of the cpu-times measured. All PE results are collected
! on PE0 in order to calculate the mean cpu-time over all PEs and other
! statistics. The output is sorted according to the amount of cpu-time consumed
! and output on PE0.
!------------------------------------------------------------------------------!
USE control_parameters
USE cpulog
USE indices, ONLY: nx, ny, nz
USE pegrid
IMPLICIT NONE
INTEGER :: i, ii(1), iii, sender
REAL :: average_cputime
REAL, SAVE :: norm = 1.0
REAL, DIMENSION(:), ALLOCATABLE :: pe_max, pe_min, pe_rms, sum
REAL, DIMENSION(:,:), ALLOCATABLE :: pe_log_points
!
!-- Compute cpu-times in seconds
log_point%mtime = log_point%mtime / norm
log_point%sum = log_point%sum / norm
log_point%vector = log_point%vector / norm
WHERE ( log_point%counts /= 0 )
log_point%mean = log_point%sum / log_point%counts
END WHERE
!
!-- Collect cpu-times from all PEs and calculate statistics
IF ( myid == 0 ) THEN
!
!-- Allocate and initialize temporary arrays needed for statistics
ALLOCATE( pe_max( SIZE( log_point ) ), pe_min( SIZE( log_point ) ), &
pe_rms( SIZE( log_point ) ), &
pe_log_points( SIZE( log_point ), 0:numprocs-1 ) )
pe_min = log_point%sum
pe_max = log_point%sum ! need to be set in case of 1 PE
pe_rms = 0.0
#if defined( __parallel )
!
!-- Receive data from all PEs
DO i = 1, numprocs-1
CALL MPI_RECV( pe_max(1), SIZE( log_point ), MPI_REAL, &
i, i, comm2d, status, ierr )
sender = status(MPI_SOURCE)
pe_log_points(:,sender) = pe_max
ENDDO
pe_log_points(:,0) = log_point%sum ! Results from PE0
!
!-- Calculate mean of all PEs, store it on log_point%sum
!-- and find minimum and maximum
DO iii = 1, SIZE( log_point )
DO i = 1, numprocs-1
log_point(iii)%sum = log_point(iii)%sum + pe_log_points(iii,i)
pe_min(iii) = MIN( pe_min(iii), pe_log_points(iii,i) )
pe_max(iii) = MAX( pe_max(iii), pe_log_points(iii,i) )
ENDDO
log_point(iii)%sum = log_point(iii)%sum / numprocs
!
!-- Calculate rms
DO i = 0, numprocs-1
pe_rms(iii) = pe_rms(iii) + ( &
pe_log_points(iii,i) - log_point(iii)%sum &
)**2
ENDDO
pe_rms(iii) = SQRT( pe_rms(iii) / numprocs )
ENDDO
ELSE
!
!-- Send data to PE0 (pe_max is used as temporary storage to send
!-- the data in order to avoid sending the data type log)
ALLOCATE( pe_max( SIZE( log_point ) ) )
pe_max = log_point%sum
CALL MPI_SEND( pe_max(1), SIZE( log_point ), MPI_REAL, 0, myid, comm2d, &
ierr )
#endif
ENDIF
!
!-- Write cpu-times
IF ( myid == 0 ) THEN
!
!-- Re-store sums
ALLOCATE( sum( SIZE( log_point ) ) )
WHERE ( log_point%counts /= 0 )
sum = log_point%sum
ELSEWHERE
sum = -1.0
ENDWHERE
!
!-- Get total time in order to calculate CPU-time per gridpoint and timestep
IF ( nr_timesteps_this_run /= 0 ) THEN
average_cputime = log_point(1)%sum / REAL( (nx+1) * (ny+1) * nz ) / &
REAL( nr_timesteps_this_run ) * 1E6 ! in micro-sec
ELSE
average_cputime = -1.0
ENDIF
!
!-- Write cpu-times sorted by size
CALL check_open( 18 )
#if defined( __parallel )
WRITE ( 18, 100 ) TRIM( run_description_header ), &
numprocs * threads_per_task, pdims(1), pdims(2), &
threads_per_task, nx+1, ny+1, nz, nr_timesteps_this_run, &
average_cputime
IF ( num_acc_per_node /= 0 ) WRITE ( 18, 108 ) num_acc_per_node
WRITE ( 18, 110 )
#else
WRITE ( 18, 100 ) TRIM( run_description_header ), &
numprocs * threads_per_task, 1, 1, &
threads_per_task, nx+1, ny+1, nz, nr_timesteps_this_run, &
average_cputime
IF ( num_acc_per_node /= 0 ) WRITE ( 18, 109 ) num_acc_per_node
WRITE ( 18, 110 )
#endif
DO
ii = MAXLOC( sum )
i = ii(1)
IF ( sum(i) /= -1.0 ) THEN
WRITE ( 18, 102 ) &
log_point(i)%place, log_point(i)%sum, &
log_point(i)%sum / log_point(1)%sum * 100.0, &
log_point(i)%counts, pe_min(i), pe_max(i), pe_rms(i)
sum(i) = -1.0
ELSE
EXIT
ENDIF
ENDDO
ENDIF
!
!-- The same procedure again for the individual measurements.
!
!-- Compute cpu-times in seconds
log_point_s%mtime = log_point_s%mtime / norm
log_point_s%sum = log_point_s%sum / norm
log_point_s%vector = log_point_s%vector / norm
WHERE ( log_point_s%counts /= 0 )
log_point_s%mean = log_point_s%sum / log_point_s%counts
END WHERE
!
!-- Collect cpu-times from all PEs and calculate statistics
#if defined( __parallel )
!
!-- Set barrier in order to avoid that PE0 receives log_point_s-data
!-- while still busy with receiving log_point-data (see above)
CALL MPI_BARRIER( comm2d, ierr )
#endif
IF ( myid == 0 ) THEN
!
!-- Initialize temporary arrays needed for statistics
pe_min = log_point_s%sum
pe_max = log_point_s%sum ! need to be set in case of 1 PE
pe_rms = 0.0
#if defined( __parallel )
!
!-- Receive data from all PEs
DO i = 1, numprocs-1
CALL MPI_RECV( pe_max(1), SIZE( log_point ), MPI_REAL, &
MPI_ANY_SOURCE, MPI_ANY_TAG, comm2d, status, ierr )
sender = status(MPI_SOURCE)
pe_log_points(:,sender) = pe_max
ENDDO
pe_log_points(:,0) = log_point_s%sum ! Results from PE0
!
!-- Calculate mean of all PEs, store it on log_point_s%sum
!-- and find minimum and maximum
DO iii = 1, SIZE( log_point )
DO i = 1, numprocs-1
log_point_s(iii)%sum = log_point_s(iii)%sum + pe_log_points(iii,i)
pe_min(iii) = MIN( pe_min(iii), pe_log_points(iii,i) )
pe_max(iii) = MAX( pe_max(iii), pe_log_points(iii,i) )
ENDDO
log_point_s(iii)%sum = log_point_s(iii)%sum / numprocs
!
!-- Calculate rms
DO i = 0, numprocs-1
pe_rms(iii) = pe_rms(iii) + ( &
pe_log_points(iii,i) - log_point_s(iii)%sum &
)**2
ENDDO
pe_rms(iii) = SQRT( pe_rms(iii) / numprocs )
ENDDO
ELSE
!
!-- Send data to PE0 (pe_max is used as temporary storage to send
!-- the data in order to avoid sending the data type log)
pe_max = log_point_s%sum
CALL MPI_SEND( pe_max(1), SIZE( log_point ), MPI_REAL, 0, 0, comm2d, &
ierr )
#endif
ENDIF
!
!-- Write cpu-times
IF ( myid == 0 ) THEN
!
!-- Re-store sums
WHERE ( log_point_s%counts /= 0 )
sum = log_point_s%sum
ELSEWHERE
sum = -1.0
ENDWHERE
!
!-- Write cpu-times sorted by size
WRITE ( 18, 101 )
DO
ii = MAXLOC( sum )
i = ii(1)
IF ( sum(i) /= -1.0 ) THEN
WRITE ( 18, 102 ) &
log_point_s(i)%place, log_point_s(i)%sum, &
log_point_s(i)%sum / log_point(1)%sum * 100.0, &
log_point_s(i)%counts, pe_min(i), pe_max(i), pe_rms(i)
sum(i) = -1.0
ELSE
EXIT
ENDIF
ENDDO
!
!-- Output of handling of MPI operations
IF ( collective_wait ) THEN
WRITE ( 18, 103 )
ELSE
WRITE ( 18, 104 )
ENDIF
IF ( synchronous_exchange ) THEN
WRITE ( 18, 105 )
ELSE
WRITE ( 18, 106 )
ENDIF
!
!-- Empty lines in order to create a gap to the results of the model
!-- continuation runs
WRITE ( 18, 107 )
!
!-- Unit 18 is not needed anymore
CALL close_file( 18 )
ENDIF
100 FORMAT (A/11('-')//'CPU measures for ',I5,' PEs (',I5,'(x) * ',I5,'(y', &
&') tasks *',I5,' threads):'// &
'gridpoints (x/y/z): ',20X,I5,' * ',I5,' * ',I5/ &
'nr of timesteps: ',22X,I6/ &
'cpu time per grid point and timestep: ',5X,F8.5,' * 10**-6 s')
101 FORMAT (/'special measures:'/ &
&'-----------------------------------------------------------', &
&'--------------------')
102 FORMAT (A20,2X,F9.3,2X,F7.2,1X,I7,3(1X,F9.3))
103 FORMAT (/'Barriers are set in front of collective operations')
104 FORMAT (/'No barriers are set in front of collective operations')
105 FORMAT (/'Exchange of ghostpoints via MPI_SENDRCV')
106 FORMAT (/'Exchange of ghostpoints via MPI_ISEND/MPI_IRECV')
107 FORMAT (//)
108 FORMAT ('Accelerator boards per node: ',14X,I2)
109 FORMAT ('Accelerator boards: ',23X,I2)
110 FORMAT ('----------------------------------------------------------', &
&'------------'//&
&'place: mean counts min ', &
&' max rms'/ &
&' sec. % sec. ', &
&' sec. sec.'/ &
&'-----------------------------------------------------------', &
&'-------------------')
END SUBROUTINE cpu_statistics
|
./openacc-vv/set_device_type_num_nvidia.F90 | #ifndef T1
!T1:runtime,construct-independent,internal-control-values,set,nonvalidating,V:2.5-2.7
LOGICAL FUNCTION test1()
USE OPENACC
IMPLICIT NONE
INCLUDE "acc_testsuite.Fh"
INTEGER :: device_num
INTEGER :: device_type
INTEGER :: errors = 0
device_type = acc_get_device_type()
device_num = acc_get_device_num(device_type)
!$acc set device_type(nvidia) device_num(device_num)
IF (errors .eq. 0) THEN
test1 = .FALSE.
ELSE
test1 = .TRUE.
END IF
END
#endif
PROGRAM main
IMPLICIT NONE
INTEGER :: failcode, testrun
LOGICAL :: failed
INCLUDE "acc_testsuite.Fh"
#ifndef T1
LOGICAL :: test1
#endif
failed = .FALSE.
failcode = 0
#ifndef T1
DO testrun = 1, NUM_TEST_CALLS
failed = failed .or. test1()
END DO
IF (failed) THEN
failcode = failcode + 2 ** 0
failed = .FALSE.
END IF
#endif
CALL EXIT (failcode)
END PROGRAM
|
End of preview. Expand
in Data Studio
- Downloads last month
- 6