From: pini Date: Mon, 17 Jan 2011 13:30:30 +0000 (+0000) Subject: Added include file with macro definitions for coccinelle-generated code. X-Git-Tag: v3.6_beta2~508 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/04748f132094859653edd593ffb2901490282f2e?ds=sidebyside Added include file with macro definitions for coccinelle-generated code. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9420 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/include/smpi/smpi_cocci.h b/include/smpi/smpi_cocci.h new file mode 100644 index 0000000000..cc03928600 --- /dev/null +++ b/include/smpi/smpi_cocci.h @@ -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