Validating the Data Type: The da_validate Function
The da_validate function checks the data's type is the one to be mapped and that it contains the required fields. These fields are:
# struct cyclic_array
# {
# int * local_elements;
# int local_count;
# int global_count;
# int numprocs;
# int myproc;
# };
Here is the validation procedure:
proc da_validate {instance_id} {
global _da_info
set fields [TV::type get $instance_id struct_fields]
# We'll save four properties of each type:
# The offset of the pointer to the local array.
# The target type identifier.
# The target type size.
# The offset of the local_count.
# The offset of the global count.
set typeinfo [list {} {} {} {} {}]
set matched 0
foreach field $fields {
set name [lindex $field 0]
set addressing [lindex $field 2]
switch -- $name {
local_elements {
set typeinfo [lreplace $typeinfo 0 0 \
[extract_offset $addressing]]
# Extract the target type too.
set field_typeid \
[TV::type get [lindex $field 1] target]
set typeinfo [lreplace $typeinfo 1 1 $field_typeid]
set typeinfo [lreplace $typeinfo 2 2 \
[TV::type get $field_typeid length]]
incr matched
}
local_count {
set typeinfo [lreplace $typeinfo 3 3 \
[extract_offset $addressing]]
incr matched
}
global_count {
set typeinfo [lreplace $typeinfo 4 4 \
[extract_offset $addressing]]
incr matched
}
}
}
if {$matched != 3} {
return false
}
set _da_info($instance_id) $typeinfo
return true;
}