<commit_before>#include "mandelbrot.h"

void parse_arguments(int argv, char** args, int* width, int* height, int* max_iteration)
{
  int have_set_width = FALSE;
  int have_set_height = FALSE;
  //printf("I have %d arguments.\n",argv);
  if(argv>1)
  {
    // We have arguments
    for(int i=1;i<argv-1;i++)
    {
      if((!strcmp(args[i],"-w"))||(!strcmp(args[i],"--width")))
      {
        i++;
        *width = atoi(args[i]);
        if(!have_set_height)
        {
          // Scale height to be sensible
          *height = *width/3.5*2;
        }
        have_set_width = TRUE;
      }
      else if((!strcmp(args[i],"-h"))||(!strcmp(args[i],"--height")))
      {
        i++;
        *height = atoi(args[i]);
        if(!have_set_width)
        {
          // Scale width to be sensible
          *width = *height/2*3.5;
        }
        have_set_height = TRUE;
      }
      else if((!strcmp(args[i],"-i"))||(!strcmp(args[i],"--max-iterations")))
      {
        i++;
        *max_iteration = atoi(args[i]);
      }
    }
  }
}

int main(int argv, char** args)
{
    // Major variables
    int width, height, max_iteration;
    float fwidth, fheight, fmax_iteration;
    struct timeval  tic, toc; 
    uint8 **gather_grid = NULL;
    uint8 **grid;
    FILE *file;
    
    // OpenMPI variables
    int rank;
    int size;
    int strip_height;
    int strip_start;
    
    // Set variable defaults
    width = 3500;
    height = 2000;
    max_iteration = 1000;
    
    // Set variables from cmdLine
    parse_arguments(argv, args, &width, &height, &max_iteration);
    
    // Begin OpenMPI
    MPI_Init( &argv, &args );
    MPI_Comm_size( MPI_COMM_WORLD, &size );
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    strip_height = height/size;
    strip_start = strip_height*rank;

    // Allocate grid memory
    grid = calloc(width, sizeof(uint8*));
    for(int i=0;i<width;i++)
    {
        grid[i] = (uint8*) calloc(strip_height, sizeof(uint8));
    }
    
    if(rank==MASTER)
    {
      // make the final array
      gather_grid = calloc(width, sizeof(uint8*));
      for(int i=0;i<width;i++)
      {
          gather_grid[i] = (uint8*) calloc(height, sizeof(uint8));
      }
    }
    
    // Convert to floats for non-integer division later
    fwidth = width;
    fheight = height;
    fmax_iteration = max_iteration;
    
    // Say hello
    if(rank==MASTER)
    {
      printf("Mandelbot set renderer.\n");
      printf("    Rendering at %d, %d.\n", width, height);
      printf("    Using %d iterations.\n", max_iteration);
      printf("Begin...\n");
    }
    
    // Loop variables
    float x0, y0, x, y, xtemp;
    int iteration;
    
    // Start timing
    gettimeofday(&tic, NULL);
    
    // Loop for all pixels in image
    for(int j=0;j<width;j++)
    {
      for(int i=0;i<strip_height;i++)
      {
        x0 = ((j+strip_start)/fwidth)*3.5 - 2.5;
        y0 = -1*((i/fheight)*2 - 1);

        //printf("        test %f, %f\n", x0, y0);
        
        x = x0;
        y = y0;
        iteration = 0;<commit_msg>Added debug output<commit_after>#include "mandelbrot.h"

void parse_arguments(int argv, char** args, int* width, int* height, int* max_iteration)
{
  int have_set_width = FALSE;
  int have_set_height = FALSE;
  //printf("I have %d arguments.\n",argv);
  if(argv>1)
  {
    // We have arguments
    for(int i=1;i<argv-1;i++)
    {
      if((!strcmp(args[i],"-w"))||(!strcmp(args[i],"--width")))
      {
        i++;
        *width = atoi(args[i]);
        if(!have_set_height)
        {
          // Scale height to be sensible
          *height = *width/3.5*2;
        }
        have_set_width = TRUE;
      }
      else if((!strcmp(args[i],"-h"))||(!strcmp(args[i],"--height")))
      {
        i++;
        *height = atoi(args[i]);
        if(!have_set_width)
        {
          // Scale width to be sensible
          *width = *height/2*3.5;
        }
        have_set_height = TRUE;
      }
      else if((!strcmp(args[i],"-i"))||(!strcmp(args[i],"--max-iterations")))
      {
        i++;
        *max_iteration = atoi(args[i]);
      }
    }
  }
}

int main(int argv, char** args)
{
    // Major variables
    int width, height, max_iteration;
    float fwidth, fheight, fmax_iteration;
    struct timeval  tic, toc; 
    uint8 **gather_grid = NULL;
    uint8 **grid;
    FILE *file;
    
    // OpenMPI variables
    int rank;
    int size;
    int strip_height;
    int strip_start;
    
    // Set variable defaults
    width = 3500;
    height = 2000;
    max_iteration = 1000;
    
    // Set variables from cmdLine
    parse_arguments(argv, args, &width, &height, &max_iteration);
    
    // Begin OpenMPI
    MPI_Init( &argv, &args );
    MPI_Comm_size( MPI_COMM_WORLD, &size );
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    strip_height = height/size;
    strip_start = strip_height*rank;

    // Allocate grid memory
    grid = calloc(width, sizeof(uint8*));
    for(int i=0;i<width;i++)
    {
        grid[i] = (uint8*) calloc(strip_height, sizeof(uint8));
    }
    
    if(rank==MASTER)
    {
      // make the final array
      gather_grid = calloc(width, sizeof(uint8*));
      for(int i=0;i<width;i++)
      {
          gather_grid[i] = (uint8*) calloc(height, sizeof(uint8));
      }
    }
    
    // Convert to floats for non-integer division later
    fwidth = width;
    fheight = height;
    fmax_iteration = max_iteration;
    
    // Say hello
    if(rank==MASTER)
    {
      printf("Mandelbot set renderer.\n");
      printf("    Rendering at %d, %d.\n", width, height);
      printf("    Using %d iterations.\n", max_iteration);
      printf("Begin...\n");
    }
    
    // Debug output
    printf("I am rank %d, I am looking after rows %d to %d", rank, strip_start, strip_start+strip_height-1);
    
    // Loop variables
    float x0, y0, x, y, xtemp;
    int iteration;
    
    // Start timing
    gettimeofday(&tic, NULL);
    
    // Loop for all pixels in image
    for(int j=0;j<width;j++)
    {
      for(int i=0;i<strip_height;i++)
      {
        x0 = ((j+strip_start)/fwidth)*3.5 - 2.5;
        y0 = -1*((i/fheight)*2 - 1);

        //printf("        test %f, %f\n", x0, y0);
        
        x = x0;
        y = y0;
        iteration = 0;
{'fraction_non_alphanumeric': 0.1561648228314895, 'fraction_numerical': 0.015873015873015872, 'mean_word_length': 2.0237518177411538, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '1306600', 'n_tokens_mistral': 2303, 'n_tokens_neox': 2253, 'n_words': 482}