void do_bcast (TYPE *dst, TYPE *src, int64 nwrds, brand_t *br, int64 msize, int64 rep, int64 fix_root) { timer t; int64 i, n, root, max; uint64 x, cksum; uint64 *ldst, *lsrc; do_sync_init(); // set pointers to local data #if defined(__UPC__) ldst = (uint64 *)&dst[MY_GTHREAD]; lsrc = (uint64 *)&src[MY_GTHREAD]; #else ldst = &dst[0]; lsrc = &src[0]; #endif // touch all memory bzero ((void *)&ldst[0], nwrds * sizeof(uint64)); bzero ((void *)&lsrc[0], nwrds * sizeof(uint64)); // doing reps of powers-of-2 wrds up to max max = msize / sizeof(uint64); for (n = 1; n < (2 * max); n *= 2) { if (n > max) n = max; // fill src buff w/ data for (i = 1; i < n; i++) { x = brand(br) ^ val; lsrc[i] = x; } // Start Timing timer_clear (&t); timer_start (&t); for (i = 0; i < rep; i++) { // used fixed root if specified root = fix_root; if (root < 0) root = brand(br) % GTHREADS; lsrc[0] = brand(br) ^ val; // broadcast n wrds from root to all PEs mpp_broadcast (dst, src, n, root); } mpp_barrier_all(); timer_stop (&t); // // verify checksum on last iter // // compute global checksum x = 0; for (i = 0; i < n; i++) x += ldst[i]; cksum = mpp_accum_long (x); // compare to local (should be x*GTHREADS) if ((GTHREADS * x) != cksum) { printf ("ERROR: expected bcast cksum %016lx (got %016lx)\n", GTHREADS * x, cksum); mpp_exit(1); } mpp_barrier_all(); if (MY_GTHREAD == 0) { //printf ("root %ld cksum is %016lx\n", root, cksum); print_results (n, rep, t.accum_wall); } } if (MY_GTHREAD == 0) printf ("cksum is %016lx\n", cksum); }
int main(int argc, char *argv[]) { char *devpath = NULL; struct astribank_device *astribank; struct eeprom_table eeprom_table; struct capabilities caps; struct capkey key; const char options[] = "vd:D:wf:"; int do_write = 0; FILE *file; char *filename = NULL; int ret; progname = argv[0]; while (1) { int c; c = getopt (argc, argv, options); if (c == -1) break; switch (c) { case 'D': devpath = optarg; break; case 'v': verbose++; break; case 'd': debug_mask = strtoul(optarg, NULL, 0); break; case 'w': do_write = 1; break; case 'f': filename = optarg; break; case 'h': default: ERR("Unknown option '%c'\n", c); usage(); } } if(!devpath) { ERR("Missing device path\n"); usage(); } DBG("Startup %s\n", devpath); if((astribank = mpp_init(devpath)) == NULL) { ERR("Failed initializing MPP\n"); return 1; } if(astribank->eeprom_type != EEPROM_TYPE_LARGE) { ERR("Cannot use this program with astribank EEPROM type %d (need %d)\n", astribank->eeprom_type, EEPROM_TYPE_LARGE); return 1; } ret = mpp_caps_get(astribank, &eeprom_table, &caps, &key); if(ret < 0) { ERR("Failed to get original capabilities: %d\n", ret); return 1; } if (do_write) { /* update capabilities based on input file */ file = stdin; if (filename) { file = fopen(filename, "r"); if (file == NULL) { ERR("Can't open file '%s'\n", filename); return 1; } } ret = read_from_file(&eeprom_table, &caps, &key, file); if (ret < 0) { ERR("Failed to read capabilities from file: %d\n", ret); return 1; } show_capabilities(&caps, stderr); if (capabilities_burn(astribank, &eeprom_table, &caps, &key) < 0) return 1; if (file != stdin) fclose(file); } else { /* print capabilities to stdout */ file = stdout; if (filename) { file = fopen(filename, "w"); if (file == NULL) { ERR("Can't create file '%s'\n", filename); return 1; } } ret = write_to_file(&eeprom_table, &caps, &key, file); if (ret < 0) { ERR("Failed to write capabilities to file: %d\n", ret); return 1; } if (file != stdout) fclose(file); } mpp_exit(astribank); return 0; }