1 /* Copyright (c) 2011. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
12 /* Macros used by coccinelle-generated code */
14 #define SMPI_VARINIT_GLOBAL(name,type) \
16 void __attribute__((weak,constructor)) __preinit_##name(void) { \
18 name = (type*)malloc(smpi_global_size() * sizeof(type)); \
20 void __attribute__((weak,destructor)) __postfini_##name(void) { \
25 #define SMPI_VARINIT_GLOBAL_AND_SET(name,type,expr) \
27 void __attribute__((weak,constructor)) __preinit_##name(void) { \
28 size_t size = smpi_global_size(); \
32 name = (type*)malloc(size * sizeof(type)); \
33 for(i = 0; i < size; i++) { \
38 void __attribute__((weak,destructor)) __postfini_##name(void) { \
43 #define SMPI_VARGET_GLOBAL(name) name[smpi_process_index()]
45 /* The following handle local static variables */
47 XBT_PUBLIC(void) smpi_register_static(void* arg);
49 #define SMPI_VARINIT_STATIC(name,type) \
50 static type *name = NULL; \
52 name = (type*)malloc(smpi_global_size() * sizeof(type)); \
53 smpi_register_static(name); \
56 #define SMPI_VARINIT_STATIC_AND_SET(name,type,expr) \
57 static type *name = NULL; \
59 size_t size = smpi_global_size(); \
62 name = (type*)malloc(size * sizeof(type)); \
63 for(i = 0; i < size; i++) { \
66 smpi_register_static(name); \
69 #define SMPI_VARGET_STATIC(name) name[smpi_process_index()]