+
+
+int smpi_keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state){
+
+ if(!smpi_keyvals)
+ smpi_keyvals = xbt_dict_new();
+
+ smpi_key_elem value = (smpi_key_elem) xbt_new0(s_smpi_mpi_key_elem_t,1);
+
+ value->copy_fn=copy_fn;
+ value->delete_fn=delete_fn;
+
+ *keyval = keyval_id;
+
+ xbt_dict_set(smpi_keyvals,(const char*)keyval,(void*)value, NULL);
+ keyval_id++;
+ return MPI_SUCCESS;
+}
+
+int smpi_keyval_free(int* keyval){
+ smpi_key_elem elem = xbt_dict_get_or_null(smpi_keyvals, (const char*)keyval);
+ if(!elem)
+ return MPI_ERR_ARG;
+ xbt_dict_remove(smpi_keyvals, (const char*)keyval);
+ xbt_free(elem);
+ return MPI_SUCCESS;
+}
+
+int smpi_attr_delete(MPI_Comm comm, int keyval){
+ smpi_key_elem elem = xbt_dict_get_or_null(smpi_keyvals, (const char*)&keyval);
+ if(!elem)
+ return MPI_ERR_ARG;
+ if(elem->delete_fn!=MPI_NULL_DELETE_FN){
+ void * value;
+ int flag;
+ if(smpi_attr_get(comm, keyval, &value, &flag)==MPI_SUCCESS){
+ int ret = elem->delete_fn(comm, keyval, &value, &flag);
+ if(ret!=MPI_SUCCESS) return ret;
+ }
+ }
+ return smpi_comm_attr_delete(comm, keyval);;
+}
+
+int smpi_attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag){
+ smpi_key_elem elem = xbt_dict_get_or_null(smpi_keyvals, (const char*)&keyval);
+ if(!elem)
+ return MPI_ERR_ARG;
+ return smpi_comm_attr_get(comm, keyval, attr_value, flag);;
+}
+
+int smpi_attr_put(MPI_Comm comm, int keyval, void* attr_value){
+
+ if(!smpi_keyvals)
+ smpi_keyvals = xbt_dict_new();
+
+ smpi_key_elem elem = xbt_dict_get_or_null(smpi_keyvals, (const char*)&keyval);
+ if(!elem )
+ return MPI_ERR_ARG;
+ int flag;
+ void* value;
+ smpi_attr_get(comm, keyval, &value, &flag);
+ if(flag){
+ int ret = elem->delete_fn(comm, keyval, &value, &flag);
+ if(ret!=MPI_SUCCESS) return ret;
+ }
+ return smpi_comm_attr_put(comm, keyval, attr_value);;
+}
+