+
+int smpi_type_attr_delete(MPI_Datatype type, int keyval){
+ char* tmpkey=xbt_malloc(sizeof(int));
+ sprintf(tmpkey, "%d", keyval);
+ smpi_type_key_elem elem = xbt_dict_get_or_null(smpi_type_keyvals, (const char*)tmpkey);
+ if(!elem)
+ return MPI_ERR_ARG;
+ if(elem->delete_fn!=MPI_NULL_DELETE_FN){
+ void * value;
+ int flag;
+ if(smpi_type_attr_get(type, keyval, &value, &flag)==MPI_SUCCESS){
+ int ret = elem->delete_fn(type, keyval, &value, &flag);
+ if(ret!=MPI_SUCCESS) return ret;
+ }
+ }
+ if(type->attributes==NULL)
+ return MPI_ERR_ARG;
+
+ xbt_dict_remove(type->attributes, (const char*)tmpkey);
+ return MPI_SUCCESS;
+}
+
+int smpi_type_attr_get(MPI_Datatype type, int keyval, void* attr_value, int* flag){
+ char* tmpkey=xbt_malloc(sizeof(int));
+ sprintf(tmpkey, "%d", keyval);
+ smpi_type_key_elem elem = xbt_dict_get_or_null(smpi_type_keyvals, (const char*)tmpkey);
+ if(!elem)
+ return MPI_ERR_ARG;
+ xbt_ex_t ex;
+ if(type->attributes==NULL){
+ *flag=0;
+ return MPI_SUCCESS;
+ }
+ TRY {
+ char* tmpkey=xbt_malloc(sizeof(int));
+ sprintf(tmpkey, "%d", keyval);
+ *(void**)attr_value = xbt_dict_get(type->attributes, (const char*)tmpkey);
+ *flag=1;
+ }
+ CATCH(ex) {
+ *flag=0;
+ xbt_ex_free(ex);
+ }
+ return MPI_SUCCESS;
+}
+
+int smpi_type_attr_put(MPI_Datatype type, int keyval, void* attr_value){
+ if(!smpi_type_keyvals)
+ smpi_type_keyvals = xbt_dict_new();
+ char* tmpkey=xbt_malloc(sizeof(int));
+ sprintf(tmpkey, "%d", keyval);
+ smpi_type_key_elem elem = xbt_dict_get_or_null(smpi_type_keyvals, (const char*)tmpkey);
+ if(!elem )
+ return MPI_ERR_ARG;
+ int flag;
+ void* value;
+ smpi_type_attr_get(type, keyval, &value, &flag);
+ if(flag && elem->delete_fn!=MPI_NULL_DELETE_FN){
+ int ret = elem->delete_fn(type, keyval, &value, &flag);
+ if(ret!=MPI_SUCCESS) return ret;
+ }
+ if(type->attributes==NULL)
+ type->attributes=xbt_dict_new();
+
+ xbt_dict_set(type->attributes, (const char*)tmpkey, attr_value, NULL);
+ return MPI_SUCCESS;
+}
+
+int smpi_type_keyval_create(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, void* extra_state){
+
+ if(!smpi_type_keyvals)
+ smpi_type_keyvals = xbt_dict_new();
+
+ smpi_type_key_elem value = (smpi_type_key_elem) xbt_new0(s_smpi_mpi_type_key_elem_t,1);
+
+ value->copy_fn=copy_fn;
+ value->delete_fn=delete_fn;
+
+ *keyval = type_keyval_id;
+ char* tmpkey=xbt_malloc(sizeof(int));
+ sprintf(tmpkey, "%d", *keyval);
+ xbt_dict_set(smpi_type_keyvals,(const char*)tmpkey,(void*)value, NULL);
+ type_keyval_id++;
+ return MPI_SUCCESS;
+}
+
+int smpi_type_keyval_free(int* keyval){
+ smpi_type_key_elem elem = xbt_dict_get_or_null(smpi_type_keyvals, (const char*)keyval);
+ if(!elem)
+ return MPI_ERR_ARG;
+ char* tmpkey=xbt_malloc(sizeof(int));
+ sprintf(tmpkey, "%d", *keyval);
+ xbt_dict_remove(smpi_type_keyvals, (const char*)tmpkey);
+ xbt_free(elem);
+ return MPI_SUCCESS;
+}