static double norm2(size_t n, const realnum *x) { // note: we don't just do sqrt(dot(n, x, x)) in order to avoid overflow size_t i; double xmax = 0, scale; long double sum = 0; for (i = 0; i < n; ++i) { double xabs = fabs(x[i]); if (xabs > xmax) xmax = xabs; } xmax = max_to_all(xmax); if (xmax == 0) return 0; scale = 1.0 / xmax; for (i = 0; i < n; ++i) { double xs = scale * x[i]; sum += xs * xs; } return xmax * sqrt(sum_to_all(sum)); }
int main(int argc, char* argv[]) { int c, i, mype, num_pes, tests, passed; char *pgm; shmem_init(); mype = shmem_my_pe(); num_pes = shmem_n_pes(); if ((pgm=strrchr(argv[0],'/'))) pgm++; else pgm = argv[0]; while((c=getopt(argc,argv,"ampsSoxhv")) != -1) { switch(c) { case 'a': And++; // do not run and_to_all break; case 'm': Min++; // do not run min_to_all break; case 'o': Or++; // do not run or_to_all break; case 'p': Prod++; // do not run prod_to_all break; case 's': Sum++; // do not run sum_to_all break; case 'x': Xor++; // do not run xor_to_all break; case 'S': Serialize++; break; case 'v': Verbose++; break; case 'h': default: Rfprintf(stderr,"usage: %s {-v(verbose)|h(help)}\n",pgm); shmem_finalize(); return 1; } } for (i = 0; i < SHMEM_REDUCE_SYNC_SIZE; i++) { pSync[i] = SHMEM_SYNC_VALUE; pSync1[i] = SHMEM_SYNC_VALUE; } tests = passed = 0; shmem_barrier_all(); passed += max_to_all(mype, num_pes); tests++; if (!Min) { passed += min_to_all(mype, num_pes); tests++; } if (!Sum) { passed += sum_to_all(mype, num_pes); tests++; } if (!And) { passed += and_to_all(mype, num_pes); tests++; } if (!Prod) { passed += prod_to_all(mype, num_pes); tests++; } if (!Or) { passed += or_to_all(mype, num_pes); tests++; } if (!Xor) { passed += xor_to_all(mype, num_pes); tests++; } c = 0; if (mype == 0) { if ((Verbose || tests != passed)) fprintf(stderr,"to_all[%d] %d of %d tests passed\n", mype,passed,tests); c = (tests == passed ? 0 : 1); } shmem_finalize(); return c; }