<commit_before>#include <stdio.h> 
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>



int roundUpDiv(int num, int den)
{
  assert (den != 0);
  return (num + den -1) / den;
}

// cC = number of chunks, typically number of compute processes
// cN = chunk number
// iC = item count, how many objects
int chunkSize(int cC, int iC, int cN)
{
  if (cN < 1 || cN > cC)
    return 0;
  else if (cN > iC/roundUpDiv(iC, cC) )
    return iC - (cN-1) * roundUpDiv(iC,cC);
  else
    return roundUpDiv(iC,cC);
}

int chunkOffset(int cC, int iC, int cN)
{
  if (cN > cC || cN <1)
    return -1;
  else
    return (cN-1) * roundUpDiv(iC, cC);
}

int main(int argc, char **arg)
{
  int fd;
  off_t size, offset;
  int iC, cN, cC, count;

  double d = 1.0;

  if (argc != 5) {
    printf("usage: %s path itemcount processcount chunkno -- write floats to file \"path\" \n", arg[0]);
    exit(1);
  }

  iC = atoi(arg[2]);  // item count  = number of floats
  cC = atoi(arg[3]);  // chunk count = number of compute procs
  cN = atoi(arg[4]);  // chunk number

  if (cN == 0) {
    fd = open(arg[1], O_CREAT | O_RDWR, 0664);
    assert (fd > 0);
    ftruncate(fd, iC * sizeof(d));
    return 0;
  }

  count = chunkSize(cC, iC, cN);
  size = sizeof(d) * count;
  offset = sizeof(d) * chunkOffset(cC, iC, cN);

  assert(offset >= 0 && count <= iC);
  assert(size >= 0);

  assert(printf("Writing %d floats of %d (all 1.0) after %d floats to %s.\n", count, iC , chunkOffset(cC, iC, cN), arg[1]) > 0);
  fd = open(arg[1], O_CREAT | O_RDWR, 0664);<commit_msg>Longs for offset and count computations<commit_after>#include <stdio.h> 
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>



long roundUpDiv(long num, long den)
{
  assert (den != 0);
  return (num + den -1) / den;
}

// cC = number of chunks, typically number of compute processes
// cN = chunk number
// iC = item count, how many objects
long chunkSize(long cC, long iC, long cN)
{
  if (cN < 1 || cN > cC)
    return 0;
  else if (cN > iC/roundUpDiv(iC, cC) )
    return iC - (cN-1) * roundUpDiv(iC,cC);
  else
    return roundUpDiv(iC,cC);
}

long chunkOffset(long cC, long iC, long cN)
{
  if (cN > cC || cN <1)
    return -1;
  else
    return (cN-1) * roundUpDiv(iC, cC);
}

int main(int argc, char **arg)
{
  int fd;
  off_t size, offset;
  long iC, cN, cC, count;

  double d = 1.0;

  if (argc != 5) {
    printf("usage: %s path itemcount processcount chunkno -- write floats to file \"path\" \n", arg[0]);
    exit(1);
  }

  iC = atol(arg[2]);  // item count  = number of floats
  cC = atol(arg[3]);  // chunk count = number of compute procs
  cN = atol(arg[4]);  // chunk number

  if (cN == 0) {
    fd = open(arg[1], O_CREAT | O_RDWR, 0664);
    assert (fd > 0);
    ftruncate(fd, iC * sizeof(d));
    return 0;
  }

  count = chunkSize(cC, iC, cN);
  size = sizeof(d) * count;
  offset = sizeof(d) * chunkOffset(cC, iC, cN);

  assert(offset >= 0 && count <= iC);
  assert(size >= 0);

  assert(printf("Writing %ld floats of %ld (all 1.0) after %ld floats to %s.\n", count, iC , chunkOffset(cC, iC, cN), arg[1]) > 0);
  fd = open(arg[1], O_CREAT | O_RDWR, 0664);
{'fraction_non_alphanumeric': 0.1700787401574803, 'fraction_numerical': 0.02204724409448819, 'mean_word_length': 2.9306930693069306, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, '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': '653188', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1326, 'n_words': 400}