-
- if (!allocs) {
- allocs = xbt_dict_new_homogeneous(free);
- }
- data = xbt_dict_get_or_null(allocs, loc);
- if (!data) {
- data = (shared_data_t *) xbt_malloc0(sizeof(int) + size);
- data->count = 1;
- xbt_dict_set(allocs, loc, data, NULL);
- } else {
- data->count++;
+ if (sg_cfg_get_boolean("smpi/use_shared_malloc")){
+ for(i = 0; i < len; i++) {
+ /* Make the 'loc' ID be a flat filename */
+ if(loc[i] == '/') {
+ loc[i] = '_';
+ }
+ }
+ if (!allocs) {
+ allocs = xbt_dict_new_homogeneous(free);
+ }
+ data = xbt_dict_get_or_null(allocs, loc);
+ if(!data) {
+ fd = shm_open(loc, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if(fd < 0) {
+ switch(errno) {
+ case EEXIST:
+ xbt_die("Please cleanup /dev/shm/%s", loc);
+ default:
+ xbt_die("An unhandled error occured while opening %s: %s", loc, strerror(errno));
+ }
+ }
+ data = xbt_new(shared_data_t, 1);
+ data->fd = fd;
+ data->count = 1;
+ data->loc = loc;
+ mem = shm_map(fd, size, data);
+ if(shm_unlink(loc) < 0) {
+ XBT_WARN("Could not early unlink %s: %s", loc, strerror(errno));
+ }
+ xbt_dict_set(allocs, loc, data, NULL);
+ XBT_DEBUG("Mapping %s at %p through %d", loc, mem, fd);
+ } else {
+ mem = shm_map(data->fd, size, data);
+ data->count++;
+ }
+ XBT_DEBUG("Shared malloc %zu in %p (metadata at %p)", size, mem, data);
+ }else{
+ mem = xbt_malloc(size);
+ XBT_DEBUG("Classic malloc %zu in %p", size, mem);