Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
I finally understood what this function is good for
[simgrid.git] / include / smpi / smpi_cocci.h
index cc03928..bcd150d 100644 (file)
@@ -7,10 +7,12 @@
 #ifndef SMPI_COCCI_H
 #define SMPI_COCCI_H
 
+#include <xbt/misc.h>
+
 /* Macros used by coccinelle-generated code */
 
-#define SMPI_INITIALIZE_GLOBAL(name,type)                       \
-   NULL;                                                        \
+#define SMPI_VARINIT_GLOBAL(name,type)                          \
+type *name = NULL;                                              \
 void __attribute__((weak,constructor)) __preinit_##name(void) { \
    if(!name)                                                    \
       name = (type*)malloc(smpi_global_size() * sizeof(type));  \
@@ -20,8 +22,8 @@ void __attribute__((weak,destructor)) __postfini_##name(void) { \
    name = NULL;                                                 \
 }
 
-#define SMPI_INITIALIZE_AND_SET_GLOBAl(name,type,expr)          \
-   NULL;                                                        \
+#define SMPI_VARINIT_GLOBAL_AND_SET(name,type,expr)             \
+type *name = NULL;                                              \
 void __attribute__((weak,constructor)) __preinit_##name(void) { \
    size_t size = smpi_global_size();                            \
    size_t i;                                                    \
@@ -38,17 +40,32 @@ void __attribute__((weak,destructor)) __postfini_##name(void) { \
    name = NULL;                                                 \
 }
 
-#define SMPI_GLOBAL_VAR_LOCAL_ACCESS(name) name[__rank()]
+#define SMPI_VARGET_GLOBAL(name) name[smpi_process_index()]
+
+/* The following handle local static variables */
 
-/* This function stores the rank locally, so that a request in
-   SIMIX is not created each time */
-int __attribute__((weak)) __rank(void) {
-   static __thread int rank = -1;
+XBT_PUBLIC(void) smpi_register_static(void* arg);
 
-   if(rank < 0) {
-      rank = smpi_global_rank();
-   }
-   return rank;
+#define SMPI_VARINIT_STATIC(name,type)                      \
+static type *name = NULL;                                   \
+if(!name) {                                                 \
+   name = (type*)malloc(smpi_global_size() * sizeof(type)); \
+   smpi_register_static(name);                              \
 }
 
+#define SMPI_VARINIT_STATIC_AND_SET(name,type,expr) \
+static type *name = NULL;                           \
+if(!name) {                                         \
+   size_t size = smpi_global_size();                \
+   size_t i;                                        \
+   type value = expr;                               \
+   name = (type*)malloc(size * sizeof(type));       \
+   for(i = 0; i < size; i++) {                      \
+      name[i] = value;                              \
+   }                                                \
+   smpi_register_static(name);                      \
+}
+
+#define SMPI_VARGET_STATIC(name) name[smpi_process_index()]
+
 #endif