<commit_before>/*
Copyright (c) 2008
Lawrence Livermore National Security, LLC.

Produced at the Lawrence Livermore National Laboratory.
Written by <NAME>, <EMAIL>.
LLNL-CODE-402774,
All rights reserved.

This file is part of P^nMPI.

Please also read the file "LICENSE" included in this package for
Our Notice and GNU Lesser General Public License.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
(as published by the Free Software Foundation) version 2.1
dated February 1999.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY
OF MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
terms and conditions of the GNU General Public License for more
details.

You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the

Free Software Foundation, Inc.,
59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/

#include <mpi.h>

#ifndef _PNMPI_MOD_DATATYPE
#define _PNMPI_MOD_DATATYPE

/*------------------------------------------------------------*/
/* Note: this module must be loaded into the stack close
   to the module(s) using it (i.e., no other module changing
   datatypes can be instantiated between this module and
   any module using it. Also, any call to its services must
   occur after calling PMPI_Init */

/* #define DATATABLEDEBUG */
/* #define USE_FUNCTIONS */
/* #define INCLUDE_WRAPPERS */

/*------------------------------------------------------------*/
/* track datatype layout */

#define PNMPI_MODULE_DATATYPE "datatype-tracking"


/*..........................................................*/
/* Transparent type to hold reference to a datatype */

typedef struct PNMPIMOD_Datatype_storage_d *PNMPIMOD_Datatype_storage_p;

typedef struct PNMPIMOD_Datatype_stack_d
{
  int i, j, b;
  char *buf, *startbuf, *blockbuf;
  PNMPIMOD_Datatype_storage_p dt;
} PNMPIMOD_Datatype_stack_t;

typedef struct PNMPIMOD_Datatype_Parameters_d
{
  int level;
  PNMPIMOD_Datatype_storage_p top;
  PNMPIMOD_Datatype_stack_t *stack;
} PNMPIMOD_Datatype_Parameters_t;

typedef struct PNMPIMOD_Datatype_entry_d
{
  MPI_Aint start;
  int block, repeat, step;
  PNMPIMOD_Datatype_storage_p dt;
} PNMPIMOD_Datatype_entry_t;

typedef struct PNMPIMOD_Datatype_storage_d
{
  int count;
  int depth;
  int size;
  int realsize;
  int homogeneous;
  int usage;
  int native;
  MPI_Datatype mpi_dt, store_dt;
  PNMPIMOD_Datatype_entry_t *list;
} PNMPIMOD_Datatype_storage_t;


/*..........................................................*/
/* get a reference to a datatype to loop over */

typedef int (*PNMPIMOD_Datatype_getReference_t)(
  void *, int, MPI_Datatype, PNMPIMOD_Datatype_Parameters_t *);
int PNMPIMOD_Datatype_getReference(void *buf, int count, MPI_Datatype dt,
                                   PNMPIMOD_Datatype_Parameters_t *ref);

typedef int (*PNMPIMOD_Datatype_delReference_t)(
  PNMPIMOD_Datatype_Parameters_t *);
int PNMPIMOD_Datatype_delReference(PNMPIMOD_Datatype_Parameters_t *ref);

typedef int (*PNMPIMOD_Datatype_getSize_t)(MPI_Datatype, int *);
int PNMPIMOD_Datatype_getSize(MPI_Datatype, int *);


/*------------------------------------------------------------*/
/* External service routines */

/*.......................................................*/
/* next item */

#ifndef USE_FUNCTIONS

