static void nss_setpwent(void) { NSS_STATUS (*_nss_setpwent)(void) = find_fn("setpwent"); NSS_STATUS status; status = _nss_setpwent(); if (status != NSS_STATUS_SUCCESS) { report_nss_error("setpwent", status); } }
static void nss_endgrent(void) { NSS_STATUS (*_nss_endgrent)(void) = find_fn("endgrent"); NSS_STATUS status; if (!_nss_endgrent) return; status = _nss_endgrent(); if (status != NSS_STATUS_SUCCESS) { report_nss_error("endgrent", status); } }
static int nss_initgroups(char *user, gid_t group, gid_t **groups, long int *start, long int *size) { NSS_STATUS (*_nss_initgroups)(char *, gid_t , long int *, long int *, gid_t **, long int , int *) = find_fn("initgroups_dyn"); NSS_STATUS status; if (!_nss_initgroups) return NSS_STATUS_UNAVAIL; status = _nss_initgroups(user, group, start, size, groups, 0, &nss_errno); if (status != NSS_STATUS_SUCCESS) { report_nss_error("initgroups", status); } return status; }
static struct passwd *nss_getpwnam(const char *name) { NSS_STATUS (*_nss_getpwnam_r)(const char *, struct passwd *, char *, size_t , int *) = find_fn("getpwnam_r"); static struct passwd pwd; static char buf[1000]; NSS_STATUS status; status = _nss_getpwnam_r(name, &pwd, buf, sizeof(buf), &nss_errno); if (status == NSS_STATUS_NOTFOUND) { return NULL; } if (status != NSS_STATUS_SUCCESS) { report_nss_error("getpwnam", status); return NULL; } return &pwd; }
static void* singleListFind(const void*_self, Find_FN find_fn, va_list *params) { const _SingleList *self = _self; Node **p = &self->head->next; void *node = NULL; for (; (*p) != NULL; p = &(*p)->next) { va_list args; va_copy(args, *params); node = find_fn((*p)->data, &args); va_end(args); if (node != NULL) { return node; } } return NULL; }
static struct passwd *nss_getpwent(void) { NSS_STATUS (*_nss_getpwent_r)(struct passwd *, char *, size_t , int *) = find_fn("getpwent_r"); static struct passwd pwd; static char buf[1000]; NSS_STATUS status; if (!_nss_getpwent_r) return NULL; status = _nss_getpwent_r(&pwd, buf, sizeof(buf), &nss_errno); if (status == NSS_STATUS_NOTFOUND) { return NULL; } if (status != NSS_STATUS_SUCCESS) { report_nss_error("getpwent", status); return NULL; } return &pwd; }
static const char *_find_config_str(const void *start, node_lookup_fn find_fn, const char *path, const char *fail, int allow_empty) { const struct dm_config_node *n = find_fn(start, path); /* Empty strings are ignored if allow_empty is set */ if (n && n->v) { if ((n->v->type == DM_CFG_STRING) && (allow_empty || (*n->v->v.str))) { log_very_verbose("Setting %s to %s", path, n->v->v.str); return n->v->v.str; } if ((n->v->type != DM_CFG_STRING) || (!allow_empty && fail)) log_warn("WARNING: Ignoring unsupported value for %s.", path); } if (fail) log_very_verbose("%s not found in config: defaulting to %s", path, fail); return fail; }
void find_n_half(double maxbw, int num_pairs, char *s_buf, char *r_buf, int myid) { double bw = 0.0, error; int size = 1, lastsize = 0, top=0, bottom=0, tmp; error = (maxbw / 100) * N_HALF_ERROR_BOUND; if (myid == 0) { fprintf(stdout, "Searching for N/2 bandwidth. Maximum "); fprintf(stdout, "Bandwidth of %f MB/s", maxbw); fprintf(stdout, "...\n"); fflush(stdout); } while ( (size != lastsize) && (size <= MAX_MSG_SIZE) && (bw < (maxbw / 2 - error) || bw > (maxbw / 2 + error))) { bw = find_fn (size, num_pairs, s_buf, r_buf); if (myid == 0) { if (bw < (maxbw / 2 - error)) { tmp = size; if (lastsize > size || top) /*We have a top! */ { if (lastsize > size) { top = lastsize; } size = size + (top - size) / 2; } else /*Still searching for a top */ { size = size << 1 ; } lastsize = tmp; } if( bw > (maxbw / 2 + error)) { tmp = size; if (lastsize < size) { bottom = lastsize; } size = size - (size - bottom) / 2; lastsize = tmp; } } MPI_Bcast (&size, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast (&lastsize, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast (&bw, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); } if (myid == 0) { if (size > MAX_MSG_SIZE) { fprintf (stdout, "Unable to find N/2 bandwidth in sizes"); fprintf (stdout, " from 0 to %d bytes\n", MAX_MSG_SIZE); } else { fprintf (stdout, "Found N/2 bandwidth of %f MB/s at size",bw); fprintf (stdout, " %i bytes\n", size); } } MPI_Barrier (MPI_COMM_WORLD); return; }
int main(int argc, char *argv[]) { int myid, num_procs, num_pairs=0, i; int size, align_size, org_method = AUTOMATIC; char *s_buf, *r_buf; double maxbw=0.0, bw=0.0; MPI_Init(&argc, &argv); for (i = 0; i < MAX_PROCS; i++) { /*initialize to -1 because it is outside the legal range for ranks*/ pair_list[i].sender = -1; pair_list[i].receiver = -1; } MPI_Comm_size (MPI_COMM_WORLD, &num_procs); MPI_Comm_rank (MPI_COMM_WORLD, &myid); while ( (i = getopt(argc, argv, "-bhm:")) != -1) { switch(i) { case 'b': find_fn = find_bibw; break; case 'h': if (myid == 0) { usage(); MPI_Abort(MPI_COMM_WORLD, 0); } break; case 'm': org_method = MANUAL; num_pairs = (int)strtoul(optarg, NULL, 0); if ((num_pairs < 1)) { if (myid == 0) { fprintf(stderr, "procs/node must be >= 1\n"); usage(); } MPI_Abort(MPI_COMM_WORLD, 1); } break; default: if ((!optopt) && (!num_pairs) && (strtoul(optarg,NULL,0))) { num_pairs = (int) strtoul(optarg, NULL, 0); } else { if (myid == 0) { usage(); MPI_Abort(MPI_COMM_WORLD, 1); } } } } if(org_method == AUTOMATIC) { num_pairs = set_pair_list(num_pairs); } else { /*do the simple way */ for (i = 0; i < num_pairs; i++) { pair_list[i].sender = i; pair_list[i + num_pairs].sender = i; pair_list[i].receiver = i + num_pairs; pair_list[i + num_pairs].receiver = i + num_pairs; } for (i = num_pairs*2; i < num_procs; i++) { pair_list[i].sender = -1; pair_list[i].receiver = -1; } } align_size = getpagesize(); s_buf = (char *) (((unsigned long) s_buf1 + (align_size - 1)) / align_size * align_size); r_buf = (char *) (((unsigned long) r_buf1 + (align_size - 1)) / align_size * align_size); if (myid == 0) { fprintf(stdout, "# PathScale Modified OSU MPI Bandwidth Test\n"); fprintf(stdout, "(OSU Version 2.2, PathScale $Revision: 1.4 $)\n"); fprintf(stdout, "# Running on %d procs per node" " (%s traffic for each process pair)\n", num_pairs, (find_fn == find_bw) ? "uni-directional" : "bi-directional"); fprintf(stdout, "# Size\t\tAggregate Bandwidth (MB/s)\tMessages/s \n"); } MPI_Barrier (MPI_COMM_WORLD); MPI_Comm_split(MPI_COMM_WORLD, pair_list[myid].sender == myid, myid, &mpi_comm_sender); /* Loop over bandwidth test */ for (size = 1; size <= MAX_MSG_SIZE; size *= 2) { /*Pulled out message test code into function find_bw/find_bibw*/ bw=find_fn(size, num_pairs, s_buf, r_buf); if (myid == 0) { double rate; rate = 1000*1000*bw/size; fprintf(stdout, "%d\t\t%f\t\t\t%f\n", size, bw, rate); fflush(stdout); if(bw>maxbw) /*keep track of maximum bandwidth for N/2*/ { maxbw=bw; } } } MPI_Bcast(&maxbw,1,MPI_DOUBLE,0,MPI_COMM_WORLD); find_n_half(maxbw, num_pairs, s_buf, r_buf, myid); MPI_Finalize(); return 0; }
static const struct dm_config_node *_find_config_node(const void *start, const char *path) { struct dm_config_node dummy = { .child = (void *) start }; return _find_or_make_node(NULL, &dummy, path); } static const struct dm_config_node *_find_first_config_node(const void *start, const char *path) { const struct dm_config_tree *cft = start; const struct dm_config_node *cn = NULL; while (cft) { if ((cn = _find_config_node(cft->root, path))) return cn; cft = cft->cascade; } return NULL; } static const char *_find_config_str(const void *start, node_lookup_fn find_fn, const char *path, const char *fail, int allow_empty) { const struct dm_config_node *n = find_fn(start, path); /* Empty strings are ignored if allow_empty is set */ if (n && n->v) { if ((n->v->type == DM_CFG_STRING) && (allow_empty || (*n->v->v.str))) { log_very_verbose("Setting %s to %s", path, n->v->v.str); return n->v->v.str; } if ((n->v->type != DM_CFG_STRING) || (!allow_empty && fail)) log_warn("WARNING: Ignoring unsupported value for %s.", path); } if (fail) log_very_verbose("%s not found in config: defaulting to %s", path, fail); return fail; } const char *dm_config_find_str(const struct dm_config_node *cn, const char *path, const char *fail) { return _find_config_str(cn, _find_config_node, path, fail, 0); } const char *dm_config_find_str_allow_empty(const struct dm_config_node *cn, const char *path, const char *fail) { return _find_config_str(cn, _find_config_node, path, fail, 1); } static int64_t _find_config_int64(const void *start, node_lookup_fn find, const char *path, int64_t fail) { const struct dm_config_node *n = find(start, path); if (n && n->v && n->v->type == DM_CFG_INT) { log_very_verbose("Setting %s to %" PRId64, path, n->v->v.i); return n->v->v.i; } log_very_verbose("%s not found in config: defaulting to %" PRId64, path, fail); return fail; } static float _find_config_float(const void *start, node_lookup_fn find, const char *path, float fail) { const struct dm_config_node *n = find(start, path); if (n && n->v && n->v->type == DM_CFG_FLOAT) { log_very_verbose("Setting %s to %f", path, n->v->v.f); return n->v->v.f; } log_very_verbose("%s not found in config: defaulting to %f", path, fail); return fail; } static int _str_in_array(const char *str, const char * const values[]) { int i; for (i = 0; values[i]; i++) if (!strcasecmp(str, values[i])) return 1; return 0; }