+ shared_metadata_t newmeta;
+ //register metadata for memcpy avoidance
+ shared_data_key_type* data = (shared_data_key_type*)xbt_malloc(sizeof(shared_data_key_type));
+ data->second.fd = -1;
+ data->second.count = 1;
+ newmeta.size = size;
+ newmeta.data = data;
+ if(shared_block_offsets[0] > 0) {
+ newmeta.private_blocks.push_back(std::make_pair(0, shared_block_offsets[0]));
+ }
+ int i_block;
+ for(i_block = 0; i_block < nb_shared_blocks-1; i_block ++) {
+ newmeta.private_blocks.push_back(std::make_pair(shared_block_offsets[2*i_block+1], shared_block_offsets[2*i_block+2]));
+ }
+ if(shared_block_offsets[2*i_block+1] < size) {
+ newmeta.private_blocks.push_back(std::make_pair(shared_block_offsets[2*i_block+1], size));
+ }
+ allocs_metadata[mem] = newmeta;
+
+ return mem;
+}
+
+/*
+ * When nb_shared_blocks == -1, default behavior of smpi_shared_malloc: everything is shared.
+ * Otherwise, only the blocks described by shared_block_offsets are shared.
+ * This array contains the offsets (in bytes) of the block to share.
+ * Even indices are the start offsets (included), odd indices are the stop offsets (excluded).
+ * For instance, if shared_block_offsets == {27, 42}, then the elements mem[27], mem[28], ..., mem[41] are shared. The others are not.
+ */
+void *smpi_shared_malloc_global(size_t size, const char *file, int line, int *shared_block_offsets=NULL, int nb_shared_blocks=-1) {
+ int tmp_shared_block_offsets[2];
+ if(nb_shared_blocks == -1) {
+ nb_shared_blocks = 1;
+ shared_block_offsets = tmp_shared_block_offsets;
+ shared_block_offsets[0] = 0;
+ shared_block_offsets[1] = size;
+ }
+ return smpi_shared_malloc_global__(size, file, line, shared_block_offsets, nb_shared_blocks);
+}
+
+void *smpi_shared_malloc(size_t size, const char *file, int line) {
+ void *mem;
+ if (size > 0 && smpi_cfg_shared_malloc == shmalloc_local) {
+ mem = smpi_shared_malloc_local(size, file, line);
+ } else if (smpi_cfg_shared_malloc == shmalloc_global) {
+ mem = smpi_shared_malloc_global(size, file, line);