#define PNMPIMOD_Datatype_nextItem_wrap(_ref, _done)              \
  {                                                               \
    int cont;                                                     \
    do                                                            \
      {                                                           \
        cont = 0;                                                 \
        _ref->stack[_ref->level].b++;                             \
        if ((_ref->stack[_ref->level].dt->list == NULL) ||        \
            (_ref->stack[_ref->level].b ==                        \
             _ref->stack[_ref->level]                             \
               .dt->list[_ref->stack[_ref->level].i]              \
               .block))                                           \
          {                                                       \
            _ref->stack[_ref->level].b = 0;                       \
            _ref->stack[_ref->level].j++;                         \
            if ((_ref->stack[_ref->level].dt->list == NULL) ||    \
                (_ref->stack[_ref->level].j ==                    \
                 _ref->stack[_ref->level]                         \
                   .dt->list[_ref->stack[_ref->level].i]          \
                   .repeat))                                      \
              {                                                   \
                _ref->stack[_ref->level].j = 0;                   \
                _ref->stack[_ref->level].i++;                     \
                if ((_ref->stack[_ref->level].i ==                \
                     _ref->stack[_ref->level].dt->count) ||       \
                    (_ref->stack[_ref->level].dt->homogeneous))   \
                  {                                               \
                    _ref->level--;                                \
                    cont = 1;                                     \
                  }                                               \
                else                                              \
                  {                                               \
                    _ref->stack[_ref->level].blockbuf =           \
                      _ref->stack[_ref->level].startbuf +         \
                      _ref->stack[_ref->level]                    \
                        .dt->list[_ref->stack[_ref->level].i]     \
                        .start;                                   \
                    _ref->stack[_ref->level].buf =                \
                      _ref->stack[_ref->level].blockbuf;          \
                  }                                               \
              }                                                   \
            else                                                  \
              {                                                   \
                _ref->stack[_ref->level].blockbuf +=              \
                  _ref->stack[_ref->level]                        \
                    .dt->list[_ref->stack[_ref->level].i]         \
                    .step;                                        \
                _ref->stack[_ref->level].buf =                    \
                  _ref->stack[_ref->level].blockbuf;              \
              }                                                   \
          }                                                       \
        else                                                      \
          {                                                       \
            if (_ref->stack[_ref->level].b != 0)                  \
              _ref->stack[_ref->level].buf +=                     \
                _ref->stack[_ref->level]                          \
                  .dt->list[_ref->stack[_ref->level].i]           \
                  .dt->size;                                      \
          }                                                       \
                                                                  \
        if (cont == 0)                                            \
          {                                                       \
            while (_ref->stack[_ref->level].dt->homogeneous == 0) \
              {                                                   \
                _ref->level++;                                    \
                _ref->stack[_ref->level].i = 0;                   \
                _ref->stack[_ref->level].j = 0;                   \
                _ref->stack[_ref->level].b = 0;                   \
                _ref->stack[_ref->level].dt =                     \
                  _ref->stack[_ref->level - 1]                    \
                    .dt->list[_ref->stack[_ref->level - 1].i]     \
                    .dt;                                          \
                _ref->stack[_ref->level].startbuf =               \
                  _ref->stack[_ref->level - 1].buf;               \
                _ref->stack[_ref->level].blockbuf =               \
                  _ref->stack[_ref->level].startbuf;              \
                if (_ref->stack[_ref->level].dt->list)            \
                  _ref->stack[_ref->level].blockbuf +=            \
                    _ref->stack[_ref->level]                      \
                      .dt->list[_ref->stack[_ref->level].i]       \
                      .start;                                     \
                _ref->stack[_ref->level].buf =                    \
                  _ref->stack[_ref->level].blockbuf;              \
              }                                                   \
          }                                                       \
      }                                                           \
    while ((cont) && (_ref->level >= 0));                         \
                                                                  \
    if (_ref->level >= 0)                                         \
      *_done = 0;                                                 \
    else                                                          \
      *_done = 1;                                                 \
  }

#define PNMPIMOD_Datatype_nextItem(ref, done) \
  PNMPIMOD_Datatype_nextItem_wrap((ref), (done))

#endif /* not USE_FUNCTIONS */

/*.......................................................*/
/* get item */

#ifndef USE_FUNCTIONS

#define PNMPIMOD_Datatype_getItem_wrap(_ref, _buf, _typ, _len, _size, _last) \
  {                                                                          \
    *_buf = _ref->stack[_ref->level].buf;                                    \
    *_typ = _ref->stack[_ref->level].dt->mpi_dt;                             \
    *_len = _ref->stack[_ref->level].dt->count;                              \
    *_size = _ref->stack[_ref->level].dt->homogeneous;                       \
    PNMPIMOD_Datatype_nextItem(_ref, _last)                                  \
  }

#define PNMPIMOD_Datatype_getItem(ref, buf, typ, len, size, last) \
  PNMPIMOD_Datatype_getItem_wrap((ref), (buf), (typ), (len), (size), (last))

#endif /* not USE_FUNCTIONS */


