void list_cvars() { int num,err,i,numvars; char *name, *desc; int bind,verbos,scope; MPI_Datatype dt; MPI_T_enum et; int maxnamelen=strlen("Variable"); int maxdesclen=0; int prtlen; int namelen,desclen; int v_int; unsigned int v_uint; unsigned long v_ulong; unsigned long long v_ullong; MPI_Count v_count; char v_char[4097]; double v_double; char value[257]; int value_sup; MPI_T_cvar_handle handle=MPI_T_CVAR_HANDLE_NULL; int count; /* Get number of variables */ err=MPI_T_cvar_get_num(&num); CHECKERR("CVARNUM",err); printf("Found %i control variables\n",num); /* Find string sizes */ numvars=0; for (i=0; i<num; i++) { int namelen=0; int desclen=0; char fname[5]; char fdesc[5]; err=MPI_T_cvar_get_info(i,fname,&namelen,&verbos,&dt,&et,fdesc,&desclen,&bind,&scope); if (namelen>maxnamelen) maxnamelen=namelen; if (desclen>maxdesclen) maxdesclen=desclen; if (verbos<=verbosity) numvars++; } printf("Found %i control variables with verbosity <= ",numvars); print_verbosity_short(verbosity); printf("\n\n"); /* Allocate string buffers */ name=(char*)malloc(sizeof(char)*maxnamelen); CHECKERR("Malloc Name",name==NULL); desc=(char*)malloc(sizeof(char)*maxdesclen); CHECKERR("Malloc Desc",desc==NULL); /* Print header */ prtlen=0; if (!longlist) { print_filled("Variable",maxnamelen,' '); printf(" "); prtlen=maxnamelen+1; printf("VRB "); printf(" "); prtlen+=5+1; printf("Type "); printf(" "); prtlen+=6+1; printf("Bind "); printf(" "); prtlen+=8+1; printf("Scope "); printf(" "); prtlen+=8+1; printf("Value"); printf("\n"); prtlen+=12; print_filled("",prtlen,'-');printf("\n"); } /* Loop and print */ for (i=0; i<num; i++) { namelen=maxnamelen; desclen=maxdesclen; err=MPI_T_cvar_get_info(i,name,&namelen,&verbos,&dt,&et,desc,&desclen,&bind,&scope); if (MPI_T_ERR_INVALID_INDEX == err) continue; CHECKERR("CVARINFO",err); value_sup=1; if (bind==MPI_T_BIND_NO_OBJECT) { err=MPI_T_cvar_handle_alloc(i,NULL,&handle,&count); CHECKERR("CVAR-ALLOC",err); } else if (bind==MPI_T_BIND_MPI_COMM) { MPI_Comm comm=MPI_COMM_WORLD; err=MPI_T_cvar_handle_alloc(i,&comm,&handle,&count); CHECKERR("CVAR-ALLOC",err); } else { value_sup=0; sprintf(value,"unsupported"); } if (value_sup) { if (count==1 || dt==MPI_CHAR) { if (dt==MPI_INT) { err=MPI_T_cvar_read(handle,&v_int); CHECKERR("CVARREAD",err); if (et==MPI_T_ENUM_NULL) { sprintf(value,"%i",v_int); } else { int i,etnum; char etname[20]; int etlen=20; int done=0; int newval; err=MPI_T_enum_get_info(et,&etnum,etname,&etlen); for (i=0; i<etnum; i++) { etlen=12; err=MPI_T_enum_get_item(et,i,&newval,etname,&etlen); if (newval==v_int) { sprintf(value, "%s",etname); done=1; } } if (!done) { sprintf(value, "unknown"); } } } else if (dt==MPI_UNSIGNED) { err=MPI_T_cvar_read(handle,&v_uint); CHECKERR("CVARREAD",err); sprintf(value,"%u",v_uint); } else if (dt==MPI_UNSIGNED_LONG) { err=MPI_T_cvar_read(handle,&v_ulong); CHECKERR("CVARREAD",err); sprintf(value,"%lu",v_ulong); } else if (dt==MPI_UNSIGNED_LONG_LONG) { err=MPI_T_cvar_read(handle,&v_ullong); CHECKERR("CVARREAD",err); sprintf(value,"%llu",v_ullong); } else if (dt==MPI_COUNT) { err=MPI_T_cvar_read(handle,&v_count); CHECKERR("CVARREAD",err); sprintf(value,"%lu",v_count); } else if (dt==MPI_CHAR) { err=MPI_T_cvar_read(handle,v_char); CHECKERR("CVARREAD",err); sprintf(value,"%s",v_char); } else if (dt==MPI_DOUBLE) { err=MPI_T_cvar_read(handle,&v_double); CHECKERR("CVARREAD",err); sprintf(value,"%d",v_double); } else { value_sup=0; sprintf(value,"unsupported"); } } else { value_sup=0; sprintf(value,"unsupported"); } } if (handle!=MPI_T_CVAR_HANDLE_NULL) { MPI_T_cvar_handle_free(&handle); CHECKERR("CVAR-FREE",err); } if (verbos<=verbosity) { if (!longlist) { print_filled(name,maxnamelen,' '); printf(" "); print_verbosity_short(verbos); printf(" "); print_type(dt); printf(" "); print_bind(bind); printf(" "); print_scope(scope); printf(" "); printf("%s",value); printf("\n"); } else { print_filled("",SCREENLEN,'-');printf("\n"); printf("Name: %s (",name); print_verbosity(verbos);printf(")\n"); printf("Type: "); print_type(dt); printf("\n"); printf("Bind: "); print_bind(bind); printf("\n"); printf("Scope: ");print_scope(scope);printf("\n"); printf("Value: %s\n\n",value); if (desc!=NULL) printf("%s\n\n",desc); } } } if (numvars>0) { if (!longlist) { print_filled("",prtlen,'-');printf("\n"); } else { print_filled("",SCREENLEN,'-');printf("\n"); } } /* free buffers */ free(name); free(desc); }
int main(int argc, char **argv) { int i; int num; int rank, size; /*#define STR_SZ (15)*/ #define STR_SZ (50) int name_len = STR_SZ; char name[STR_SZ] = ""; int desc_len = STR_SZ; char desc[STR_SZ] = ""; int verb; MPI_Datatype dtype; int count; int bind; int scope; int provided; int initialize_mpi = 0; MPI_T_cvar_handle handle; MPI_T_enum enumtype; provided = 0xdeadbeef; MPI_T_init_thread(MPI_THREAD_SINGLE, &provided); assert(provided != 0xdeadbeef); if (initialize_mpi) { MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); } num = 0xdeadbeef; MPI_T_cvar_get_num(&num); printf("get_num=%d\n", num); assert(num != 0xdeadbeef); for (i = 0; i < num; ++i) { name_len = desc_len = STR_SZ; MPI_T_cvar_get_info(i, name, &name_len, &verb, &dtype, &enumtype, desc, &desc_len, &bind, &scope); printf("index=%d\n", i); printf("--> name='%s' name_len=%d desc='%s' desc_len=%d\n", name, name_len, desc, desc_len); printf("--> verb=%d dtype=%#x bind=%d scope=%d\n", verb, dtype, bind, scope); MPI_T_cvar_handle_alloc(i, NULL, &handle, &count); printf("--> handle allocated: handle=%p count=%d\n", handle, count); if (dtype == MPI_INT) { int val = 0xdeadbeef; MPI_T_cvar_read(handle, &val); printf("--> val=%d\n", val); ++val; MPI_T_cvar_write(handle, &val); val = 0xdeadbeef; MPI_T_cvar_read(handle, &val); printf("--> incremented val=%d\n", val); } else if (dtype == MPI_DOUBLE) { double val = NAN; MPI_T_cvar_read(handle, &val); printf("--> val=%f\n", val); val *= 2.0; MPI_T_cvar_write(handle, &val); val = NAN; MPI_T_cvar_read(handle, &val); printf("--> doubled val=%f\n", val); } else if (dtype == MPI_CHAR) { char *str = malloc(count+1); MPI_T_cvar_read(handle, str); printf("--> str='%s'\n", str); /* just write the string back unmodified for now */ MPI_T_cvar_write(handle, str); MPI_T_cvar_read(handle, str); printf("--> written-then-read str='%s'\n", str); } MPI_T_cvar_handle_free(&handle); printf("\n"); } if (initialize_mpi) { MPI_Finalize(); } MPI_T_finalize(); return 0; }
int main(int argc, char **argv) { int errs = 0; int i, j; int rank, size; int num_pvars, num_cvars, num_cat; #define STR_SZ (50) int name_len; char name[STR_SZ + 1] = ""; /* +1 to check for overrun */ int desc_len; char desc[STR_SZ + 1] = ""; /* +1 to check for overrun */ int verb; MPI_Datatype dtype; int count; int bind; int scope; int provided; /* Init'ed to a garbage value, to trigger MPI_T bugs easily if there are. */ MPI_T_enum enumtype = (MPI_T_enum) 0x31415926; MTest_Init(&argc, &argv); MPI_T_init_thread(MPI_THREAD_SINGLE, &provided); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); /* loop over all cvars and ask for string arguments with various valid * combinations of NULL and non-NULL to ensure that the library handles this * case correctly */ MPI_T_cvar_get_num(&num_cvars); for (i = 0; i < num_cvars; ++i) { int full_name_len, full_desc_len; /* pass NULL string, non-zero lengths; should get full lengths */ full_name_len = full_desc_len = 1; MPI_T_cvar_get_info(i, NULL, &full_name_len, &verb, &dtype, &enumtype, NULL, &full_desc_len, &bind, &scope); check(full_name_len >= 0); check(full_desc_len >= 0); /* pass non-NULL string, zero lengths; should get full lengths also */ name_len = desc_len = 0; MPI_T_cvar_get_info(i, name, &name_len, &verb, &dtype, &enumtype, desc, &desc_len, &bind, &scope); check(full_name_len == name_len); check(full_desc_len == desc_len); /* regular call, no NULLs; should truncate (with termination) to STR_SZ * if necessary, otherwise returns strlen+1 in the corresponding "_len" * var */ name_len = desc_len = STR_SZ; MPI_T_cvar_get_info(i, name, &name_len, &verb, &dtype, &enumtype, desc, &desc_len, &bind, &scope); check((strlen(name) + 1) == min(name_len, STR_SZ)); check((strlen(desc) + 1) == min(desc_len, STR_SZ)); /* pass NULL lengths, string buffers should be left alone */ for (j = 0; j < STR_SZ; ++j) { name[j] = j % CHAR_MAX; desc[j] = j % CHAR_MAX; } MPI_T_cvar_get_info(i, name, /*name_len= */ NULL, &verb, &dtype, &enumtype, desc, /*desc_len= */ NULL, &bind, &scope); for (j = 0; j < STR_SZ; ++j) { check(name[j] == j % CHAR_MAX); check(desc[j] == j % CHAR_MAX); } /* not much of a string test, just need a quick spot to stick a test for * the existence of the correct MPI_T prototype (tt#1727) */ /* Include test that enumtype is defined */ if (dtype == MPI_INT && enumtype != MPI_T_ENUM_NULL) { int num_enumtype = -1; name_len = STR_SZ; MPI_T_enum_get_info(enumtype, &num_enumtype, name, &name_len); check(num_enumtype >= 0); } } /* check string handling for performance variables */ MPI_T_pvar_get_num(&num_pvars); for (i = 0; i < num_pvars; ++i) { int varclass, bind, readonly, continuous, atomic; MPI_Datatype dtype; MPI_T_enum enumtype; int full_name_len, full_desc_len; /* pass NULL string, non-zero lengths; should get full lengths */ full_name_len = full_desc_len = 1; MPI_T_pvar_get_info(i, NULL, &full_name_len, &verb, &varclass, &dtype, &enumtype, NULL, &full_desc_len, &bind, &readonly, &continuous, &atomic); check(full_name_len >= 0); check(full_desc_len >= 0); /* pass non-NULL string, zero lengths; should get full lengths also */ name_len = desc_len = 0; MPI_T_pvar_get_info(i, name, &name_len, &verb, &varclass, &dtype, &enumtype, desc, &desc_len, &bind, &readonly, &continuous, &atomic); check(full_name_len == name_len); check(full_desc_len == desc_len); /* regular call, no NULLs; should truncate (with termination) to STR_SZ * if necessary, otherwise returns strlen+1 in the corresponding "_len" * var */ name[STR_SZ] = (char) 'Z'; desc[STR_SZ] = (char) 'Z'; name_len = desc_len = STR_SZ; MPI_T_pvar_get_info(i, name, &name_len, &verb, &varclass, &dtype, &enumtype, desc, &desc_len, &bind, &readonly, &continuous, &atomic); check((strlen(name) + 1) == min(name_len, STR_SZ)); check((strlen(desc) + 1) == min(desc_len, STR_SZ)); check(name[STR_SZ] == (char) 'Z'); check(desc[STR_SZ] == (char) 'Z'); /* pass NULL lengths, string buffers should be left alone */ for (j = 0; j < STR_SZ; ++j) { name[j] = j % CHAR_MAX; desc[j] = j % CHAR_MAX; } MPI_T_pvar_get_info(i, name, /*name_len= */ NULL, &verb, &varclass, &dtype, &enumtype, desc, /*desc_len= */ NULL, &bind, &readonly, &continuous, &atomic); for (j = 0; j < STR_SZ; ++j) { check(name[j] == j % CHAR_MAX); check(desc[j] == j % CHAR_MAX); } } /* check string handling for categories */ MPI_T_category_get_num(&num_cat); for (i = 0; i < num_cat; ++i) { int full_name_len, full_desc_len; /* pass NULL string, non-zero lengths; should get full lengths */ full_name_len = full_desc_len = 1; MPI_T_category_get_info(i, NULL, &full_name_len, NULL, &full_desc_len, &num_cvars, &num_pvars, /*num_categories= */ &j); check(full_name_len >= 0); check(full_desc_len >= 0); /* pass non-NULL string, zero lengths; should get full lengths also */ name_len = desc_len = 0; MPI_T_category_get_info(i, name, &name_len, desc, &desc_len, &num_cvars, &num_pvars, /*num_categories= */ &j); check(full_name_len == name_len); check(full_desc_len == desc_len); /* regular call, no NULLs; should truncate (with termination) to STR_SZ * if necessary, otherwise returns strlen+1 in the corresponding "_len" * var */ name[STR_SZ] = (char) 'Z'; desc[STR_SZ] = (char) 'Z'; name_len = desc_len = STR_SZ; MPI_T_category_get_info(i, name, &name_len, desc, &desc_len, &num_cvars, &num_pvars, /*num_categories= */ &j); check((strlen(name) + 1) == min(name_len, STR_SZ)); check((strlen(desc) + 1) == min(desc_len, STR_SZ)); check(name[STR_SZ] == (char) 'Z'); check(desc[STR_SZ] == (char) 'Z'); /* pass NULL lengths, string buffers should be left alone */ for (j = 0; j < STR_SZ; ++j) { name[j] = j % CHAR_MAX; desc[j] = j % CHAR_MAX; } MPI_T_category_get_info(i, name, /*name_len= */ NULL, desc, /*desc_len= */ NULL, &num_cvars, &num_pvars, /*num_categories= */ &j); for (j = 0; j < STR_SZ; ++j) { check(name[j] == j % CHAR_MAX); check(desc[j] == j % CHAR_MAX); } /* not really a string test, just need a quick spot to stick a test for the * existence of the correct MPI_T prototype (tt#1727) */ { int indices[1]; MPI_T_category_get_pvars(i, 1, indices); } } MPI_T_finalize(); MTest_Finalize(errs); return MTestReturnValue(errs); }