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 */
46 /** @brief Make sure that the passed pointer is freed on process exit.
48 * This function is rather internal, mainly used for the
49 * privatization of global variables through coccinelle.
51 XBT_PUBLIC(void) smpi_register_static(void* arg, void_f_pvoid_t free_fn);
53 XBT_PUBLIC(void) smpi_free_static(void);
55 #define SMPI_VARINIT_STATIC(name,type) \
56 static type *name = NULL; \
58 name = (type*)malloc(smpi_global_size() * sizeof(type)); \
59 smpi_register_static(name, xbt_free); \
62 #define SMPI_VARINIT_STATIC_AND_SET(name,type,expr) \
63 static type *name = NULL; \
65 size_t size = smpi_global_size(); \
68 name = (type*)malloc(size * sizeof(type)); \
69 for(i = 0; i < size; i++) { \
72 smpi_register_static(name, xbt_free); \
75 #define SMPI_VARGET_STATIC(name) name[smpi_process_index()]