#endif /* _PNMPI_MOD_DATATYPE */
<commit_msg>fix another const issue<commit_after>/*
Copyright (c) 2008
Lawrence Livermore National Security, LLC.

Produced at the Lawrence Livermore National Laboratory.
Written by <NAME>, <EMAIL>.
LLNL-CODE-402774,
All rights reserved.

This file is part of P^nMPI.

Please also read the file "LICENSE" included in this package for
Our Notice and GNU Lesser General Public License.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
(as published by the Free Software Foundation) version 2.1
dated February 1999.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY
OF MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
terms and conditions of the GNU General Public License for more
details.

You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the

Free Software Foundation, Inc.,
59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/

#include <mpi.h>

#ifndef _PNMPI_MOD_DATATYPE
#define _PNMPI_MOD_DATATYPE

/*------------------------------------------------------------*/
/* Note: this module must be loaded into the stack close
   to the module(s) using it (i.e., no other module changing
   datatypes can be instantiated between this module and
   any module using it. Also, any call to its services must
   occur after calling PMPI_Init */

/* #define DATATABLEDEBUG */
/* #define USE_FUNCTIONS */
/* #define INCLUDE_WRAPPERS */

/*------------------------------------------------------------*/
/* track datatype layout */

#define PNMPI_MODULE_DATATYPE "datatype-tracking"


/*..........................................................*/
/* Transparent type to hold reference to a datatype */

typedef struct PNMPIMOD_Datatype_storage_d *PNMPIMOD_Datatype_storage_p;

typedef struct PNMPIMOD_Datatype_stack_d
{
  int i, j, b;
  char *buf, *startbuf, *blockbuf;
  PNMPIMOD_Datatype_storage_p dt;
} PNMPIMOD_Datatype_stack_t;

typedef struct PNMPIMOD_Datatype_Parameters_d
{
  int level;
  PNMPIMOD_Datatype_storage_p top;
  PNMPIMOD_Datatype_stack_t *stack;
} PNMPIMOD_Datatype_Parameters_t;

typedef struct PNMPIMOD_Datatype_entry_d
{
  MPI_Aint start;
  int block, repeat, step;
  PNMPIMOD_Datatype_storage_p dt;
} PNMPIMOD_Datatype_entry_t;

typedef struct PNMPIMOD_Datatype_storage_d
{
  int count;
  int depth;
  int size;
  int realsize;
  int homogeneous;
  int usage;
  int native;
  MPI_Datatype mpi_dt, store_dt;
  PNMPIMOD_Datatype_entry_t *list;
} PNMPIMOD_Datatype_storage_t;


/*..........................................................*/
/* get a reference to a datatype to loop over */

typedef int (*PNMPIMOD_Datatype_getReference_t)(
  const void *, int, MPI_Datatype, PNMPIMOD_Datatype_Parameters_t *);
int PNMPIMOD_Datatype_getReference(const void *buf, int count, MPI_Datatype dt,
                                   PNMPIMOD_Datatype_Parameters_t *ref);

typedef int (*PNMPIMOD_Datatype_delReference_t)(
  PNMPIMOD_Datatype_Parameters_t *);
int PNMPIMOD_Datatype_delReference(PNMPIMOD_Datatype_Parameters_t *ref);

typedef int (*PNMPIMOD_Datatype_getSize_t)(MPI_Datatype, int *);
int PNMPIMOD_Datatype_getSize(MPI_Datatype, int *);

/*------------------------------------------------------------*/
/* External service routines */

/*.......................................................*/
/* next item */

#ifndef USE_FUNCTIONS

