Example #1
0
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;
}
Example #2
0
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);
}