einsteintoolkit / CactusNumerical_Slab.json
xinshuo's picture
Upload folder using huggingface_hub
10a2580 verified
Raw
History Blame Contribute Delete
93.3 kB
{
"thorn_name": "CactusNumerical/Slab",
"url": "https://bitbucket.org/cactuscode/cactusnumerical.git",
"configuration": "# Configuration definition for thorn Slab\n\nPROVIDES Slab\n{\n}\n\nOPTIONAL LoopControl MPI\n{\n}\n",
"interface": "# Interface definition for thorn Slab\n\nIMPLEMENTS: Slab\n\nINCLUDES HEADER: slab.h IN Slab.h\nINCLUDES HEADER: slab.inc IN Slab.inc\n\nUSES INCLUDE HEADER: loopcontrol.h\n\nCCTK_POINTER_TO_CONST \\\nFUNCTION GetMPICommWorld (CCTK_POINTER_TO_CONST IN cctkGH)\nUSES FUNCTION GetMPICommWorld\n",
"param": "# Parameter definitions for thorn Slab\n\nBOOLEAN timer_output \"Print slabbing timings at shutdown time\" STEERABLE=always\n{\n} \"no\"\n\nBOOLEAN use_alltoallv \"Use MPI_Alltoallv for communication?\" STEERABLE=always\n{\n} \"no\"\n",
"schedule": "# Schedule definitions for thorn Slab\n\nSCHEDULE Slab_InitMPIDatatypes AT startup after Driver_Startup\n{\n LANG: C\n} \"Create MPI datatypes for complex variables in C\"\n\nSCHEDULE Slab_InitTimers AT wragh\n{\n LANG: C\n} \"Initialise timers\"\n\nif (timer_output) {\n SCHEDULE Slab_PrintTimers AT shutdown\n {\n LANG: C\n } \"Print timers\"\n}\n",
"src": {
"make.code.defn": "# Main make.code.defn file for thorn Slab\n\n# Source files in this directory\nSRCS = slab.cc\n\n# Subdirectories containing source files\nSUBDIRS = \n\n",
"slab.h": "#ifndef SLAB_H\n#define SLAB_H\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include <stdio.h>\n\n#include <cctk.h>\n\n/*\n * Slab_Transfer copies a slab from one array into a slab of another\n * array.\n *\n * The src and dst variables describe the source and the destination\n * slab, respectively.\n *\n * The variables gsh, lbnd, ash and lsh describe the shape and\n * distribution of the array containing the slab. They are equivalent\n * to the corresponding quantities in the cGH structure.\n *\n * off, str, and len describe the location and shape of the slab\n * within the array. off is the offset, i.e., the location of the\n * \"first\" corner of the slab. str is the stride, i.e., the distance\n * between to grid points in the slab. The stride can be negative.\n * len is the length, i.e., the number of grid points making up the\n * slab. len does not include the grid points that are skipped if the\n * stride is larger than one.\n *\n * xpose describes a possible permutation of the coordinate axes\n * between the slabs. It is source-axis = xpose[destination-axis].\n *\n * flip describes a possible inversion of the coordinate axes (from\n * the point of view of the destination slab). It is source-axis =\n * xpose[flip[destination-axis]].\n *\n * The corresponding lengths of the source and the destination slabs\n * must be equal, i.e., for all d: src.len[xpose[d]] = dst.len[d].\n *\n * The slabs are copied according to\n *\n * dst[dst.off + I * dst.str] = src[src.off + J * src.str]\n *\n * where the multi-indices I and J have the ranges specified by\n * dst.len and src.len, respectively, and I and J are related by the\n * transposition\n *\n * J = xpose[flip[I]]\n *\n *\n *\n * Restrictions:\n *\n * dim >= 0\n *\n * gsh >= 0\n * lbnd >= 0\n * lsh >= 0\n * ash >= lsh\n * lbnd + lsh <= gsh\n * lbbox and ubbox must be booleans, i.e., either 0 or 1\n * nghostzones >= 0\n *\n * len >= 0\n * str != 0\n * off >= 0\n * off < gsh\n * off + (len-1) * str >= 0\n * off + (len-1) * str < gsh\n *\n * xpose must be a permutation of 0 ... dim-1\n * flip must be a boolean, i.e., either 0 or 1\n *\n * The source and the destination arrays may be the same.\n */\n\n#define SLAB_MAXDIM 3\n\nstruct slabinfo {\n int gsh;\n int lbnd, lsh;\n int ash;\n int lbbox, ubbox, nghostzones;\n int off, str, len;\n};\n\nstruct xferinfo {\n struct slabinfo src, dst;\n int xpose;\n int flip;\n};\n\nvoid print_slabinfo(FILE *const out,\n struct slabinfo const *restrict const slabinfo);\n\nvoid print_xferinfo(FILE *const out,\n struct xferinfo const *restrict const xferinfo);\n\nstruct slabsetup;\n\nstruct slabsetup *\nSlab_MultiTransfer_Init(cGH const *restrict const cctkGH, int const dim,\n struct xferinfo const *restrict const xferinfo,\n int const options);\n\nint Slab_MultiTransfer_Apply(cGH const *restrict const cctkGH,\n struct slabsetup const *restrict const slabsetup,\n int const nvars,\n int const *restrict const srctypes,\n void const *restrict const *restrict const srcptrs,\n int const *restrict const dsttypes,\n void *restrict const *restrict const dstptrs);\n\nint Slab_MultiTransfer_Finalize(cGH const *restrict const cctkGH,\n struct slabsetup *restrict const slabsetup);\n\nint Slab_MultiTransfer(cGH const *restrict const cctkGH, int const dim,\n struct xferinfo const *restrict const xferinfo,\n int const options, int const nvars,\n int const *restrict const srctypes,\n void const *restrict const *restrict const srcptrs,\n int const *restrict const dsttypes,\n void *restrict const *restrict const dstptrs);\n\nint Slab_Transfer(cGH const *restrict const cctkGH, int const dim,\n struct xferinfo const *restrict const xferinfo,\n int const options, int const srctype,\n void const *restrict const srcptr, int const dsttype,\n void *restrict const dstptr);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* defined SLAB_H */\n",
"slab.cc": "// TODO:\n// Provide facilities for dim > 3\n// Set up the slab exchange information in advance\n// Slab in several stages\n// Test slabbing without MPI\n// Allow not setting the ghost zones\n// Allow not using / not setting the boundaries\n// Allow different numbers of ghost zones at the lower and upper boundary\n\n// Print debug information?\n#undef DEBUG\n\n// Perform expensive self-checks?\n#undef CHECK\n\n// Omit all self-checks? (Overrides CHECK)\n#undef NDEBUG\n\n// Byte value for poison checks: use 255 for nan, or e.g. 113 for a\n// large value\n#define POISON_VALUE 254\n\n#include <algorithm>\n#include <cassert>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <limits>\n#include <vector>\n\n#include <cctk.h>\n#include <cctk_Arguments.h>\n#include <cctk_DefineThorn.h>\n#include <cctk_Parameters.h>\n#include <util_ErrorCodes.h>\n#include <util_Table.h>\n\n#include <loopcontrol.h>\n\n#ifdef CCTK_MPI\n#include <mpi.h>\n#define HAVE_MPI 1\n#else\n#define HAVE_MPI 0\n#endif\n\n#include \"slab.h\"\n\nusing namespace std;\n\n#ifdef DEBUG\n#define ifdebug\n#else\n#define ifdebug while (0)\n#endif\n\n#ifdef CHECK\n#define ifcheck\n#else\n#define ifcheck while (0)\n#endif\n\n#ifdef NDEBUG\n#define check(x) ((x) ? 0 : CCTK_WARN(0, \"internal error\"))\n#else\n#define check(x) assert(x)\n#endif\n\nstatic int timer_init = -1;\nstatic int timer_apply = -1;\nstatic int timer_copy_in = -1;\nstatic int timer_copy_in_noxpose = -1;\nstatic int timer_copy_in_xposexy = -1;\nstatic int timer_copy_in_xposegeneral = -1;\nstatic int timer_copy_in_general = -1;\nstatic int timer_xfer = -1;\nstatic int timer_copy_back = -1;\nstatic int timer_copy_back_noflip = -1;\nstatic int timer_copy_back_flipx = -1;\nstatic int timer_copy_back_flipy = -1;\nstatic int timer_copy_back_flipxy = -1;\nstatic int timer_copy_back_flipgeneral = -1;\nstatic int timer_copy_back_general = -1;\n\nextern \"C\" void Slab_InitTimers(CCTK_ARGUMENTS) {\n DECLARE_CCTK_ARGUMENTS_Slab_InitTimers;\n timer_init = CCTK_TimerCreate(\"Slab/init\");\n timer_apply = CCTK_TimerCreate(\"Slab/apply\");\n timer_copy_in = CCTK_TimerCreate(\"Slab/copy_in\");\n timer_copy_in_noxpose = CCTK_TimerCreate(\"Slab/copy_in_noxpose\");\n timer_copy_in_xposexy = CCTK_TimerCreate(\"Slab/copy_in_xposexy\");\n timer_copy_in_xposegeneral = CCTK_TimerCreate(\"Slab/copy_in_xposegeneral\");\n timer_copy_in_general = CCTK_TimerCreate(\"Slab/copy_in_general\");\n timer_xfer = CCTK_TimerCreate(\"Slab/xfer\");\n timer_copy_back = CCTK_TimerCreate(\"Slab/copy_back\");\n timer_copy_back_noflip = CCTK_TimerCreate(\"Slab/copy_back_noflip\");\n timer_copy_back_flipx = CCTK_TimerCreate(\"Slab/copy_back_flipx\");\n timer_copy_back_flipy = CCTK_TimerCreate(\"Slab/copy_back_flipy\");\n timer_copy_back_flipxy = CCTK_TimerCreate(\"Slab/copy_back_flipxy\");\n timer_copy_back_flipgeneral = CCTK_TimerCreate(\"Slab/copy_back_flipgeneral\");\n timer_copy_back_general = CCTK_TimerCreate(\"Slab/copy_back_general\");\n}\n\nextern \"C\" int Slab_PrintTimers() {\n CCTK_TimerPrintDataI(timer_init, -1);\n CCTK_TimerPrintDataI(timer_apply, -1);\n CCTK_TimerPrintDataI(timer_copy_in, -1);\n CCTK_TimerPrintDataI(timer_copy_in_noxpose, -1);\n CCTK_TimerPrintDataI(timer_copy_in_xposexy, -1);\n CCTK_TimerPrintDataI(timer_copy_in_xposegeneral, -1);\n CCTK_TimerPrintDataI(timer_copy_in_general, -1);\n CCTK_TimerPrintDataI(timer_xfer, -1);\n CCTK_TimerPrintDataI(timer_copy_back, -1);\n CCTK_TimerPrintDataI(timer_copy_back_noflip, -1);\n CCTK_TimerPrintDataI(timer_copy_back_flipx, -1);\n CCTK_TimerPrintDataI(timer_copy_back_flipy, -1);\n CCTK_TimerPrintDataI(timer_copy_back_flipxy, -1);\n CCTK_TimerPrintDataI(timer_copy_back_flipgeneral, -1);\n CCTK_TimerPrintDataI(timer_copy_back_general, -1);\n return 0;\n}\n\n// Find out which driver to use\n#ifdef CCTK_MPI\n#if defined CARPET_CARPET\n#include \"Carpet/Carpet/src/carpet_public.h\"\n#endif\n#if defined CACTUSPUGH_PUGH\n#include \"CactusPUGH/PUGH/src/include/pugh.h\"\n#endif\n#endif\n\n#ifdef CCTK_MPI\n// Determine MPI type sizes\n\n#define CACTUS_MPI_BYTE MPI_CHAR\n\n#define CACTUS_MPI_INT1 MPI_CHAR\n\n#if SIZEOF_SHORT_INT == 2\n#define CACTUS_MPI_INT2 MPI_SHORT\n#elif SIZEOF_INT == 2\n#define CACTUS_MPI_INT2 MPI_INT\n#elif SIZEOF_LONG_INT == 2\n#define CACTUS_MPI_INT2 MPI_LONG\n#elif SIZEOF_LONG_LONG == 2\n#define CACTUS_MPI_INT2 MPI_LONG_LONG_INT\n#endif\n\n#if SIZEOF_SHORT_INT == 4\n#define CACTUS_MPI_INT4 MPI_SHORT\n#elif SIZEOF_INT == 4\n#define CACTUS_MPI_INT4 MPI_INT\n#elif SIZEOF_LONG_INT == 4\n#define CACTUS_MPI_INT4 MPI_LONG\n#elif SIZEOF_LONG_LONG == 4\n#define CACTUS_MPI_INT4 MPI_LONG_LONG_INT\n#endif\n\n#if SIZEOF_SHORT_INT == 8\n#define CACTUS_MPI_INT8 MPI_SHORT\n#elif SIZEOF_INT == 8\n#define CACTUS_MPI_INT8 MPI_INT\n#elif SIZEOF_LONG_INT == 8\n#define CACTUS_MPI_INT8 MPI_LONG\n#elif SIZEOF_LONG_LONG == 8\n#define CACTUS_MPI_INT8 MPI_LONG_LONG_INT\n#endif\n\n#if SIZEOF_SHORT_INT == 16\n#define CACTUS_MPI_INT16 MPI_SHORT\n#elif SIZEOF_INT == 16\n#define CACTUS_MPI_INT16 MPI_INT\n#elif SIZEOF_LONG_INT == 16\n#define CACTUS_MPI_INT16 MPI_LONG\n#elif SIZEOF_LONG_LONG == 16\n#define CACTUS_MPI_INT16 MPI_LONG_LONG_INT\n#endif\n\n#if SIZEOF_FLOAT == 4\n#define CACTUS_MPI_REAL4 MPI_FLOAT\n#elif SIZEOF_DOUBLE == 4\n#define CACTUS_MPI_REAL4 MPI_DOUBLE\n#elif SIZEOF_LONG_DOUBLE == 4\n#define CACTUS_MPI_REAL4 MPI_LONG_DOUBLE\n#endif\n\n#if SIZEOF_FLOAT == 8\n#define CACTUS_MPI_REAL8 MPI_FLOAT\n#elif SIZEOF_DOUBLE == 8\n#define CACTUS_MPI_REAL8 MPI_DOUBLE\n#elif SIZEOF_LONG_DOUBLE == 8\n#define CACTUS_MPI_REAL8 MPI_LONG_DOUBLE\n#endif\n\n#if SIZEOF_FLOAT == 16\n#define CACTUS_MPI_REAL16 MPI_FLOAT\n#elif SIZEOF_DOUBLE == 16\n#define CACTUS_MPI_REAL16 MPI_DOUBLE\n#elif SIZEOF_LONG_DOUBLE == 16\n#define CACTUS_MPI_REAL16 MPI_LONG_DOUBLE\n#endif\n\nstatic MPI_Datatype CACTUS_MPI_COMPLEX8;\nstatic MPI_Datatype CACTUS_MPI_COMPLEX16;\nstatic MPI_Datatype CACTUS_MPI_COMPLEX32;\n\n#endif\n\n// Replace MPI functions if MPI is disabled\n#ifndef CCTK_MPI\n\ntypedef int MPI_Comm;\n\ntypedef enum {\n CACTUS_MPI_BYTE = CCTK_VARIABLE_BYTE,\n CACTUS_MPI_INT = CCTK_VARIABLE_INT,\n CACTUS_MPI_INT1 = CCTK_VARIABLE_INT1,\n CACTUS_MPI_INT2 = CCTK_VARIABLE_INT2,\n CACTUS_MPI_INT4 = CCTK_VARIABLE_INT4,\n CACTUS_MPI_INT8 = CCTK_VARIABLE_INT8,\n CACTUS_MPI_INT16 = CCTK_VARIABLE_INT16,\n CACTUS_MPI_REAL = CCTK_VARIABLE_REAL,\n CACTUS_MPI_REAL4 = CCTK_VARIABLE_REAL4,\n CACTUS_MPI_REAL8 = CCTK_VARIABLE_REAL8,\n CACTUS_MPI_REAL16 = CCTK_VARIABLE_REAL16,\n CACTUS_MPI_COMPLEX = CCTK_VARIABLE_COMPLEX,\n CACTUS_MPI_COMPLEX8 = CCTK_VARIABLE_COMPLEX8,\n CACTUS_MPI_COMPLEX16 = CCTK_VARIABLE_COMPLEX16,\n CACTUS_MPI_COMPLEX32 = CCTK_VARIABLE_COMPLEX32\n} MPI_Datatype;\n\nstatic MPI_Datatype MPI_INT;\n\ntypedef enum { MPI_MIN, MPI_MAX } MPI_Op;\n\nstatic int MPI_Barrier(MPI_Comm comm) { return 0; }\n\nstatic int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype, int root,\n MPI_Comm comm) {\n assert(buffer);\n assert(count >= 0);\n assert(root == 0);\n return 0;\n}\n\nstatic int MPI_Comm_size(MPI_Comm comm, int *size) {\n *size = 1;\n return 0;\n}\n\nstatic int MPI_Comm_rank(MPI_Comm comm, int *rank) {\n *rank = 0;\n return 0;\n}\n\nstatic int MPI_Allgather(void *sendbuf, int sendcnt, int sendtype,\n void *recvbuf, int recvcnt, int recvtype,\n MPI_Comm comm) {\n int recvsize;\n assert(sendbuf);\n assert(recvbuf);\n assert(sendcnt == recvcnt);\n assert(recvcnt >= 0);\n assert(sendtype == recvtype);\n recvsize = CCTK_VarTypeSize(recvtype);\n assert(recvsize > 0);\n memcpy(recvbuf, sendbuf, recvcnt * recvsize);\n return 0;\n}\n\nstatic int MPI_Alltoall(void *sendbuf, int sendcnt, int sendtype, void *recvbuf,\n int recvcnt, int recvtype, MPI_Comm comm) {\n int recvsize;\n assert(sendbuf);\n assert(recvbuf);\n assert(sendcnt == recvcnt);\n assert(recvcnt >= 0);\n assert(sendtype == recvtype);\n recvsize = CCTK_VarTypeSize(recvtype);\n assert(recvsize > 0);\n memcpy(recvbuf, sendbuf, recvcnt * recvsize);\n return 0;\n}\n\nstatic int MPI_Alltoallv(void *sendbuf, int *sendcnt, int *sendoff,\n int sendtype, void *recvbuf, int *recvcnt,\n int *recvoff, int recvtype, MPI_Comm comm) {\n int recvsize;\n assert(sendbuf);\n assert(recvbuf);\n assert(sendcnt);\n assert(recvcnt);\n assert(*sendcnt == *recvcnt);\n assert(*recvcnt >= 0);\n assert(sendoff);\n assert(recvoff);\n assert(*sendoff == 0);\n assert(*recvoff == 0);\n assert(sendtype == recvtype);\n recvsize = CCTK_VarTypeSize(recvtype);\n assert(recvsize > 0);\n memcpy(recvbuf, sendbuf, *recvcnt * recvsize);\n return 0;\n}\n\nstatic int MPI_Allreduce(void *sendbuf, void *recvbuf, int count,\n MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) {\n int recvsize;\n assert(sendbuf);\n assert(recvbuf);\n assert(count >= 0);\n recvsize = CCTK_VarTypeSize(datatype);\n assert(recvsize > 0);\n memcpy(recvbuf, sendbuf, count * recvsize);\n return 0;\n}\n\ntypedef int MPI_Request; // dummy\ntypedef int MPI_Status; // dummy\n#define MPI_REQUEST_NULL 0 // dummy\n#define MPI_STATUSES_IGNORE 0 // dummy\n\nstatic int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int source,\n int tag, MPI_Comm comm, MPI_Request *request) {\n abort();\n}\n\nstatic int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dest,\n int tag, MPI_Comm comm, MPI_Request *request) {\n abort();\n}\n\nstatic int MPI_Waitall(int count, MPI_Request *array_of_requests,\n MPI_Status *array_of_statuses) {\n abort();\n}\n\n#endif\n\n// Get the MPI COMM_WOLRD communicator from the driver\nstatic MPI_Comm get_mpi_comm(cGH const *restrict const cctkGH) {\n#ifdef CCTK_MPI\n if (CCTK_IsFunctionAliased(\"GetMPICommWorld\")) {\n return *(MPI_Comm const *)GetMPICommWorld(cctkGH);\n }\n#if defined CACTUSPUGH_PUGH\n {\n static int PUGH_active = -1;\n if (PUGH_active == -1)\n PUGH_active = CCTK_IsThornActive(\"PUGH\");\n assert(PUGH_active >= 0);\n if (PUGH_active)\n return PUGH_pGH(cctkGH)->PUGH_COMM_WORLD;\n }\n#endif\n return MPI_COMM_WORLD;\n#else\n return 0;\n#endif\n}\n\n// Initialise the MPI datatypes for complex variables\nextern \"C\" int Slab_InitMPIDatatypes() {\n#ifdef CCTK_MPI\n#ifdef HAVE_CCTK_REAL4\n assert(CACTUS_MPI_REAL4 != MPI_DATATYPE_NULL);\n MPI_Type_contiguous(2, CACTUS_MPI_REAL4, &CACTUS_MPI_COMPLEX8);\n MPI_Type_commit(&CACTUS_MPI_COMPLEX8);\n#endif\n#ifdef HAVE_CCTK_REAL8\n assert(CACTUS_MPI_REAL8 != MPI_DATATYPE_NULL);\n MPI_Type_contiguous(2, CACTUS_MPI_REAL8, &CACTUS_MPI_COMPLEX16);\n MPI_Type_commit(&CACTUS_MPI_COMPLEX16);\n#endif\n#ifdef HAVE_CCTK_REAL16\n if (CACTUS_MPI_REAL16 != MPI_DATATYPE_NULL) {\n MPI_Type_contiguous(2, CACTUS_MPI_REAL16, &CACTUS_MPI_COMPLEX32);\n MPI_Type_commit(&CACTUS_MPI_COMPLEX32);\n } else {\n // CCTK_REAL16 is not supported by MPI\n CCTK_WARN(CCTK_WARN_ALERT, \"CCTK_REAL16 support is enabled in Cactus, but \"\n \"is not supported by MPI. All MPI operations \"\n \"with this datatype will fail.\");\n CACTUS_MPI_COMPLEX32 = MPI_DATATYPE_NULL;\n }\n#endif\n#endif\n\n#ifndef CCTK_MPI\n switch (sizeof(int)) {\n#ifdef HAVE_CCTK_INT1\n case sizeof(CCTK_INT1):\n MPI_INT = CACTUS_MPI_INT1;\n break;\n#endif\n#ifdef HAVE_CCTK_INT2\n case sizeof(CCTK_INT2):\n MPI_INT = CACTUS_MPI_INT2;\n break;\n#endif\n#ifdef HAVE_CCTK_INT4\n case sizeof(CCTK_INT4):\n MPI_INT = CACTUS_MPI_INT4;\n break;\n#endif\n#ifdef HAVE_CCTK_INT8\n case sizeof(CCTK_INT8):\n MPI_INT = CACTUS_MPI_INT8;\n break;\n#endif\n default:\n CCTK_BUILTIN_UNREACHABLE();\n }\n#endif\n\n return 0;\n}\n\n// Normalise a Cactus datatype\nstatic int normal_type(int cactustype) {\n switch (cactustype) {\n case CCTK_VARIABLE_INT:\n#ifdef CCTK_INTEGER_PRECISION_1\n return CCTK_VARIABLE_INT1;\n#endif\n#ifdef CCTK_INTEGER_PRECISION_2\n return CCTK_VARIABLE_INT2;\n#endif\n#ifdef CCTK_INTEGER_PRECISION_4\n return CCTK_VARIABLE_INT4;\n#endif\n#ifdef CCTK_INTEGER_PRECISION_8\n return CCTK_VARIABLE_INT8;\n#endif\n#ifdef CCTK_INTEGER_PRECISION_16\n return CCTK_VARIABLE_INT16;\n#endif\n CCTK_BUILTIN_UNREACHABLE();\n case CCTK_VARIABLE_REAL:\n#ifdef CCTK_REAL_PRECISION_4\n return CCTK_VARIABLE_REAL4;\n#endif\n#ifdef CCTK_REAL_PRECISION_8\n return CCTK_VARIABLE_REAL8;\n#endif\n#ifdef CCTK_REAL_PRECISION_16\n return CCTK_VARIABLE_REAL16;\n#endif\n CCTK_BUILTIN_UNREACHABLE();\n case CCTK_VARIABLE_COMPLEX:\n#ifdef CCTK_REAL_PRECISION_4\n return CCTK_VARIABLE_COMPLEX8;\n#endif\n#ifdef CCTK_REAL_PRECISION_8\n return CCTK_VARIABLE_COMPLEX16;\n#endif\n#ifdef CCTK_REAL_PRECISION_16\n return CCTK_VARIABLE_COMPLEX32;\n#endif\n CCTK_BUILTIN_UNREACHABLE();\n }\n return cactustype;\n}\n\n// Find the MPI datatype corresponding to a Cactus datatype\nstatic MPI_Datatype mpi_type(int const cactustype) {\n int const normaltype = normal_type(cactustype);\n switch (normaltype) {\n case CCTK_VARIABLE_BYTE:\n return CACTUS_MPI_BYTE;\n#ifdef HAVE_CCTK_INT1\n case CCTK_VARIABLE_INT1:\n return CACTUS_MPI_INT1;\n#endif\n#ifdef HAVE_CCTK_INT2\n case CCTK_VARIABLE_INT2:\n return CACTUS_MPI_INT2;\n#endif\n#ifdef HAVE_CCTK_INT4\n case CCTK_VARIABLE_INT4:\n return CACTUS_MPI_INT4;\n#endif\n#ifdef HAVE_CCTK_INT8\n case CCTK_VARIABLE_INT8:\n return CACTUS_MPI_INT8;\n#endif\n// #ifdef HAVE_CCTK_INT16\n// case CCTK_VARIABLE_INT16: return CACTUS_MPI_INT16;\n// #endif\n#ifdef HAVE_CCTK_REAL4\n case CCTK_VARIABLE_REAL4:\n return CACTUS_MPI_REAL4;\n case CCTK_VARIABLE_COMPLEX8:\n return CACTUS_MPI_COMPLEX8;\n#endif\n#ifdef HAVE_CCTK_REAL8\n case CCTK_VARIABLE_REAL8:\n return CACTUS_MPI_REAL8;\n case CCTK_VARIABLE_COMPLEX16:\n return CACTUS_MPI_COMPLEX16;\n#endif\n#ifdef HAVE_CCTK_REAL16\n case CCTK_VARIABLE_REAL16:\n return CACTUS_MPI_REAL16;\n case CCTK_VARIABLE_COMPLEX32:\n return CACTUS_MPI_COMPLEX32;\n#endif\n }\n CCTK_ERROR(\"Unsupported datatype\");\n}\n\n////////////////////////////////////////////////////////////////////////////////\n\nstruct bbox {\n int off; // offset\n int len; // length\n int alen; // allocated length\n int str; // stride\n};\n\nstruct arrays {\n bbox global; // global region (all processors)\n bbox local; // this processor's region\n bbox active; // ???\n bbox slab; // the slab that should be transferred\n};\n\nstruct xfer {\n arrays src; // source region\n arrays dst; // destination region\n int xpose; // exchange axes\n int flip; // change directions of axes\n};\n\nstatic inline int roundup(int const x, int const y) {\n assert(x >= 0);\n assert(y > 0);\n return (x + y - 1) / y * y;\n}\n\nstatic void bbox_print(bbox const *restrict const bbox) {\n assert(bbox);\n printf(\"[%d:%d:%d]\", bbox->off, bbox->off + (bbox->len - 1) * bbox->str,\n bbox->str);\n}\n\nstatic void bbox_check(bbox const *restrict const bbox) {\n assert(bbox);\n assert(bbox->len >= 0);\n assert(bbox->alen >= bbox->len);\n assert(bbox->str > 0);\n}\n\nstatic void global2bbox(slabinfo const *restrict const slab,\n bbox *restrict const bbox) {\n assert(slab);\n assert(bbox);\n assert(slab->gsh >= 0);\n bbox->off = 0;\n bbox->len = slab->gsh;\n bbox->alen = slab->gsh;\n bbox->str = 1;\n bbox_check(bbox);\n}\n\nstatic void local2bbox(slabinfo const *restrict const slab,\n bbox *restrict const bbox) {\n assert(slab);\n assert(bbox);\n assert(slab->lbnd >= 0);\n assert(slab->lsh >= 0);\n assert(slab->ash >= slab->lsh);\n assert(slab->lbnd + slab->lsh <= slab->gsh);\n bbox->off = slab->lbnd;\n bbox->len = slab->lsh;\n bbox->alen = slab->ash;\n bbox->str = 1;\n bbox_check(bbox);\n}\n\nstatic void active2bbox(slabinfo const *restrict const slab,\n bbox *restrict const bbox, int const useghosts) {\n assert(slab);\n assert(bbox);\n assert(useghosts == 0 or useghosts == 1);\n assert(slab->lbnd >= 0);\n assert(slab->lsh >= 0);\n assert(slab->ash >= slab->lsh);\n assert(slab->lbnd + slab->lsh <= slab->gsh);\n assert(slab->lbbox == 0 or slab->lbbox == 1);\n assert(slab->ubbox == 0 or slab->ubbox == 1);\n assert(slab->nghostzones >= 0);\n int const nlghostzones = slab->lbbox or useghosts ? 0 : slab->nghostzones;\n int const nughostzones = slab->ubbox or useghosts ? 0 : slab->nghostzones;\n bbox->off = slab->lbnd + nlghostzones;\n bbox->len = slab->lsh - nlghostzones - nughostzones;\n bbox->alen = slab->ash;\n bbox->str = 1;\n bbox_check(bbox);\n}\n\nstatic void slab2bbox(slabinfo const *restrict const slab,\n bbox *restrict const bbox) {\n assert(slab);\n assert(bbox);\n bbox->off = slab->off;\n bbox->len = slab->len;\n // bbox->alen = slab->len;\n bbox->alen = 1000000; // undefined\n bbox->str = slab->str;\n bbox_check(bbox);\n}\n\nstatic int bbox_iscontained(bbox const *restrict const inner,\n bbox const *restrict const outer) {\n bbox_check(inner);\n bbox_check(outer);\n int const inner_last = inner->off + (inner->len - 1) * inner->str;\n int const outer_last = outer->off + (outer->len - 1) * outer->str;\n return inner->off >= outer->off and inner_last <= outer_last;\n}\n\nstatic void bbox_clip(bbox *restrict const inner,\n bbox const *restrict const outer) {\n bbox_check(inner);\n bbox_check(outer);\n int inner_last = inner->off + (inner->len - 1) * inner->str;\n int const outer_last = outer->off + (outer->len - 1) * outer->str;\n if (inner->off < outer->off) {\n inner->off += roundup(outer->off - inner->off, inner->str);\n }\n if (inner_last > outer_last) {\n inner_last -= roundup(inner_last - outer_last, inner->str);\n }\n assert((inner_last - inner->off) % inner->str == 0);\n if (inner_last >= inner->off) {\n inner->len = (inner_last - inner->off + inner->str) / inner->str;\n } else {\n inner->len = 0;\n }\n bbox_check(inner);\n}\n\n// ydst = xdst + Flip (ysrc - xsrc)]\n// This function is its own inverse.\nstatic void bbox_xform(bbox *restrict const ydst,\n bbox const *restrict const ysrc,\n bbox const *restrict const xdst,\n bbox const *restrict const xsrc, int const flip) {\n assert(ydst);\n bbox_check(ysrc);\n bbox_check(xdst);\n bbox_check(xsrc);\n assert(ysrc->str == xsrc->str);\n /* int const xsrc_last = xsrc->off + (xsrc->len - 1) * xsrc->str; */\n int const xdst_last = xdst->off + (xdst->len - 1) * xdst->str;\n int const ysrc_last = ysrc->off + (ysrc->len - 1) * ysrc->str;\n ydst->str = xdst->str;\n assert((ysrc->off - xsrc->off) % ysrc->str == 0);\n ydst->off = xdst->off + (ysrc->off - xsrc->off) / ysrc->str * ydst->str;\n int ydst_last = xdst->off + (ysrc_last - xsrc->off) / ysrc->str * ydst->str;\n if (flip) {\n int const off = ydst->off;\n int const last = ydst_last;\n ydst->off = xdst->off + xdst_last - last;\n ydst_last = xdst_last - (off - xdst->off);\n }\n assert((ysrc_last - xsrc->off) % ysrc->str == 0);\n assert(ydst_last - ydst->off + ydst->str >= 0);\n ydst->len = (ydst_last - ydst->off + ydst->str) / ydst->str;\n ydst->alen = xdst->alen;\n bbox_check(ydst);\n}\n\nextern \"C\" void print_slabinfo(FILE *const out,\n slabinfo const *restrict const slabinfo) {\n fprintf(out, \" gsh: %d\\n\", slabinfo->gsh);\n fprintf(out, \" lbnd: %d, lsh: %d\\n\", slabinfo->lbnd, slabinfo->lsh);\n fprintf(out, \" ash: %d\\n\", slabinfo->ash);\n fprintf(out, \" lbbox: %d, ubbox: %d, nghostzones: %d\\n\", slabinfo->lbbox,\n slabinfo->ubbox, slabinfo->nghostzones);\n fprintf(out, \" off: %d, str: %d, len: %d\\n\", slabinfo->off, slabinfo->str,\n slabinfo->len);\n}\n\nextern \"C\" void print_xferinfo(FILE *const out,\n xferinfo const *restrict const xferinfo) {\n fprintf(out, \" src:\\n\");\n print_slabinfo(out, &xferinfo->src);\n fprintf(out, \" dst:\\n\");\n print_slabinfo(out, &xferinfo->dst);\n fprintf(out, \" xpose: %d\\n\", xferinfo->xpose);\n fprintf(out, \" flip: %d\\n\", xferinfo->flip);\n}\n\n// workhorse routines for the actual copying transposing, and flipping\n// of data\ntemplate <typename T>\ninline void copy_data(const vector<xfer> &info, const vector<bbox> &srcdetail,\n const vector<ptrdiff_t> &srcoffset,\n const vector<ptrdiff_t> &srcelems, vector<char> &srcdata,\n void const *restrict const *restrict const srcptrs,\n const int n, const vector<int> &varis, const int nvaris,\n const int xpose_x, const int xpose_y, const int xpose_z) {\n assert(srcptrs);\n\n ptrdiff_t const srcoffi = info[0].src.local.off;\n ptrdiff_t const srcoffj = info[1].src.local.off;\n ptrdiff_t const srcoffk = info[2].src.local.off;\n\n ptrdiff_t const srcleni = info[0].src.local.len;\n ptrdiff_t const srclenj = info[1].src.local.len;\n ptrdiff_t const srclenk = info[2].src.local.len;\n\n ptrdiff_t const srcaleni = info[0].src.local.alen;\n ptrdiff_t const srcalenj = info[1].src.local.alen;\n ptrdiff_t const srcalenk = info[2].src.local.alen;\n\n ptrdiff_t const srcdetailoffi = srcdetail[n * SLAB_MAXDIM + 0].off;\n ptrdiff_t const srcdetailoffj = srcdetail[n * SLAB_MAXDIM + 1].off;\n ptrdiff_t const srcdetailoffk = srcdetail[n * SLAB_MAXDIM + 2].off;\n\n ptrdiff_t const srcdetailleni = srcdetail[n * SLAB_MAXDIM + 0].len;\n ptrdiff_t const srcdetaillenj = srcdetail[n * SLAB_MAXDIM + 1].len;\n ptrdiff_t const srcdetaillenk = srcdetail[n * SLAB_MAXDIM + 2].len;\n\n ptrdiff_t const dstdetailleni = srcdetail[n * SLAB_MAXDIM + xpose_x].len;\n ptrdiff_t const dstdetaillenj = srcdetail[n * SLAB_MAXDIM + xpose_y].len;\n ptrdiff_t const dstdetaillenk = srcdetail[n * SLAB_MAXDIM + xpose_z].len;\n\n if (n == 0)\n assert(srcoffset[n] == 0);\n // TODO: This does not take nvaris into account\n // if (n<size-1) assert\n // (srcoffset[n+1]==srcoffset[n]+srcdetailleni*srcdetaillenj*srcdetaillenk);\n\n ifcheck {\n const int xpose[SLAB_MAXDIM] = {xpose_x, xpose_y, xpose_z};\n for (int i = 0; i < SLAB_MAXDIM; ++i) {\n for (int j = i + 1; j < SLAB_MAXDIM; ++j) {\n assert(xpose[i] != xpose[j]);\n }\n }\n }\n\n assert(dstdetailleni * dstdetaillenj * dstdetaillenk == srcelems[n]);\n if (srcelems[n] == 0)\n return;\n\n for (int vari = 0; vari < nvaris; ++vari) {\n T *restrict const srcdataptr =\n (T *)&srcdata.front() + srcoffset[n] + vari * srcelems[n];\n T const *restrict const srcptr = (T const *)srcptrs[varis[vari]];\n assert(srcptr);\n\n if (xpose_x == 0 and xpose_y == 1 and xpose_z == 2) {\n // no transposition\n\n CCTK_TimerStartI(timer_copy_in_noxpose);\n // #pragma omp parallel\n CCTK_LOOP3(Slab_copy_in_noxpose, i, j, k, 0, 0, 0, srcdetailleni,\n srcdetaillenj, srcdetaillenk, srcaleni, srcalenj, srcalenk) {\n ptrdiff_t const srcindi = srcdetailoffi + i - srcoffi;\n ptrdiff_t const srcindj = srcdetailoffj + j - srcoffj;\n ptrdiff_t const srcindk = srcdetailoffk + k - srcoffk;\n ifcheck assert(srcindi >= 0 and srcindi < srcleni);\n ifcheck assert(srcindj >= 0 and srcindj < srclenj);\n ifcheck assert(srcindk >= 0 and srcindk < srclenk);\n ptrdiff_t const srcind =\n srcindi + srcaleni * (srcindj + srcalenj * srcindk);\n ptrdiff_t const bufind = i + dstdetailleni * (j + dstdetaillenj * k);\n srcdataptr[bufind] = srcptr[srcind];\n }\n CCTK_ENDLOOP3(Slab_copy_in_noxpose);\n CCTK_TimerStopI(timer_copy_in_noxpose);\n\n } else if (xpose_x == 1 and xpose_y == 0 and xpose_z == 2) {\n // transpose x and y\n\n CCTK_TimerStartI(timer_copy_in_xposexy);\n // #pragma omp parallel\n // Interchange i and j loops\n CCTK_LOOP3(Slab_copy_in_xposexy, j, i, k, 0, 0, 0, srcdetaillenj,\n srcdetailleni, srcdetaillenk, srcalenj, srcaleni, srcalenk) {\n int const srcindi = srcdetailoffi + i - srcoffi;\n int const srcindj = srcdetailoffj + j - srcoffj;\n int const srcindk = srcdetailoffk + k - srcoffk;\n ifcheck assert(srcindi >= 0 and srcindi < srcleni);\n ifcheck assert(srcindj >= 0 and srcindj < srclenj);\n ifcheck assert(srcindk >= 0 and srcindk < srclenk);\n ptrdiff_t const srcind =\n srcindi + srcaleni * (srcindj + srcalenj * srcindk);\n ptrdiff_t const bufind = j + dstdetailleni * (i + dstdetaillenj * k);\n srcdataptr[bufind] = srcptr[srcind];\n }\n CCTK_ENDLOOP3(Slab_copy_in_xposexy);\n CCTK_TimerStopI(timer_copy_in_xposexy);\n\n } else {\n // general transposition\n\n CCTK_TimerStartI(timer_copy_in_xposegeneral);\n // #pragma omp parallel\n CCTK_LOOP3(Slab_copy_in_xposegeneral, i, j, k, 0, 0, 0, srcdetailleni,\n srcdetaillenj, srcdetaillenk, srcaleni, srcalenj, srcalenk) {\n int ipos[SLAB_MAXDIM];\n ipos[0] = i;\n ipos[1] = j;\n ipos[2] = k;\n int const srcindi = srcdetailoffi + i - srcoffi;\n int const srcindj = srcdetailoffj + j - srcoffj;\n int const srcindk = srcdetailoffk + k - srcoffk;\n ifcheck assert(srcindi >= 0 and srcindi < srcleni);\n ifcheck assert(srcindj >= 0 and srcindj < srclenj);\n ifcheck assert(srcindk >= 0 and srcindk < srclenk);\n ptrdiff_t const srcind =\n srcindi + srcaleni * (srcindj + srcalenj * srcindk);\n // TODO: rewrite this, moving the index onto dstdetaillen and\n // outside the loop; then collapse all loop specialisations\n ptrdiff_t const bufind =\n (ipos[xpose_x] +\n dstdetailleni * (ipos[xpose_y] + dstdetaillenj * ipos[xpose_z]));\n srcdataptr[bufind] = srcptr[srcind];\n }\n CCTK_ENDLOOP3(Slab_copy_in_xposegeneral);\n CCTK_TimerStopI(timer_copy_in_xposegeneral);\n }\n\n } // for vari\n}\n\n// workhorse routine responsible for the actual copying/flipping of data\ntemplate <typename T>\ninline void\ncopy_data_back(const vector<xfer> &info, const vector<bbox> &dstdetail,\n const vector<ptrdiff_t> &dstoffset,\n const vector<ptrdiff_t> &dstelems, const vector<char> &dstdata,\n void *restrict const *restrict const dstptrs, const int n,\n const vector<int> &varis, const int nvaris, const bool flip_x,\n const bool flip_y, const bool flip_z) {\n assert(dstptrs);\n\n ptrdiff_t const dstoffi = info[0].dst.local.off;\n ptrdiff_t const dstoffj = info[1].dst.local.off;\n ptrdiff_t const dstoffk = info[2].dst.local.off;\n\n ptrdiff_t const dstleni = info[0].dst.local.len;\n ptrdiff_t const dstlenj = info[1].dst.local.len;\n ptrdiff_t const dstlenk = info[2].dst.local.len;\n\n ptrdiff_t const dstaleni = info[0].dst.local.alen;\n ptrdiff_t const dstalenj = info[1].dst.local.alen;\n ptrdiff_t const dstalenk = info[2].dst.local.alen;\n\n ptrdiff_t const dstdetailoffi = dstdetail[n * SLAB_MAXDIM + 0].off;\n ptrdiff_t const dstdetailoffj = dstdetail[n * SLAB_MAXDIM + 1].off;\n ptrdiff_t const dstdetailoffk = dstdetail[n * SLAB_MAXDIM + 2].off;\n\n ptrdiff_t const dstdetailleni = dstdetail[n * SLAB_MAXDIM + 0].len;\n ptrdiff_t const dstdetaillenj = dstdetail[n * SLAB_MAXDIM + 1].len;\n ptrdiff_t const dstdetaillenk = dstdetail[n * SLAB_MAXDIM + 2].len;\n\n assert(dstdetailleni * dstdetaillenj * dstdetaillenk == dstelems[n]);\n if (dstelems[n] == 0)\n return;\n\n for (int vari = 0; vari < nvaris; ++vari) {\n T *restrict const dstptr = (T * restrict)dstptrs[varis[vari]];\n assert(dstptr);\n T const *restrict const dstdataptr =\n (T const *)&dstdata.front() + dstoffset[n] + vari * dstelems[n];\n\n if (not flip_x and not flip_y and not flip_z) {\n // no flipping\n\n CCTK_TimerStartI(timer_copy_back_noflip);\n // #pragma omp parallel\n CCTK_LOOP3(Slab_copy_back_noflip, i, j, k, 0, 0, 0, dstdetailleni,\n dstdetaillenj, dstdetaillenk, dstaleni, dstalenj, dstalenk) {\n ptrdiff_t const dstindi = dstdetailoffi + i - dstoffi;\n ptrdiff_t const dstindj = dstdetailoffj + j - dstoffj;\n ptrdiff_t const dstindk = dstdetailoffk + k - dstoffk;\n ifcheck assert(dstindi >= 0 and dstindi < dstleni);\n ifcheck assert(dstindj >= 0 and dstindj < dstlenj);\n ifcheck assert(dstindk >= 0 and dstindk < dstlenk);\n ptrdiff_t const dstind =\n dstindi + dstaleni * (dstindj + dstalenj * dstindk);\n ptrdiff_t const bufind = i + dstdetailleni * (j + dstdetaillenj * k);\n dstptr[dstind] = dstdataptr[bufind];\n }\n CCTK_ENDLOOP3(Slab_copy_back_noflip);\n CCTK_TimerStopI(timer_copy_back_noflip);\n\n } else if (flip_x and not flip_y and not flip_z) {\n // flip in x direction\n\n CCTK_TimerStartI(timer_copy_back_flipx);\n // #pragma omp parallel\n CCTK_LOOP3(Slab_copy_back_flipx, i, j, k, 0, 0, 0, dstdetailleni,\n dstdetaillenj, dstdetaillenk, dstaleni, dstalenj, dstalenk) {\n ptrdiff_t const dstindi =\n dstdetailoffi + (dstdetailleni - 1 - i) - dstoffi;\n ptrdiff_t const dstindj = dstdetailoffj + j - dstoffj;\n ptrdiff_t const dstindk = dstdetailoffk + k - dstoffk;\n ifcheck assert(dstindi >= 0 and dstindi < dstleni);\n ifcheck assert(dstindj >= 0 and dstindj < dstlenj);\n ifcheck assert(dstindk >= 0 and dstindk < dstlenk);\n ptrdiff_t const dstind =\n dstindi + dstaleni * (dstindj + dstalenj * dstindk);\n ptrdiff_t const bufind = i + dstdetailleni * (j + dstdetaillenj * k);\n dstptr[dstind] = dstdataptr[bufind];\n }\n CCTK_ENDLOOP3(Slab_copy_back_flipx);\n CCTK_TimerStopI(timer_copy_back_flipx);\n\n } else if (not flip_x and flip_y and not flip_z) {\n // flip in y direction\n\n CCTK_TimerStartI(timer_copy_back_flipy);\n // #pragma omp parallel\n CCTK_LOOP3(Slab_copy_back_flipy, i, j, k, 0, 0, 0, dstdetailleni,\n dstdetaillenj, dstdetaillenk, dstaleni, dstalenj, dstalenk) {\n ptrdiff_t const dstindi = dstdetailoffi + i - dstoffi;\n ptrdiff_t const dstindj =\n dstdetailoffj + (dstdetaillenj - 1 - j) - dstoffj;\n ptrdiff_t const dstindk = dstdetailoffk + k - dstoffk;\n ifcheck assert(dstindi >= 0 and dstindi < dstleni);\n ifcheck assert(dstindj >= 0 and dstindj < dstlenj);\n ifcheck assert(dstindk >= 0 and dstindk < dstlenk);\n ptrdiff_t const dstind =\n dstindi + dstaleni * (dstindj + dstalenj * dstindk);\n ptrdiff_t const bufind = i + dstdetailleni * (j + dstdetaillenj * k);\n dstptr[dstind] = dstdataptr[bufind];\n }\n CCTK_ENDLOOP3(Slab_copy_back_flipy);\n CCTK_TimerStopI(timer_copy_back_flipy);\n\n } else if (flip_x and flip_y and not flip_z) {\n // flip in both x and y direction\n\n CCTK_TimerStartI(timer_copy_back_flipxy);\n // #pragma omp parallel\n CCTK_LOOP3(Slab_copy_back_flipxy, i, j, k, 0, 0, 0, dstdetailleni,\n dstdetaillenj, dstdetaillenk, dstaleni, dstalenj, dstalenk) {\n ptrdiff_t const dstindi =\n dstdetailoffi + (dstdetailleni - 1 - i) - dstoffi;\n ptrdiff_t const dstindj =\n dstdetailoffj + (dstdetaillenj - 1 - j) - dstoffj;\n ptrdiff_t const dstindk = dstdetailoffk + k - dstoffk;\n ifcheck assert(dstindi >= 0 and dstindi < dstleni);\n ifcheck assert(dstindj >= 0 and dstindj < dstlenj);\n ifcheck assert(dstindk >= 0 and dstindk < dstlenk);\n ptrdiff_t const dstind =\n dstindi + dstaleni * (dstindj + dstalenj * dstindk);\n ptrdiff_t const bufind = i + dstdetailleni * (j + dstdetaillenj * k);\n dstptr[dstind] = dstdataptr[bufind];\n }\n CCTK_ENDLOOP3(Slab_copy_back_flipxy);\n CCTK_TimerStopI(timer_copy_back_flipxy);\n\n } else {\n // general flipping\n\n CCTK_TimerStartI(timer_copy_back_flipgeneral);\n // #pragma omp parallel\n CCTK_LOOP3(Slab_copy_back_flipgeneral, i, j, k, 0, 0, 0, dstdetailleni,\n dstdetaillenj, dstdetaillenk, dstaleni, dstalenj, dstalenk) {\n // TODO: rewrite this, moving the flipping onto dstlen and\n // outside the loop; then collapse all loop specialisations\n ptrdiff_t const dstindi =\n dstdetailoffi + (flip_x ? dstdetailleni - 1 - i : i) - dstoffi;\n ptrdiff_t const dstindj =\n dstdetailoffj + (flip_y ? dstdetaillenj - 1 - j : j) - dstoffj;\n ptrdiff_t const dstindk =\n dstdetailoffk + (flip_z ? dstdetaillenk - 1 - k : k) - dstoffk;\n ifcheck assert(dstindi >= 0 and dstindi < dstleni);\n ifcheck assert(dstindj >= 0 and dstindj < dstlenj);\n ifcheck assert(dstindk >= 0 and dstindk < dstlenk);\n ptrdiff_t const dstind =\n dstindi + dstaleni * (dstindj + dstalenj * dstindk);\n ptrdiff_t const bufind = i + dstdetailleni * (j + dstdetaillenj * k);\n dstptr[dstind] = dstdataptr[bufind];\n }\n CCTK_ENDLOOP3(Slab_copy_back_flipgeneral);\n CCTK_TimerStopI(timer_copy_back_flipgeneral);\n }\n\n } // for vari\n}\n\nstruct slabsetup {\n MPI_Comm comm;\n vector<xfer> info;\n vector<xfer> allinfo;\n vector<bbox> srcdetail, dstdetail;\n ptrdiff_t srclentot, dstlentot;\n};\n\nextern \"C\" slabsetup *\nSlab_MultiTransfer_Init(cGH const *restrict const cctkGH, int const dim,\n xferinfo const *restrict const xferinfo,\n int const options) {\n DECLARE_CCTK_PARAMETERS;\n\n // Check arguments\n check(cctkGH);\n check(dim >= 0);\n check(xferinfo);\n\n CCTK_TimerStartI(timer_init);\n\n slabsetup *restrict const slabsetup = new struct slabsetup;\n\n bool useghosts;\n {\n CCTK_INT tmp;\n int const iret = Util_TableGetInt(options, &tmp, \"useghosts\");\n if (iret == 1) {\n // There was an entry, use it\n useghosts = tmp;\n } else if (iret == UTIL_ERROR_BAD_HANDLE or\n iret == UTIL_ERROR_TABLE_NO_SUCH_KEY) {\n // There was no entry, use a default\n useghosts = false;\n } else {\n // Something went wrong, abort\n check(0);\n }\n }\n\n check(dim <= SLAB_MAXDIM);\n vector<xfer> &info = slabsetup->info;\n info.resize(SLAB_MAXDIM);\n for (int d = 0; d < dim; ++d) {\n global2bbox(&xferinfo[d].src, &info[d].src.global);\n local2bbox(&xferinfo[d].src, &info[d].src.local);\n active2bbox(&xferinfo[d].src, &info[d].src.active, useghosts);\n slab2bbox(&xferinfo[d].src, &info[d].src.slab);\n check(bbox_iscontained(&info[d].src.active, &info[d].src.local));\n check(bbox_iscontained(&info[d].src.local, &info[d].src.global));\n\n global2bbox(&xferinfo[d].dst, &info[d].dst.global);\n local2bbox(&xferinfo[d].dst, &info[d].dst.local);\n active2bbox(&xferinfo[d].dst, &info[d].dst.active, 1); // fill ghosts\n slab2bbox(&xferinfo[d].dst, &info[d].dst.slab);\n check(bbox_iscontained(&info[d].dst.active, &info[d].dst.local));\n check(bbox_iscontained(&info[d].dst.local, &info[d].dst.global));\n\n info[d].xpose = xferinfo[d].xpose;\n check(info[d].xpose >= 0 and info[d].xpose < dim);\n info[d].flip = xferinfo[d].flip;\n check(info[d].flip == 0 or info[d].flip == 1);\n }\n for (int d = dim; d < SLAB_MAXDIM; ++d) {\n static bbox const fake_bbox = {0, 1, 1, 1};\n static arrays const fake_arrays = {\n {0, 1, 1, 1}, {0, 1, 1, 1}, {0, 1, 1, 1}, {0, 1, 1, 1}};\n\n bbox_check(&fake_bbox);\n\n info[d].src = fake_arrays;\n check(bbox_iscontained(&info[d].src.active, &info[d].src.local));\n check(bbox_iscontained(&info[d].src.local, &info[d].src.global));\n\n info[d].dst = fake_arrays;\n check(bbox_iscontained(&info[d].dst.active, &info[d].dst.local));\n check(bbox_iscontained(&info[d].dst.local, &info[d].dst.global));\n\n info[d].xpose = d;\n check(info[d].xpose >= 0 and info[d].xpose < SLAB_MAXDIM);\n info[d].flip = 0;\n check(info[d].flip == 0 or info[d].flip == 1);\n }\n\n ifcheck {\n ifdebug printf(\"srcinfo:\\n\");\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n printf(\" src.global d=%d \", d);\n bbox_print(&info[d].src.global);\n printf(\"\\n\");\n printf(\" src.local d=%d \", d);\n bbox_print(&info[d].src.local);\n printf(\"\\n\");\n printf(\" src.active d=%d \", d);\n bbox_print(&info[d].src.active);\n printf(\"\\n\");\n printf(\" src.slab d=%d \", d);\n bbox_print(&info[d].src.slab);\n printf(\"\\n\");\n }\n ifdebug printf(\"dstinfo:\\n\");\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n printf(\" dst.global d=%d \", d);\n bbox_print(&info[d].dst.global);\n printf(\"\\n\");\n printf(\" dst.local d=%d \", d);\n bbox_print(&info[d].dst.local);\n printf(\"\\n\");\n printf(\" dst.active d=%d \", d);\n bbox_print(&info[d].dst.active);\n printf(\"\\n\");\n printf(\" dst.slab d=%d \", d);\n bbox_print(&info[d].dst.slab);\n printf(\"\\n\");\n }\n ifdebug printf(\"info:\\n\");\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n printf(\" xpose d=%d %d\\n\", d, info[d].xpose);\n printf(\" flip d=%d %d\\n\", d, info[d].flip);\n }\n }\n\n {\n bool iflag[SLAB_MAXDIM];\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n iflag[d] = false;\n }\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n assert(not iflag[info[d].xpose]);\n iflag[info[d].xpose] = true;\n }\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n assert(iflag[d]);\n }\n // Allow non-contributing processors to be non-knowledgeable\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n if (info[info[d].xpose].src.slab.len and info[d].dst.slab.len > 0) {\n assert(info[info[d].xpose].src.slab.len == info[d].dst.slab.len);\n }\n }\n }\n\n ptrdiff_t &srclentot = slabsetup->srclentot;\n ptrdiff_t &dstlentot = slabsetup->dstlentot;\n srclentot = 1;\n dstlentot = 1;\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n srclentot *= info[d].src.local.len;\n dstlentot *= info[d].dst.local.len;\n }\n\n MPI_Comm &comm = slabsetup->comm;\n {\n CCTK_POINTER_TO_CONST tmp1;\n int const iret1 = Util_TableGetPointerToConst(options, &tmp1, \"comm\");\n if (iret1 == 1) {\n // There was an entry, use it\n comm = *(MPI_Comm const *)tmp1;\n } else if (iret1 == UTIL_ERROR_TABLE_WRONG_DATA_TYPE) {\n // Entry has wrong type, fall back\n CCTK_POINTER tmp2;\n int const iret2 = Util_TableGetPointer(options, &tmp2, \"comm\");\n if (iret2 == 1) {\n // There was an entry, use it\n comm = *(MPI_Comm const *)tmp2;\n } else {\n // Something went wrong, abort\n check(0);\n }\n } else if (iret1 == UTIL_ERROR_BAD_HANDLE or\n iret1 == UTIL_ERROR_TABLE_NO_SUCH_KEY) {\n // There was no entry, use a default\n comm = get_mpi_comm(cctkGH);\n } else {\n // Something went wrong, abort\n check(0);\n }\n }\n\n ifcheck {\n ifdebug fflush(stdout);\n MPI_Barrier(comm);\n }\n\n int size, rank;\n MPI_Comm_size(comm, &size);\n MPI_Comm_rank(comm, &rank);\n\n ifcheck {\n static int count = 424242;\n int mycount = count;\n ifdebug fflush(stdout);\n MPI_Bcast(&mycount, 1, MPI_INT, 0, comm);\n assert(mycount == count);\n ++count;\n }\n\n vector<xfer> &allinfo = slabsetup->allinfo;\n allinfo.resize(size * SLAB_MAXDIM);\n {\n int const info_nints = sizeof(xfer) / sizeof(int);\n ifdebug fflush(stdout);\n MPI_Allgather(&info.front(), SLAB_MAXDIM * info_nints, MPI_INT,\n &allinfo.front(), SLAB_MAXDIM * info_nints, MPI_INT, comm);\n }\n\n for (int n = 0; n < size; ++n) {\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n // Allow non-contributing processors to be non-knowledgeable\n if (allinfo[n * SLAB_MAXDIM + d].src.slab.len > 0 and\n info[d].src.slab.len > 0) {\n assert(allinfo[n * SLAB_MAXDIM + d].src.global.off ==\n info[d].src.global.off);\n assert(allinfo[n * SLAB_MAXDIM + d].src.global.len ==\n info[d].src.global.len);\n assert(allinfo[n * SLAB_MAXDIM + d].src.global.str ==\n info[d].src.global.str);\n assert(allinfo[n * SLAB_MAXDIM + d].src.local.str ==\n info[d].src.local.str);\n assert(allinfo[n * SLAB_MAXDIM + d].src.active.str ==\n info[d].src.active.str);\n // 2003-03-01 eschnett: I don't know why the following should\n // be necessary\n assert(allinfo[n * SLAB_MAXDIM + d].src.slab.str ==\n info[d].src.slab.str);\n }\n if (allinfo[n * SLAB_MAXDIM + d].dst.slab.len > 0 and\n info[d].dst.slab.len > 0) {\n assert(allinfo[n * SLAB_MAXDIM + d].dst.global.off ==\n info[d].dst.global.off);\n assert(allinfo[n * SLAB_MAXDIM + d].dst.global.len ==\n info[d].dst.global.len);\n assert(allinfo[n * SLAB_MAXDIM + d].dst.global.str ==\n info[d].dst.global.str);\n assert(allinfo[n * SLAB_MAXDIM + d].dst.local.str ==\n info[d].dst.local.str);\n assert(allinfo[n * SLAB_MAXDIM + d].dst.active.str ==\n info[d].dst.active.str);\n assert(allinfo[n * SLAB_MAXDIM + d].dst.slab.str ==\n info[d].dst.slab.str);\n }\n assert(allinfo[n * SLAB_MAXDIM + d].xpose == info[d].xpose);\n assert(allinfo[n * SLAB_MAXDIM + d].flip == info[d].flip);\n }\n }\n\n vector<bbox> &srcdetail = slabsetup->srcdetail;\n srcdetail.resize(size * SLAB_MAXDIM);\n for (int n = 0; n < size; ++n) {\n ifdebug printf(\"srcdetail n=%d:\\n\", n);\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n srcdetail[n * SLAB_MAXDIM + d] = allinfo[n * SLAB_MAXDIM + d].src.slab;\n ifdebug printf(\" src.slab d=%d \", d);\n ifdebug bbox_print(&srcdetail[n * SLAB_MAXDIM + d]);\n ifdebug printf(\"\\n\");\n bbox_clip(&srcdetail[n * SLAB_MAXDIM + d], &info[d].src.active);\n ifdebug printf(\" clipped with src.active d=%d \", d);\n ifdebug bbox_print(&srcdetail[n * SLAB_MAXDIM + d]);\n ifdebug printf(\"\\n\");\n }\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n bbox whereto;\n bbox wherefrom;\n whereto = allinfo[n * SLAB_MAXDIM + d].dst.slab;\n ifdebug printf(\" dst.slab d=%d \", info[d].xpose);\n ifdebug bbox_print(&whereto);\n ifdebug printf(\"\\n\");\n bbox_clip(&whereto, &allinfo[n * SLAB_MAXDIM + d].dst.active);\n ifdebug printf(\" whereto d=%d \", info[d].xpose);\n ifdebug bbox_print(&whereto);\n ifdebug printf(\"\\n\");\n bbox_xform(&wherefrom, &whereto,\n &allinfo[n * SLAB_MAXDIM + info[d].xpose].src.slab,\n &allinfo[n * SLAB_MAXDIM + d].dst.slab, info[d].flip);\n ifdebug printf(\" wherefrom d=%d \", info[d].xpose);\n ifdebug bbox_print(&wherefrom);\n ifdebug printf(\"\\n\");\n bbox_clip(&srcdetail[n * SLAB_MAXDIM + info[d].xpose], &wherefrom);\n ifdebug printf(\" clipped with wherefrom d=%d \", info[d].xpose);\n ifdebug bbox_print(&srcdetail[n * SLAB_MAXDIM + info[d].xpose]);\n ifdebug printf(\"\\n\");\n }\n }\n\n vector<bbox> &dstdetail = slabsetup->dstdetail;\n dstdetail.resize(size * SLAB_MAXDIM);\n for (int n = 0; n < size; ++n) {\n ifdebug printf(\"dstdetail n=%d:\\n\", n);\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n // dstdetail[n*SLAB_MAXDIM+d] = allinfo[n*SLAB_MAXDIM+d].dst.slab;\n dstdetail[n * SLAB_MAXDIM + d] = info[d].dst.slab;\n ifdebug printf(\" dst.slab d=%d \", d);\n ifdebug bbox_print(&dstdetail[n * SLAB_MAXDIM + d]);\n ifdebug printf(\"\\n\");\n bbox_clip(&dstdetail[n * SLAB_MAXDIM + d], &info[d].dst.active);\n ifdebug printf(\" clipped with dst.active d=%d \", d);\n ifdebug bbox_print(&dstdetail[n * SLAB_MAXDIM + d]);\n ifdebug printf(\"\\n\");\n }\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n bbox wherefrom;\n bbox whereto;\n // wherefrom = allinfo[n*SLAB_MAXDIM+info[d].xpose].src.slab;\n wherefrom = info[info[d].xpose].src.slab;\n ifdebug printf(\" src.slab d=%d \", d);\n // ifdebug bbox_print (&dstdetail[n*SLAB_MAXDIM+d]);\n ifdebug bbox_print(&wherefrom);\n ifdebug printf(\"\\n\");\n bbox_clip(&wherefrom,\n &allinfo[n * SLAB_MAXDIM + info[d].xpose].src.active);\n ifdebug printf(\" wherefrom d=%d \", d);\n // ifdebug bbox_print (&dstdetail[n*SLAB_MAXDIM+d]);\n ifdebug bbox_print(&wherefrom);\n ifdebug printf(\"\\n\");\n bbox_xform(&whereto, &wherefrom, &allinfo[n * SLAB_MAXDIM + d].dst.slab,\n // &allinfo[n*SLAB_MAXDIM+info[d].xpose].src.slab,\n &info[info[d].xpose].src.slab, info[d].flip);\n ifdebug printf(\" whereto d=%d \", d);\n // ifdebug bbox_print (&dstdetail[n*SLAB_MAXDIM+d]);\n ifdebug bbox_print(&whereto);\n ifdebug printf(\"\\n\");\n bbox_clip(&dstdetail[n * SLAB_MAXDIM + d], &whereto);\n ifdebug printf(\" clipped with whereto d=%d \", d);\n ifdebug bbox_print(&dstdetail[n * SLAB_MAXDIM + d]);\n ifdebug printf(\"\\n\");\n }\n }\n\n CCTK_TimerStopI(timer_init);\n\n return slabsetup;\n}\n\nextern \"C\" int\nSlab_MultiTransfer_Apply(cGH const *restrict const cctkGH,\n slabsetup const *restrict const slabsetup,\n int const nvars, int const *restrict const srctypes,\n void const *restrict const *restrict const srcptrs,\n int const *restrict const dsttypes,\n void *restrict const *restrict const dstptrs) {\n DECLARE_CCTK_PARAMETERS;\n\n // Check arguments\n check(cctkGH);\n check(slabsetup);\n check(nvars >= 0);\n check(nvars == 0 or srctypes);\n for (int var = 0; var < nvars; ++var)\n check(srctypes[var] >= 0);\n check(nvars == 0 or srcptrs);\n ptrdiff_t const &srclentot = slabsetup->srclentot;\n for (int var = 0; var < nvars; ++var)\n if (srclentot > 0)\n assert(srcptrs[var]);\n check(nvars == 0 or dsttypes);\n for (int var = 0; var < nvars; ++var)\n check(dsttypes[var] >= 0);\n check(nvars == 0 or dstptrs);\n ptrdiff_t const &dstlentot = slabsetup->dstlentot;\n for (int var = 0; var < nvars; ++var)\n if (dstlentot > 0)\n assert(dstptrs[var]);\n\n if (nvars == 0)\n return 0;\n\n CCTK_TimerStartI(timer_apply);\n\n MPI_Comm const &comm = slabsetup->comm;\n\n ifcheck {\n ifdebug fflush(stdout);\n MPI_Barrier(comm);\n }\n\n int size, rank;\n MPI_Comm_size(comm, &size);\n MPI_Comm_rank(comm, &rank);\n\n ifcheck {\n static int count = 424242;\n int mycount = count;\n ifdebug fflush(stdout);\n MPI_Bcast(&mycount, 1, MPI_INT, 0, comm);\n assert(mycount == count);\n ++count;\n }\n\n vector<xfer> const &info = slabsetup->info;\n vector<xfer> const &allinfo = slabsetup->allinfo;\n vector<bbox> const &srcdetail = slabsetup->srcdetail;\n vector<bbox> const &dstdetail = slabsetup->dstdetail;\n\n vector<ptrdiff_t> srcelems(size);\n vector<ptrdiff_t> srccount(size);\n vector<ptrdiff_t> srcoffset(size + 1);\n\n vector<ptrdiff_t> dstelems(size);\n vector<ptrdiff_t> dstcount(size);\n vector<ptrdiff_t> dstoffset(size + 1);\n\n int nvartypes = 0;\n vector<int> vartypes(nvars);\n vector<int> vartypecount(nvars);\n for (int var = 0; var < nvars; ++var) {\n int const srctype = srctypes[var];\n int const dsttype = dsttypes[var];\n check(srctype == dsttype);\n int vartypei;\n for (vartypei = 0; vartypei < nvartypes; ++vartypei) {\n if (srctype == vartypes[vartypei])\n break;\n }\n if (vartypei >= nvartypes) {\n vartypes[nvartypes] = srctype;\n vartypecount[nvartypes] = 0;\n ++nvartypes;\n }\n assert(vartypei < nvartypes);\n ++vartypecount[vartypei];\n }\n\n for (int vartypei = 0; vartypei < nvartypes; ++vartypei) {\n int const vartype = vartypes[vartypei];\n int nvaris = 0;\n vector<int> varis(nvars);\n for (int var = 0; var < nvars; ++var) {\n if (srctypes[var] == vartype) {\n varis[nvaris] = var;\n ++nvaris;\n }\n }\n assert(nvaris == vartypecount[vartypei]);\n assert(nvaris > 0);\n\n ptrdiff_t const vartypesize = CCTK_VarTypeSize(vartype);\n check(vartypesize > 0);\n MPI_Datatype const vardatatype = mpi_type(vartype);\n\n srcoffset[0] = 0;\n for (int n = 0; n < size; ++n) {\n srcelems[n] = 1;\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n srcelems[n] *= srcdetail[n * SLAB_MAXDIM + d].len;\n }\n srccount[n] = nvaris * srcelems[n];\n ifdebug printf(\"srccnt n=%d offset=%td count=%td\\n\", n, srcoffset[n],\n srccount[n]);\n srcoffset[n + 1] = srcoffset[n] + srccount[n];\n }\n vector<char> srcdata(srcoffset[size] * vartypesize);\n ifcheck {\n if (vartype == CCTK_VARIABLE_REAL) {\n CCTK_REAL *restrict const srcdataptr = (CCTK_REAL *)&srcdata.front();\n CCTK_REAL marker;\n memset(&marker, POISON_VALUE, sizeof marker);\n for (int i = 0; i < srcoffset[size]; ++i) {\n memcpy(&srcdataptr[i], &marker, sizeof marker);\n }\n }\n }\n\n dstoffset[0] = 0;\n for (int n = 0; n < size; ++n) {\n dstelems[n] = 1;\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n dstelems[n] *= dstdetail[n * SLAB_MAXDIM + d].len;\n }\n dstcount[n] = nvaris * dstelems[n];\n ifdebug printf(\"dstcnt n=%d offset=%td count=%td\\n\", n, dstoffset[n],\n dstcount[n]);\n dstoffset[n + 1] = dstoffset[n] + dstcount[n];\n }\n vector<char> dstdata(dstoffset[size] * vartypesize);\n ifcheck {\n if (vartype == CCTK_VARIABLE_REAL) {\n CCTK_REAL *restrict const dstdataptr = (CCTK_REAL *)&dstdata.front();\n CCTK_REAL marker;\n memset(&marker, POISON_VALUE, sizeof marker);\n for (int i = 0; i < dstoffset[size]; ++i) {\n memcpy(&dstdataptr[i], &marker, sizeof marker);\n }\n }\n }\n\n check(srccount[rank] == dstcount[rank]);\n\n ifcheck {\n vector<long long> src2count(size);\n vector<long long> dst2count(size);\n ifdebug fflush(stdout);\n MPI_Alltoall(&srccount.front(), 1, MPI_LONG_LONG, &src2count.front(), 1,\n MPI_LONG_LONG, comm);\n MPI_Alltoall(&dstcount.front(), 1, MPI_LONG_LONG, &dst2count.front(), 1,\n MPI_LONG_LONG, comm);\n for (int n = 0; n < size; ++n) {\n check(src2count[n] == dstcount[n]);\n check(dst2count[n] == srccount[n]);\n }\n }\n\n CCTK_TimerStartI(timer_copy_in);\n\n for (int n = 0; n < size; ++n) {\n check(SLAB_MAXDIM == 3);\n\n if (srcdetail[n * SLAB_MAXDIM].str == 1 and\n srcdetail[n * SLAB_MAXDIM + 1].str == 1 and\n srcdetail[n * SLAB_MAXDIM + 2].str == 1 and\n vartype == CCTK_VARIABLE_REAL) {\n // Optimised for stride 1 and CCTK_REAL\n copy_data<CCTK_REAL>(info, srcdetail, srcoffset, srcelems, srcdata,\n srcptrs, n, varis, nvaris, info[0].xpose,\n info[1].xpose, info[2].xpose);\n } else if (srcdetail[n * SLAB_MAXDIM].str == 1 and\n srcdetail[n * SLAB_MAXDIM + 1].str == 1 and\n srcdetail[n * SLAB_MAXDIM + 2].str == 1 and\n vartype == CCTK_VARIABLE_COMPLEX) {\n // Optimised for stride 1 and CCTK_COMPLEX\n copy_data<CCTK_COMPLEX>(info, srcdetail, srcoffset, srcelems, srcdata,\n srcptrs, n, varis, nvaris, info[0].xpose,\n info[1].xpose, info[2].xpose);\n } else if (srcdetail[n * SLAB_MAXDIM].str == 1 and\n srcdetail[n * SLAB_MAXDIM + 1].str == 1 and\n srcdetail[n * SLAB_MAXDIM + 2].str == 1 and\n vartype == CCTK_VARIABLE_INT) {\n // Optimised for stride 1 and CCTK_INT\n copy_data<CCTK_INT>(info, srcdetail, srcoffset, srcelems, srcdata,\n srcptrs, n, varis, nvaris, info[0].xpose,\n info[1].xpose, info[2].xpose);\n } else {\n // Generic, unoptimised version\n CCTK_TimerStartI(timer_copy_in_general);\n\n ptrdiff_t const srcdetailleni =\n srcdetail[n * SLAB_MAXDIM + info[0].xpose].len;\n ptrdiff_t const srcdetaillenj =\n srcdetail[n * SLAB_MAXDIM + info[1].xpose].len;\n ptrdiff_t const srcdetaillenk =\n srcdetail[n * SLAB_MAXDIM + info[2].xpose].len;\n\n for (int vari = 0; vari < nvaris; ++vari) {\n char *restrict const srcdataptr =\n &srcdata[vartypesize * (srcoffset[n] + vari * srcelems[n])];\n char const *restrict const srcptr =\n (char const *)srcptrs[varis[vari]];\n\n // #pragma omp parallel for\n for (int k = 0; k < srcdetaillenk; ++k) {\n for (int j = 0; j < srcdetaillenj; ++j) {\n for (int i = 0; i < srcdetailleni; ++i) {\n ptrdiff_t ipos[SLAB_MAXDIM];\n ipos[0] = i;\n ipos[1] = j;\n ipos[2] = k;\n ptrdiff_t srcipos[SLAB_MAXDIM];\n ptrdiff_t bufipos[SLAB_MAXDIM];\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n int const c = info[d].xpose;\n srcipos[c] = srcdetail[n * SLAB_MAXDIM + c].off +\n ipos[d] * srcdetail[n * SLAB_MAXDIM + c].str;\n assert(srcipos[c] >= info[c].src.local.off and\n srcipos[c] <\n info[c].src.local.off + info[c].src.local.len);\n assert(\n srcipos[c] >=\n allinfo[n * SLAB_MAXDIM + c].src.slab.off and\n srcipos[c] <=\n allinfo[n * SLAB_MAXDIM + c].src.slab.off +\n (allinfo[n * SLAB_MAXDIM + c].src.slab.len - 1) *\n allinfo[n * SLAB_MAXDIM + c].src.slab.str);\n assert(\n (srcipos[c] - allinfo[n * SLAB_MAXDIM + c].src.slab.off) %\n allinfo[n * SLAB_MAXDIM + c].src.slab.str ==\n 0);\n bufipos[d] = ipos[d];\n assert(bufipos[d] >= 0 and\n bufipos[d] < srcdetail[n * SLAB_MAXDIM + c].len);\n }\n ptrdiff_t srcind = 0;\n ptrdiff_t bufind = 0;\n for (int d = SLAB_MAXDIM - 1; d >= 0; --d) {\n int const c = info[d].xpose;\n srcind = srcind * info[d].src.local.alen + srcipos[d] -\n info[d].src.local.off;\n bufind =\n bufind * srcdetail[n * SLAB_MAXDIM + c].len + bufipos[d];\n }\n assert(srcind < srclentot);\n assert(bufind < (ptrdiff_t)srccount[n]);\n memcpy(srcdataptr + vartypesize * bufind,\n srcptr + vartypesize * srcind, vartypesize);\n }\n }\n }\n\n } // for vari\n CCTK_TimerStopI(timer_copy_in_general);\n }\n } // for n\n\n ifcheck {\n if (vartype == CCTK_VARIABLE_REAL) {\n CCTK_REAL const *restrict const srcdataptr =\n (CCTK_REAL const *)&srcdata.front();\n CCTK_REAL marker;\n memset(&marker, POISON_VALUE, sizeof marker);\n for (int i = 0; i < srcoffset[size]; ++i) {\n assert(memcmp(&srcdataptr[i], &marker, sizeof marker) != 0);\n }\n }\n }\n CCTK_TimerStopI(timer_copy_in);\n\n CCTK_TimerStartI(timer_xfer);\n ifdebug fflush(stdout);\n if (not HAVE_MPI or use_alltoallv) {\n // MPI_Alltoallv does not support 64-bit integers\n CCTK_ERROR(\"Cannot use MPI_Alltoallv\");\n // MPI_Alltoallv(&srcdata.front(), &srccount.front(), &srcoffset.front(),\n // vardatatype, &dstdata.front(), &dstcount.front(),\n // &dstoffset.front(), vardatatype, comm);\n } else {\n vector<MPI_Request> requests;\n requests.reserve(2 * size);\n // Start receive\n for (int n = 0; n < size; ++n) {\n if (n != rank and dstcount[n] > 0) {\n ptrdiff_t offset = vartypesize * dstoffset[n];\n ptrdiff_t count = dstcount[n];\n while (count > 0) {\n ptrdiff_t thiscount =\n min(ptrdiff_t(numeric_limits<int>::max()), count);\n MPI_Request req;\n MPI_Irecv(&dstdata[offset], thiscount, vardatatype, n, 0, comm,\n &req);\n requests.push_back(req);\n offset += thiscount;\n count -= thiscount;\n }\n }\n }\n // Start send\n for (int n = 0; n < size; ++n) {\n if (n != rank and srccount[n] > 0) {\n ptrdiff_t offset = vartypesize * srcoffset[n];\n ptrdiff_t count = srccount[n];\n while (count > 0) {\n ptrdiff_t thiscount =\n min(ptrdiff_t(numeric_limits<int>::max()), count);\n MPI_Request req;\n MPI_Isend(&srcdata[offset], count, vardatatype, n, 0, comm, &req);\n requests.push_back(req);\n offset += thiscount;\n count -= thiscount;\n }\n }\n }\n // Self communication\n {\n int const n = rank;\n assert(dstcount[n] == srccount[n]);\n memcpy(&dstdata[vartypesize * dstoffset[n]],\n &srcdata[vartypesize * srcoffset[n]], dstcount[n] * vartypesize);\n }\n // Wait\n MPI_Waitall(requests.size(), &requests.front(), MPI_STATUSES_IGNORE);\n }\n\n ifcheck {\n if (vartype == CCTK_VARIABLE_REAL) {\n for (int vari = 0; vari < nvaris; ++vari) {\n CCTK_REAL const *restrict const dstdataptr =\n (CCTK_REAL const *)&dstdata.front();\n CCTK_REAL marker;\n memset(&marker, POISON_VALUE, sizeof marker);\n for (int i = 0; i < dstoffset[size]; ++i) {\n assert(memcmp(&dstdataptr[i], &marker, sizeof marker) != 0);\n }\n }\n }\n }\n CCTK_TimerStopI(timer_xfer);\n\n CCTK_TimerStartI(timer_copy_back);\n for (int n = 0; n < size; ++n) {\n check(SLAB_MAXDIM == 3);\n\n if (dstdetail[n * SLAB_MAXDIM].str == 1 and\n dstdetail[n * SLAB_MAXDIM + 1].str == 1 and\n dstdetail[n * SLAB_MAXDIM + 2].str == 1 and\n vartype == CCTK_VARIABLE_REAL) {\n // Optimised version for stride 1 and CCTK_REAL\n copy_data_back<CCTK_REAL>(info, dstdetail, dstoffset, dstelems, dstdata,\n dstptrs, n, varis, nvaris, info[0].flip,\n info[1].flip, info[2].flip);\n } else if (dstdetail[n * SLAB_MAXDIM].str == 1 and\n dstdetail[n * SLAB_MAXDIM + 1].str == 1 and\n dstdetail[n * SLAB_MAXDIM + 2].str == 1 and\n vartype == CCTK_VARIABLE_COMPLEX) {\n // Optimised version for stride 1 and CCTK_COMPLEX\n copy_data_back<CCTK_COMPLEX>(info, dstdetail, dstoffset, dstelems,\n dstdata, dstptrs, n, varis, nvaris,\n info[0].flip, info[1].flip, info[2].flip);\n } else if (dstdetail[n * SLAB_MAXDIM].str == 1 and\n dstdetail[n * SLAB_MAXDIM + 1].str == 1 and\n dstdetail[n * SLAB_MAXDIM + 2].str == 1 and\n vartype == CCTK_VARIABLE_INT) {\n // Optimised version for stride 1 and CCTK_INT\n copy_data_back<CCTK_INT>(info, dstdetail, dstoffset, dstelems, dstdata,\n dstptrs, n, varis, nvaris, info[0].flip,\n info[1].flip, info[2].flip);\n } else {\n // Generic, unoptimised version\n CCTK_TimerStartI(timer_copy_back_general);\n\n ptrdiff_t const dstdetailleni = dstdetail[n * SLAB_MAXDIM + 0].len;\n ptrdiff_t const dstdetaillenj = dstdetail[n * SLAB_MAXDIM + 1].len;\n ptrdiff_t const dstdetaillenk = dstdetail[n * SLAB_MAXDIM + 2].len;\n\n for (int vari = 0; vari < nvaris; ++vari) {\n char *restrict const dstptr = (char *restrict)dstptrs[varis[vari]];\n char const *restrict const dstdataptr =\n &dstdata[vartypesize * (dstoffset[n] + vari * dstelems[n])];\n\n // #pragma omp parallel for\n for (int k = 0; k < dstdetaillenk; ++k) {\n for (int j = 0; j < dstdetaillenj; ++j) {\n for (int i = 0; i < dstdetailleni; ++i) {\n ptrdiff_t ipos[SLAB_MAXDIM];\n ipos[0] = i;\n ipos[1] = j;\n ipos[2] = k;\n ptrdiff_t bufipos[SLAB_MAXDIM];\n ptrdiff_t dstipos[SLAB_MAXDIM];\n for (int d = 0; d < SLAB_MAXDIM; ++d) {\n if (not info[d].flip) {\n bufipos[d] = ipos[d];\n } else {\n bufipos[d] =\n dstdetail[n * SLAB_MAXDIM + d].len - 1 - ipos[d];\n }\n ifcheck assert(bufipos[d] >= 0 and\n bufipos[d] <\n dstdetail[n * SLAB_MAXDIM + d].len);\n dstipos[d] = dstdetail[n * SLAB_MAXDIM + d].off +\n ipos[d] * info[d].dst.slab.str;\n ifcheck assert(dstipos[d] >= info[d].dst.local.off and\n dstipos[d] < info[d].dst.local.off +\n info[d].dst.local.len);\n ifcheck assert(dstipos[d] >= info[d].dst.slab.off and\n dstipos[d] <= info[d].dst.slab.off +\n (info[d].dst.slab.len - 1) *\n info[d].dst.slab.str);\n ifcheck assert((dstipos[d] - info[d].dst.slab.off) %\n info[d].dst.slab.str ==\n 0);\n }\n ptrdiff_t bufind = 0;\n ptrdiff_t dstind = 0;\n for (int d = SLAB_MAXDIM - 1; d >= 0; --d) {\n bufind =\n bufind * dstdetail[n * SLAB_MAXDIM + d].len + bufipos[d];\n dstind = dstind * info[d].dst.local.alen + dstipos[d] -\n info[d].dst.local.off;\n }\n ifcheck assert(bufind < (ptrdiff_t)dstcount[n]);\n ifcheck assert(dstind < dstlentot);\n memcpy(dstptr + vartypesize * dstind,\n dstdataptr + vartypesize * bufind, vartypesize);\n }\n }\n }\n\n } // for vari\n CCTK_TimerStopI(timer_copy_back_general);\n }\n\n } // for n\n CCTK_TimerStopI(timer_copy_back);\n\n } // for vartypei\n\n ifcheck {\n ifdebug fflush(stdout);\n MPI_Barrier(comm);\n }\n\n CCTK_TimerStopI(timer_apply);\n\n return 0;\n}\n\nextern \"C\" int\nSlab_MultiTransfer_Finalize(cGH const *restrict const cctkGH,\n slabsetup *restrict const slabsetup) {\n DECLARE_CCTK_PARAMETERS;\n\n // Check arguments\n check(cctkGH);\n check(slabsetup);\n\n delete slabsetup;\n\n return 0;\n}\n\n// Interface for transferring a variable in one go\nextern \"C\" int\nSlab_MultiTransfer(cGH const *restrict const cctkGH, int const dim,\n xferinfo const *restrict const xferinfo, int const options,\n int const nvars, int const *restrict const srctypes,\n void const *restrict const *restrict const srcptrs,\n int const *restrict const dsttypes,\n void *restrict const *restrict const dstptrs) {\n slabsetup *restrict const slabsetup =\n Slab_MultiTransfer_Init(cctkGH, dim, xferinfo, options);\n Slab_MultiTransfer_Apply(cctkGH, slabsetup, nvars, srctypes, srcptrs,\n dsttypes, dstptrs);\n Slab_MultiTransfer_Finalize(cctkGH, slabsetup);\n return 0;\n}\n\n// Old interface for transferring a single variable\nextern \"C\" int Slab_Transfer(cGH const *restrict const cctkGH, int const dim,\n xferinfo const *restrict const xferinfo,\n int const options, int const srctype,\n void const *restrict const srcptr,\n int const dsttype, void *restrict const dstptr) {\n int const nvars = 1;\n int const srctypes[] = {srctype};\n void const *restrict const srcptrs[] = {srcptr};\n int const dsttypes[] = {dsttype};\n void *restrict const dstptrs[] = {dstptr};\n return Slab_MultiTransfer(cctkGH, dim, xferinfo, options, nvars, srctypes,\n srcptrs, dsttypes, dstptrs);\n}\n\n// Fortran wrapper\nextern \"C\" void CCTK_FCALL CCTK_FNAME(Slab_Transfer)(\n int *restrict const ierr, cGH const *const *restrict const cctkGH,\n int const *restrict const dim, int const *restrict const src_gsh,\n int const *restrict const src_lbnd, int const *restrict const src_lsh,\n int const *restrict const src_ash, int const *restrict const src_lbbox,\n int const *restrict const src_ubbox,\n int const *restrict const src_nghostzones,\n int const *restrict const src_off, int const *restrict const src_str,\n int const *restrict const src_len, int const *restrict const dst_gsh,\n int const *restrict const dst_lbnd, int const *restrict const dst_lsh,\n int const *restrict const dst_ash, int const *restrict const dst_lbbox,\n int const *restrict const dst_ubbox,\n int const *restrict const dst_nghostzones,\n int const *restrict const dst_off, int const *restrict const dst_str,\n int const *restrict const dst_len, int const *restrict const xpose,\n int const *restrict const flip, int const *restrict const options,\n int const *restrict const srctype, void const *restrict const srcptr,\n int const *restrict const dsttype, void *restrict const dstptr) {\n vector<xferinfo> xferinfo(*dim);\n\n for (int d = 0; d < *dim; ++d) {\n xferinfo[d].src.gsh = src_gsh[d];\n xferinfo[d].src.lbnd = src_lbnd[d];\n xferinfo[d].src.lsh = src_lsh[d];\n xferinfo[d].src.ash = src_ash[d];\n xferinfo[d].src.lbbox = src_lbbox[d];\n xferinfo[d].src.ubbox = src_ubbox[d];\n xferinfo[d].src.nghostzones = src_nghostzones[d];\n xferinfo[d].src.off = src_off[d];\n xferinfo[d].src.str = src_str[d];\n xferinfo[d].src.len = src_len[d];\n\n xferinfo[d].dst.gsh = dst_gsh[d];\n xferinfo[d].dst.lbnd = dst_lbnd[d];\n xferinfo[d].dst.lsh = dst_lsh[d];\n xferinfo[d].dst.ash = dst_ash[d];\n xferinfo[d].dst.lbbox = dst_lbbox[d];\n xferinfo[d].dst.ubbox = dst_ubbox[d];\n xferinfo[d].dst.nghostzones = dst_nghostzones[d];\n xferinfo[d].dst.off = dst_off[d];\n xferinfo[d].dst.str = dst_str[d];\n xferinfo[d].dst.len = dst_len[d];\n\n xferinfo[d].xpose = xpose[d];\n xferinfo[d].flip = flip[d];\n }\n\n *ierr = Slab_Transfer(*cctkGH, *dim, &xferinfo.front(), *options, *srctype,\n srcptr, *dsttype, dstptr);\n}\n",
"slab.inc": "! -*-F90-*-\n\ninterface\n subroutine Slab_Transfer (ierr, cctkGH, dim, &\n src_gsh, src_lbnd, src_lsh, src_ash, &\n src_lbbox, src_ubbox, src_nghostzones, &\n src_off, src_str, src_len, &\n dst_gsh, dst_lbnd, dst_lsh, dst_ash, &\n dst_lbbox, dst_ubbox, dst_nghostzones, &\n dst_off, dst_str, dst_len, &\n xpose, flip, &\n options, &\n srctype, srcptr, &\n dsttype, dstptr)\n implicit none\n integer ierr\n CCTK_POINTER cctkGH \n integer dim\n integer src_gsh(dim), src_lbnd(dim), src_lsh(dim), src_ash(dim)\n integer src_lbbox(dim), src_ubbox(dim), src_nghostzones(dim)\n integer src_off(dim), src_str(dim), src_len(dim)\n integer dst_gsh(dim), dst_lbnd(dim), dst_lsh(dim), dst_ash(dim)\n integer dst_lbbox(dim), dst_ubbox(dim), dst_nghostzones(dim)\n integer dst_off(dim), dst_str(dim), dst_len(dim)\n integer xpose(dim), flip(dim)\n integer options\n integer srctype\n CCTK_REAL srcptr(*)\n integer dsttype\n CCTK_REAL dstptr(*)\n end subroutine Slab_Transfer\nend interface\n"
},
"test": {},
"doc": {
"documentation.tex": "% *======================================================================*\n% Cactus Thorn template for ThornGuide documentation\n% Author: Ian Kelley\n% Date: Sun Jun 02, 2002\n%\n% Thorn documentation in the latex file doc/documentation.tex \n% will be included in ThornGuides built with the Cactus make system.\n% The scripts employed by the make system automatically include \n% pages about variables, parameters and scheduling parsed from the \n% relevent thorn CCL files.\n% \n% This template contains guidelines which help to assure that your \n% documentation will be correctly added to ThornGuides. More \n% information is available in the Cactus UsersGuide.\n% \n% Guidelines:\n% - Do not change anything before the line\n% % START CACTUS THORNGUIDE\",\n% except for filling in the title, author, date etc. fields.\n% - Each of these fields should only be on ONE line.\n% - Author names should be sparated with a \\\\ or a comma\n% - You can define your own macros are OK, but they must appear after\n% the START CACTUS THORNGUIDE line, and do not redefine standard \n% latex commands.\n% - To avoid name clashes with other thorns, 'labels', 'citations', \n% 'references', and 'image' names should conform to the following \n% convention: \n% ARRANGEMENT_THORN_LABEL\n% For example, an image wave.eps in the arrangement CactusWave and \n% thorn WaveToyC should be renamed to CactusWave_WaveToyC_wave.eps\n% - Graphics should only be included using the graphix package. \n% More specifically, with the \"includegraphics\" command. Do\n% not specify any graphic file extensions in your .tex file. This \n% will allow us (later) to create a PDF version of the ThornGuide\n% via pdflatex. |\n% - References should be included with the latex \"bibitem\" command. \n% - use \\begin{abstract}...\\end{abstract} instead of \\abstract{...}\n% - For the benefit of our Perl scripts, and for future extensions, \n% please use simple latex. \n%\n% *======================================================================* \n% \n% Example of including a graphic image:\n% \\begin{figure}[ht]\n% \t\\begin{center}\n% \t \\includegraphics[width=6cm]{MyArrangement_MyThorn_MyFigure}\n% \t\\end{center}\n% \t\\caption{Illustration of this and that}\n% \t\\label{MyArrangement_MyThorn_MyLabel}\n% \\end{figure}\n%\n% Example of using a label:\n% \\label{MyArrangement_MyThorn_MyLabel}\n%\n% Example of a citation:\n% \\cite{MyArrangement_MyThorn_Author99}\n%\n% Example of including a reference\n% \\bibitem{MyArrangement_MyThorn_Author99}\n% {J. Author, {\\em The Title of the Book, Journal, or periodical}, 1 (1999), \n% 1--16. {\\tt http://www.nowhere.com/}}\n%\n% *======================================================================* \n\n% If you are using CVS use this line to give version information\n\n\\documentclass{article}\n\n% Use the Cactus ThornGuide style file\n% (Automatically used from Cactus distribution, if you have a \n% thorn without the Cactus Flesh download this from the Cactus\n% homepage at www.cactuscode.org)\n\\usepackage{../../../../doc/latex/cactus}\n\n\\begin{document}\n\n% The author of the documentation\n\\author{Erik Schnetter \\textless eschnetter@perimeterinstitute.ca\\textgreater}\n\n% The title of the document (not necessarily the name of the Thorn)\n\\title{Generic Hyperslabbing}\n\n% the date your document was last changed, if your document is in CVS, \n% please use:\n\\date{$ $Date$ $}\n\n\\maketitle\n\n% Do not delete next line\n% START CACTUS THORNGUIDE\n\n% Add all definitions used in this documentation here \n% \\def\\mydef etc\n\n% Add an abstract for this thorn's documentation\n\\begin{abstract}\nThe Slab thorn provides generic slabbing facilities. A slab is a\nsub-array of another array. Both the array and the slab can be\nmultidimensional, and the slab can have a non-unit stride. The Slab\nthorn provides a routine to copy a slab from one array into a slab of\nanother array, while possibly transposing or mirroring the slab. The\nprocessor distribution of the arrays can be specified freely, so that\nthe Slab thorn can be used to interface to non-Cactus libraries with\ndifferent data layouts.\n\nThe Slab thorn is driver independent, i.e., not tied to PUGH or\nCarpet, and does not require MPI for single-processor configurations.\n\\end{abstract}\n\n% The following sections are suggestive only.\n% Remove them or add your own.\n\n\n\n\\section{Introduction}\n\nA \\emph{Slab} is a subarray of another array. This concept is used in\nmany places with many different names. Fortran has so-called ``array\nsubscript triplets'', which represent the same thing. In BLAS, the\n``leading dimension'' arguments are used to described slabs. Slabs\nare sometimes also called ``array views'' in object oriented\napplications. Slabs are rectangular in shape, and can be rotated with\nregard to their containing array by multiples of 90 degrees. They can\nalso be mirrored, i.e., the direction of axes can be inverted.\n\nIt is often necessary to copy slabs from one array into other arrays,\nor to copy one slab of an array to another slab of the same array.\nThis can be used to change the processor distribution of some data, or\nto apply symmetry or periodicity boundary conditions, or to collect\ndata onto a single processor to process it more easily.\n\n\n\n\\section{Using This Thorn}\n\n\\begin{FunctionDescription}{Slab\\_Transfer}{}\nTransfer a slab contained in one array to a (possibly different) slab\nof another (possibly the same) array\n\n\\begin{SynopsisSection}\n\\begin{Synopsis}{C}\n\\begin{verbatim}\nINHERITS: Slab\nUSES INCLUDE HEADER: Slab.h\n\n#include \"cctk.h\"\n#include \"Slab.h\"\n\nstruct slabinfo {\n int gsh;\n int lbnd, lsh;\n int ash;\n int lbbox, ubbox, nghostzones;\n int off, str, len;\n};\n\nstruct xferinfo {\n struct slabinfo src, dst;\n int xpose;\n int flip;\n};\n\nint Slab_Transfer (cGH * restrict const cctkGH,\n int const dim,\n struct xferinfo const * restrict const xferinfo,\n int const options,\n int const srctype,\n void const * const srcptr,\n int const dsttype,\n void * const dstptr);\n\\end{verbatim}\n\\end{Synopsis}\n\\end{SynopsisSection}\n\n\\begin{ResultSection}\n\\begin{Result}{0}\nSuccess\n\\end{Result}\n\\begin{Result}{nonzero}\nFailure\n\\end{Result}\n\\end{ResultSection}\n\n\\begin{ParameterSection}\n\\begin{Parameter}{cctkGH}\nPointer to the CCTK grid hierarchy\n\\end{Parameter}\n\n\\begin{Parameter}{dim}\nNumber of dimensions of the arrays and slabs. Must be nonnegative.\n\\end{Parameter}\n\n\\begin{Parameter}{xferinfo[dim]}\nDescribes the layout of the slab transfer, i.e., the shape and\ndistribution of the source and destination arrays, and the locations\nof the source and destination slabs, and a possible transformation\nbetween the slabs. Each dimension is described separately. See the\nentries \\texttt{xferinfo[d].*} below.\n\\end{Parameter}\n\n\\begin{Parameter}{xferinfo[d].src}\nDescribes the source array and source slab. See the \\textit{slabinfo}\nentries below.\n\\end{Parameter}\n\n\\begin{Parameter}{xferinfo[d].dst}\nDescribes the destination array and destination slab. See the\n\\textit{slabinfo} entries below.\n\\end{Parameter}\n\n\\begin{Parameter}{xferinfo[d].xpose}\nDescribes how to transpose the slab, i.e., possibly permuting the slab\naxes, as in $(x,y) \\rightarrow (y,x)$. \\texttt{xferinfo[d].xpose}\ncontains an integer value in the range \\texttt{0\\ldots dim-1},\nspecifying the source axis corresponding to the destination axis\n\\texttt{d}. Specify \\texttt{xferinfo[d].xpose = d} for no\ntransposition. No two values of \\texttt{xferinfo[*].xpose} may be the\nsame.\n\\end{Parameter}\n\n\\begin{Parameter}{xferinfo[d].flip}\nDescribes how to mirror the slab, i.e., possibly inverting the slab\naxes, as in $(x) \\rightarrow (-x)$. \\texttt{xferinfo[d].flip}\ncontaines a boolean value specifying whether the axis in direction\n\\texttt{d} should be inverted, i.e., either \\texttt{0} or \\texttt{1},\nwhere \\texttt{0} indicates no inversion, and \\texttt{1} indicates\ninversion.\n\nWhen axes are both transposed and inverted while a slab is copied,\nthen the transposing happens first, and the axis inversion later.\nThat is, the sequence of ``actions'' is: extract slab, transpose,\ninvert, insert slab. For example, when transposing the $x$ and $z$\naxes and inverting the $x$ axis, then the destination slab's $x$ axis\nis the source slab's flipped $z$ axis, while the destination $z$ axis\nis the unflipped source $x$ axis.\n\\end{Parameter}\n\n\\begin{Parameter}{\\textit{slab}}\nDescribes the shape and processor distribution of one dimension of an\narray, and the location of this dimension of a slab. The shape and\ndistribution is specified in the same manner as in the \\texttt{cGH}\nstructure. See the entries \\texttt{\\textit{slab}.*} below.\n\\end{Parameter}\n\n\\begin{Parameter}{\\textit{slab}.gsh}\nGlobal shape of the array; the overall number of grid points\n\\end{Parameter}\n\n\\begin{Parameter}{\\textit{slab}.lbnd}\nLower boundary of the array; the global index of the lower boundary of\nthe processor-local part of the array\n\\end{Parameter}\n\n\\begin{Parameter}{\\textit{slab}.lsh}\nLocal shape of the array; the number of grid points on this processor\n\\end{Parameter}\n\n\\begin{Parameter}{\\textit{slab}.ash}\nLocal allocated shape of the array; the number of grid points on this\nprocessor including padding\n\\end{Parameter}\n\n\\begin{Parameter}{\\textit{slab}.lbbox}\nLower bounding box of the array; whether the lower boundary of the\narray is an outer boundary. This corresponds to the even entries in\nCactus' \\texttt{bbox} array. Must be \\texttt{0} or \\texttt{1}.\n\\end{Parameter}\n\n\\begin{Parameter}{\\textit{slab}.ubbox}\nUpper bounding box of the array; whether the upper boundary of the\narray is an outer boundary. This corresponds to the odd entries in\nCactus' \\texttt{bbox} array. Must be \\texttt{0} or \\texttt{1}.\n\\end{Parameter}\n\n\\begin{Parameter}{\\textit{slab}.nghostzones}\nNumber of ghost zones of the array; the number of grid points on this\nprocessor that are only copied from neighbouring processors\n\\end{Parameter}\n\n\\begin{Parameter}{\\textit{slab}.off}\nSlab offset; the global index of the lowest grid point of the slab\n\\end{Parameter}\n\n\\begin{Parameter}{\\textit{slab}.str}\nSlab stride; the distance between two grid points making up the slab.\nSpecify \\texttt{\\textit{slab}.str = 1} for a unit stride. Must be\npositive.\n\\end{Parameter}\n\n\\begin{Parameter}{\\textit{slab}.len}\nSlab length; the number of grid points that make up the slab. This\ndoes not count the grid points that are skipped if the slab has a\nnon-unit stride. Must be nonnegative.\n\\end{Parameter}\n\n\\begin{Parameter}{options}\nHandle of an option table. Two options are understood,\n\\texttt{CCTK\\_INT useghosts} and \\texttt{CCTK\\_POINTER comm}.\n\\texttt{useghosts} (see below) specifies whether values in ghost zones\nmay be used in the source array. \\texttt{comm} is a pointer to an MPI\ncommunicator that should be used instead of \\texttt{MPI\\_COMM\\_WORLD}\nor the communicator returned by the aliased function\n\\texttt{GetMPICommWorld}.\n\\end{Parameter}\n\n\\begin{Parameter}{srctype}\nType of the source array. Pass the corresponding\n\\texttt{CCTK\\_VARIABLE\\_*} constant.\n\\end{Parameter}\n\n\\begin{Parameter}{srcptr}\nPointer to the source array\n\\end{Parameter}\n\n\\begin{Parameter}{dsttype}\nType of the destination array. Pass the corresponding\n\\texttt{CCTK\\_VARIABLE\\_*} constant.\n\\end{Parameter}\n\n\\begin{Parameter}{dstptr}\nPointer to the destination array\n\\end{Parameter}\n\\end{ParameterSection}\n\n\\begin{Discussion}\n\\texttt{Slab\\_Transfer} copies one slab from one array onto a possibly\ndifferent slab in possibly the same array. The shape and processor\ndistribution of the arrays can be specified freely, as long as each\nprocessor holds a rectangular subset of grid points. The location of\nthe slab can also be specified freely, and the slab can be rotated (by\nmultiples of 90 degrees) or inverted before it is copied. The source\nand destination slab are allowed to overlap.\n\nBy default, \\texttt{Slab\\_Transfer} is conservative with regard to\nsynchronisation. It assumes that the ghost zones of the source array\nare not valid, but will correctly fill in the ghost zones in the\ndestination slab. This can be changed by setting the option\n\\texttt{useghosts} in the option table.\n\nThere are currently some restrictions, which can be remedied if the\nneed arises: The dimension must be 3 (lower dimensions can easily be\npadded). The communication schedule is set up for every slab\ntransfer, which is expensive. The number of ghost zones along the\nlower and upper boundary is assumed to be the same. There is no\nFortran interface.\n\\end{Discussion}\n\n\\begin{SeeAlsoSection}\n\\begin{SeeAlso}{CarpetSlab}\nThe hyperslabbing thorn of the driver Carpet.\n\\end{SeeAlso}\n\n\\begin{SeeAlso}{PUGHSlab}\nThe hyperslabbing thorn of the driver CactusPUGH.\n\\end{SeeAlso}\n\n\\begin{SeeAlso}{New hyperslabbing API}\nThe web page\n\\texttt{http://www.cactuscode.org/Development/Current.html} contains a\nhyperlink to the new proposed hyperslabbing API\\@. This API is slightly\ndifferent from the one used here.\n\\end{SeeAlso}\n\\end{SeeAlsoSection}\n\n\\begin{ExampleSection}\n\\begin{Example}{C}\nThe identity transfer: copy a whole 3D grid function without\ntransforming it\n\n\\begin{verbatim}\nINHERITS: Slab\nUSES INCLUDE HEADER: Slab.h\n\n#include <assert.h>\n#include \"cctk.h\"\n#include \"cctk_Arguments.h\"\n\n#include \"Slab.h\"\n\nDECLARE_CCTK_ARGUMENTS;\n\nstruct xferinfo info[3];\nint d;\nint ierr;\n\n/* Set up the array descriptors */\nassert (cctk_dim <= 3);\nfor (d=0; d<cctk_dim; ++d) {\n info[d].src.gsh = cctk_gsh[d];\n info[d].src.lbnd = cctk_lbnd[d];\n info[d].src.lsh = cctk_lsh[d];\n info[d].src.ash = cctk_ash[d];\n info[d].src.lbbox = cctk_bbox[2*d];\n info[d].src.ubbox = cctk_bbox[2*d+1];\n info[d].src.nghostzones = cctk_nghostzones[d];\n info[d].dst.gsh = cctk_gsh[d];\n info[d].dst.lbnd = cctk_lbnd[d];\n info[d].dst.lsh = cctk_lsh[d];\n info[d].dst.ash = cctk_ash[d];\n info[d].dst.lbbox = cctk_bbox[2*d];\n info[d].dst.ubbox = cctk_bbox[2*d+1];\n info[d].dst.nghostzones = cctk_nghostzones[d];\n}\n\n/* Set up the slab and transformation descriptors */\nassert (cctk_dim <= 3);\nfor (d=0; d<cctk_dim; ++d) {\n info[d].src.off = 0;\n info[d].src.len = cctk_gsh[d];\n info[d].src.str = 1;\n info[d].dst.off = 0;\n info[d].dst.len = cctk_gsh[d];\n info[d].dst.str = 1;\n info[d].xpose = d;\n info[d].flip = 0;\n}\n\n/* Transfer the slab */\nierr = Slab_Transfer\n (cctkGH, cctk_dim, info, -1,\n CCTK_VARIABLE_REAL, gf1, CCTK_VARIABLE_REAL, gf2);\nassert (!ierr);\n\\end{verbatim}\n\\end{Example}\n\n\\begin{Example}{C}\nA complicated transfer: copy a subarray, transposing the $x$ and $z$\naxes, and inverting the $x$ axis\n\n\\begin{verbatim}\nINHERITS: Slab\nUSES INCLUDE HEADER: Slab.h\n\n#include <assert.h>\n#include \"cctk.h\"\n#include \"cctk_Arguments.h\"\n\n#include \"Slab.h\"\n\nDECLARE_CCTK_ARGUMENTS;\n\nstruct xferinfo info[3];\nint d;\nint ierr;\n\n/* Set up the array descriptors (same as above) */\nassert (cctk_dim <= 3);\nfor (d=0; d<cctk_dim; ++d) {\n info[d].src.gsh = cctk_gsh[d];\n info[d].src.lbnd = cctk_lbnd[d];\n info[d].src.lsh = cctk_lsh[d];\n info[d].src.ash = cctk_ash[d];\n info[d].src.lbbox = cctk_bbox[2*d];\n info[d].src.ubbox = cctk_bbox[2*d+1];\n info[d].src.nghostzones = cctk_nghostzones[d];\n info[d].dst.gsh = cctk_gsh[d];\n info[d].dst.lbnd = cctk_lbnd[d];\n info[d].dst.lsh = cctk_lsh[d];\n info[d].dst.ash = cctk_ash[d];\n info[d].dst.lbbox = cctk_bbox[2*d];\n info[d].dst.ubbox = cctk_bbox[2*d+1];\n info[d].dst.nghostzones = cctk_nghostzones[d];\n}\n\n/* Set up the slab and transformation descriptors */\ninfo[0].src.off = 5;\ninfo[1].src.off = 5;\ninfo[2].src.off = 1;\ninfo[0].src.str = 1;\ninfo[1].src.str = 1;\ninfo[2].src.str = 1;\ninfo[0].src.len = 2;\ninfo[1].src.len = 3;\ninfo[2].src.len = 2;\n\ninfo[0].dst.off = 2;\ninfo[1].dst.off = 3;\ninfo[2].dst.off = 4;\ninfo[0].dst.str = 1;\ninfo[1].dst.str = 1;\ninfo[2].dst.str = 1;\ninfo[0].dst.len = 2;\ninfo[1].dst.len = 3;\ninfo[2].dst.len = 2;\n\ninfo[0].xpose = 2;\ninfo[1].xpose = 1;\ninfo[2].xpose = 0;\ninfo[0].flip = 1;\ninfo[1].flip = 0;\ninfo[2].flip = 0;\n\n/* Transfer the slab */\nierr = Slab_Transfer\n (cctkGH, cctk_dim, info, -1,\n CCTK_VARIABLE_REAL, gf1, CCTK_VARIABLE_REAL, gf2);\nassert (!ierr);\n\\end{verbatim}\n\\end{Example}\n\\end{ExampleSection}\n\n\\end{FunctionDescription}\n\n\n\n\\section{Obtaining This Thorn}\n\nThis thorn is available from the \\texttt{CactusNumerical} arrangement in the\n\\texttt{arrangements} directory on the \\texttt{svn.cactuscode.org}\nCVS server via anonymous pserver access.\n\n\n\\section{Support and Feedback}\n\nThis thorn was written by Erik Schnetter \\textless\neschnetter@perimeterinstitute.ca\\textgreater\\ in 2002. Contact me for\nquestions and comments.\n\n% Do not delete next line\n% END CACTUS THORNGUIDE\n\n\\end{document}\n"
}
}