#define PNMPIMOD_Datatype_nextItem_wrap(_ref, _done)              \
  {                                                               \
    int cont;                                                     \
    do                                                            \
      {                                                           \
        cont = 0;                                                 \
        _ref->stack[_ref->level].b++;                             \
        if ((_ref->stack[_ref->level].dt->list == NULL) ||        \
            (_ref->stack[_ref->level].b ==                        \
             _ref->stack[_ref->level]                             \
               .dt->list[_ref->stack[_ref->level].i]              \
               .block))                                           \
          {                                                       \
            _ref->stack[_ref->level].b = 0;                       \
            _ref->stack[_ref->level].j++;                         \
            if ((_ref->stack[_ref->level].dt->list == NULL) ||    \
                (_ref->stack[_ref->level].j ==                    \
                 _ref->stack[_ref->level]                         \
                   .dt->list[_ref->stack[_ref->level].i]          \
                   .repeat))                                      \
              {                                                   \
                _ref->stack[_ref->level].j = 0;                   \
                _ref->stack[_ref->level].i++;                     \
                if ((_ref->stack[_ref->level].i ==                \
                     _ref->stack[_ref->level].dt->count) ||       \
                    (_ref->stack[_ref->level].dt->homogeneous))   \
                  {                                               \
                    _ref->level--;                                \
                    cont = 1;                                     \
                  }                                               \
                else                                              \
                  {                                               \
                    _ref->stack[_ref->level].blockbuf =           \
                      _ref->stack[_ref->level].startbuf +         \
                      _ref->stack[_ref->level]                    \
                        .dt->list[_ref->stack[_ref->level].i]     \
                        .start;                                   \
                    _ref->stack[_ref->level].buf =                \
                      _ref->stack[_ref->level].blockbuf;          \
                  }                                               \
              }                                                   \
            else                                                  \
              {                                                   \
                _ref->stack[_ref->level].blockbuf +=              \
                  _ref->stack[_ref->level]                        \
                    .dt->list[_ref->stack[_ref->level].i]         \
                    .step;                                        \
                _ref->stack[_ref->level].buf =                    \
                  _ref->stack[_ref->level].blockbuf;              \
              }                                                   \
          }                                                       \
        else                                                      \
          {                                                       \
            if (_ref->stack[_ref->level].b != 0)                  \
              _ref->stack[_ref->level].buf +=                     \
                _ref->stack[_ref->level]                          \
                  .dt->list[_ref->stack[_ref->level].i]           \
                  .dt->size;                                      \
          }                                                       \
                                                                  \
        if (cont == 0)                                            \
          {                                                       \
            while (_ref->stack[_ref->level].dt->homogeneous == 0) \
              {                                                   \
                _ref->level++;                                    \
                _ref->stack[_ref->level].i = 0;                   \
                _ref->stack[_ref->level].j = 0;                   \
                _ref->stack[_ref->level].b = 0;                   \
                _ref->stack[_ref->level].dt =                     \
                  _ref->stack[_ref->level - 1]                    \
                    .dt->list[_ref->stack[_ref->level - 1].i]     \
                    .dt;                                          \
                _ref->stack[_ref->level].startbuf =               \
                  _ref->stack[_ref->level - 1].buf;               \
                _ref->stack[_ref->level].blockbuf =               \
                  _ref->stack[_ref->level].startbuf;              \
                if (_ref->stack[_ref->level].dt->list)            \
                  _ref->stack[_ref->level].blockbuf +=            \
                    _ref->stack[_ref->level]                      \
                      .dt->list[_ref->stack[_ref->level].i]       \
                      .start;                                     \
                _ref->stack[_ref->level].buf =                    \
                  _ref->stack[_ref->level].blockbuf;              \
              }                                                   \
          }                                                       \
      }                                                           \
    while ((cont) && (_ref->level >= 0));                         \
                                                                  \
    if (_ref->level >= 0)                                         \
      *_done = 0;                                                 \
    else                                                          \
      *_done = 1;                                                 \
  }

#define PNMPIMOD_Datatype_nextItem(ref, done) \
  PNMPIMOD_Datatype_nextItem_wrap((ref), (done))

#endif /* not USE_FUNCTIONS */

/*.......................................................*/
/* get item */

#ifndef USE_FUNCTIONS

#define PNMPIMOD_Datatype_getItem_wrap(_ref, _buf, _typ, _len, _size, _last) \
  {                                                                          \
    *_buf = _ref->stack[_ref->level].buf;                                    \
    *_typ = _ref->stack[_ref->level].dt->mpi_dt;                             \
    *_len = _ref->stack[_ref->level].dt->count;                              \
    *_size = _ref->stack[_ref->level].dt->homogeneous;                       \
    PNMPIMOD_Datatype_nextItem(_ref, _last)                                  \
  }

#define PNMPIMOD_Datatype_getItem(ref, buf, typ, len, size, last) \
  PNMPIMOD_Datatype_getItem_wrap((ref), (buf), (typ), (len), (size), (last))

#endif /* not USE_FUNCTIONS */


#endif /* _PNMPI_MOD_DATATYPE */

{'fraction_non_alphanumeric': 0.12936622674066128, 'fraction_numerical': 0.004383714965256727, 'mean_word_length': 0.8116076708625496, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 263, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 160, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2332113', 'n_tokens_mistral': 5161, 'n_tokens_neox': 4791, 'n_words': 981}