Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Added include file with macro definitions for coccinelle-generated code.
authorpini <pini@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 17 Jan 2011 13:30:30 +0000 (13:30 +0000)
committerpini <pini@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 17 Jan 2011 13:30:30 +0000 (13:30 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9420 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/smpi/smpi_cocci.h [new file with mode: 0644]

diff --git a/include/smpi/smpi_cocci.h b/include/smpi/smpi_cocci.h
new file mode 100644 (file)
index 0000000..cc03928
--- /dev/null
@@ -0,0 +1,54 @@
+/* Copyright (c) 2011. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef SMPI_COCCI_H
+#define SMPI_COCCI_H
+
+/* Macros used by coccinelle-generated code */
+
+#define SMPI_INITIALIZE_GLOBAL(name,type)                       \
+   NULL;                                                        \
+void __attribute__((weak,constructor)) __preinit_##name(void) { \
+   if(!name)                                                    \
+      name = (type*)malloc(smpi_global_size() * sizeof(type));  \
+}                                                               \
+void __attribute__((weak,destructor)) __postfini_##name(void) { \
+   free(name);                                                  \
+   name = NULL;                                                 \
+}
+
+#define SMPI_INITIALIZE_AND_SET_GLOBAl(name,type,expr)          \
+   NULL;                                                        \
+void __attribute__((weak,constructor)) __preinit_##name(void) { \
+   size_t size = smpi_global_size();                            \
+   size_t i;                                                    \
+   type value = expr;                                           \
+   if(!name) {                                                  \
+      name = (type*)malloc(size * sizeof(type));                \
+      for(i = 0; i < size; i++) {                               \
+         name[i] = value;                                       \
+      }                                                         \
+   }                                                            \
+}                                                               \
+void __attribute__((weak,destructor)) __postfini_##name(void) { \
+   free(name);                                                  \
+   name = NULL;                                                 \
+}
+
+#define SMPI_GLOBAL_VAR_LOCAL_ACCESS(name) name[__rank()]
+
+/* 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;
+
+   if(rank < 0) {
+      rank = smpi_global_rank();
+   }
+   return rank;
+}
+
+#endif