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 * Since its implementation relies on the on_exit() function that
52 * is not implemented on Mac, this function is a no-op on that
53 * architecture. But the only issue raised is that the memory is
54 * not raised right before the process terminaison. This is only
55 * important if you want to run valgrind on the code, or
58 XBT_PUBLIC(void) smpi_register_static(void* arg);
60 #define SMPI_VARINIT_STATIC(name,type) \
61 static type *name = NULL; \
63 name = (type*)malloc(smpi_global_size() * sizeof(type)); \
64 smpi_register_static(name); \
67 #define SMPI_VARINIT_STATIC_AND_SET(name,type,expr) \
68 static type *name = NULL; \
70 size_t size = smpi_global_size(); \
73 name = (type*)malloc(size * sizeof(type)); \
74 for(i = 0; i < size; i++) { \
77 smpi_register_static(name); \
80 #define SMPI_VARGET_STATIC(name) name[smpi_process_index()]