<commit_before>#include <stdio.h>
#include "rtdb.h"
#include "macdecls.h"
#include "sndrcv.h"

typedef long integer;		/* Equivalent C type to FORTRAN integer */

#define TYPE_RTDB_HANDLE  30001
#define TYPE_RTDB_STATUS  30002
#define TYPE_RTDB_NELEM   30003 
#define TYPE_RTDB_ARRAY   30004 
#define TYPE_RTDB_LEN     30005
#define TYPE_RTDB_NAME    30006
#define TYPE_RTDB_DATE    30007
#define TYPE_RTDB_TYPE    30008

static int me;

#define MAX_RTDB 5
#define INACTIVE  -1
#define SEQUENTIAL 0
#define PARALLEL   1
/* Mode in which DB was opended */
static int par_mode[MAX_RTDB] = {INACTIVE,INACTIVE,INACTIVE,INACTIVE,INACTIVE};
static int parallel_mode=PARALLEL; /* Current mode SEQUENTIAL/PARALLEL */

int rtdb_parallel(const int mode)
/*
  Set the parallel access mode of all databases to mode and
  return the previous setting
*/
{
  int old = parallel_mode;

  if (mode)
    parallel_mode = PARALLEL;
  else
    parallel_mode = SEQUENTIAL;
  
  return old;
}

static void rtdb_broadcast(const int msg_type, const int ma_type, 
			   const int nelem, void *data)
/*
  Convenience routine for rtdb that broadcasts MA data types from
  node 0 to all other nodes
*/
{
  long len = MA_sizeof(ma_type, nelem, MT_CHAR);
  long from = 0;
  long type = msg_type;

  BRDCST_(&type, (char *) data, &len, &from);
}

int rtdb_open(const char *filename, const char *mode, int *handle)
{
  int status;
  me = NODEID_();

  if (parallel_mode == SEQUENTIAL || me == 0)
    status = rtdb_seq_open(filename, mode, handle);

  if (parallel_mode == PARALLEL) {
    rtdb_broadcast(TYPE_RTDB_HANDLE, MT_INT, 1, (void *) handle);
    rtdb_broadcast(TYPE_RTDB_STATUS, MT_INT, 1, (void *) &status);
  }

  if (status)
    par_mode[*handle] = parallel_mode;

  return status;
}

int rtdb_close(const int handle, const char *mode)
{
  int status;
  
  if (handle < 0 || handle >= MAX_RTDB) {
    (void) fprintf(stderr, "rtdb_close: handle out of range %d\n", handle);<commit_msg>RJH: Use GA global ops<commit_after>#include <stdio.h>
#include "rtdb.h"
#include "macdecls.h"
#include "sndrcv.h"

typedef long integer;		/* Equivalent C type to FORTRAN integer */

#define TYPE_RTDB_HANDLE  30001
#define TYPE_RTDB_STATUS  30002
#define TYPE_RTDB_NELEM   30003 
#define TYPE_RTDB_ARRAY   30004 
#define TYPE_RTDB_LEN     30005
#define TYPE_RTDB_NAME    30006
#define TYPE_RTDB_DATE    30007
#define TYPE_RTDB_TYPE    30008

static int me;

#define MAX_RTDB 5
#define INACTIVE  -1
#define SEQUENTIAL 0
#define PARALLEL   1
/* Mode in which DB was opended */
static int par_mode[MAX_RTDB] = {INACTIVE,INACTIVE,INACTIVE,INACTIVE,INACTIVE};
static int parallel_mode=PARALLEL; /* Current mode SEQUENTIAL/PARALLEL */

int rtdb_parallel(const int mode)
/*
  Set the parallel access mode of all databases to mode and
  return the previous setting
*/
{
  int old = parallel_mode;

  if (mode)
    parallel_mode = PARALLEL;
  else
    parallel_mode = SEQUENTIAL;
  
  return old;
}

static void rtdb_broadcast(const int msg_type, const int ma_type, 
			   const int nelem, void *data)
/*
  Convenience routine for rtdb that broadcasts MA data types from
  node 0 to all other nodes
*/
{
  long len = MA_sizeof(ma_type, nelem, MT_CHAR);
  long from = 0;
  long type = msg_type;

  ga_brdcst_(&type, (char *) data, &len, &from);
}

int rtdb_open(const char *filename, const char *mode, int *handle)
{
  int status;
  me = NODEID_();

  if (parallel_mode == SEQUENTIAL || me == 0)
    status = rtdb_seq_open(filename, mode, handle);

  if (parallel_mode == PARALLEL) {
    rtdb_broadcast(TYPE_RTDB_HANDLE, MT_INT, 1, (void *) handle);
    rtdb_broadcast(TYPE_RTDB_STATUS, MT_INT, 1, (void *) &status);
  }

  if (status)
    par_mode[*handle] = parallel_mode;

  return status;
}

int rtdb_close(const int handle, const char *mode)
{
  int status;
  
  if (handle < 0 || handle >= MAX_RTDB) {
    (void) fprintf(stderr, "rtdb_close: handle out of range %d\n", handle);
{'fraction_non_alphanumeric': 0.10040671072699542, 'fraction_numerical': 0.02541942043721403, 'mean_word_length': 4.012738853503185, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '570505', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1447, 'n_words': 427}