<commit_before>#include <cstdio>
#include <cstdlib>
#include <pthread.h>
//#include "carbon_user.h"     /* For the Graphite Simulator*/
#include <time.h>
#include <sys/timeb.h>

#define MAX            100000000
#define INT_MAX        100000000
#define BILLION 1E9

//Thread Argument Structure
typedef struct
{
   int*      local_min;
   int*      global_min;
   int*      Q;
   int*      D;
   //int**     W;
   int**     W_index;
   int*      d_count;
   int       tid;
   int       P;
   int       N;
   int       DEG;
   pthread_barrier_t* barrier_total;
   pthread_barrier_t* barrier;
} thread_arg_t;

//Function Declarations
int initialize_single_source(int* D, int* Q, int source, int N);
void init_weights(int N, int DEG, int** W, int** W_index);

//Global Variables
pthread_mutex_t lock;
pthread_mutex_t locks[4194304];    //locks for each vertex
int local_min_buffer[1024];
int global_min_buffer;
int P_global = 256;
int *edges;
int *exist;
int largest=0;
thread_arg_t thread_arg[1024];
pthread_t   thread_handle[1024];   //Max threads and pthread handlers

//Primary Parallel Function
void* do_work(void* args)
{
   //Thread Variables
   volatile thread_arg_t* arg = (thread_arg_t*) args;
   int tid                  = arg->tid;      //thread id
   int P                    = arg->P;        //Total threads
   int* D                   = arg->D;        //contains components
   //Output: Array D,with D[i] being the component
   //to which vertex i belongs
   //
   //int** W                = arg->W;
   int** W_index            = arg->W_index;  //Graph Structure
   int mod                  = 1;             //modularity
   int v                    = 0;             //current vertex
   int iterations           = 0;             //iterations  
   int start =  0;  //tid    * DEG / (arg->P);
   int stop  = 0;   //(tid+1) * DEG / (arg->P);
   double tid_d = tid;
   double P_d = P;
   double largest_d = largest+1.0;

   //Chunk work for threads via double precision
   double start_d = (tid_d) * (largest_d/P_d);
   double stop_d  = (tid_d+1.0) * (largest_d/P_d);
   start =  start_d;//tid    *  (largest+1) / (P);
   stop =  stop_d;//(tid+1) *  (largest+1) / (P);

   pthread_barrier_wait(arg->barrier_total);

   //Each component is its own, first phase
   for(v=start;v<stop;v++)
   {
      D[v] = v;
   }
   //printf("\n started P:%d %d",P, change); 
   pthread_barrier_wait(arg->barrier_total);

   //start connecting, second phase
   while(mod==1)
   { 
      mod=0;
      iterations++;
      for(v=start;v<stop;v++)                  //for each vertex
      { 
         if(exist[v]==1)                       //if vertex exists
         { 
            for(int i = 0; i < edges[v]; i++)   //for each edge
            {
               int neighbor = W_index[v][i];
               pthread_mutex_lock(&locks[neighbor]);

               if((D[v] < D[neighbor]) && (D[neighbor] == D[D[neighbor]]))
               {
                  mod=1;                      //some change occured
                  D[D[neighbor]] = D[v];
               }				

               pthread_mutex_unlock(&locks[neighbor]);
            }
         }
      }
      //printf("\n third phase");
      pthread_barrier_wait(arg->barrier_total);

	  //Third phase, assign components
      for(v=start;v<stop;v++)
      {
         while(D[v] != D[D[v]])
         {
            D[v] = D[D[v]];
         }
      }
      /*if(mod==1)
        {
        pthread_mutex_lock(&lock);
        change=1;
        pthread_mutex_lock(&lock);
        }*/
      //if(tid==0)
      //  printf("\n change:%d",mod);

      //pthread_barrier_wait(arg->barrier_total);
   }
   //printf("\n Iterations:%d",iterations);
   pthread_barrier_wait(arg->barrier_total);
   return NULL;
}<commit_msg>removed neighor locks<commit_after>#include <cstdio>
#include <cstdlib>
#include <pthread.h>
//#include "carbon_user.h"     /* For the Graphite Simulator*/
#include <time.h>
#include <sys/timeb.h>

#define MAX            100000000
#define INT_MAX        100000000
#define BILLION 1E9

//Thread Argument Structure
typedef struct
{
   int*      local_min;
   int*      global_min;
   int*      Q;
   int*      D;
   //int**     W;
   int**     W_index;
   int*      d_count;
   int       tid;
   int       P;
   int       N;
   int       DEG;
   pthread_barrier_t* barrier_total;
   pthread_barrier_t* barrier;
} thread_arg_t;

//Function Declarations
int initialize_single_source(int* D, int* Q, int source, int N);
void init_weights(int N, int DEG, int** W, int** W_index);

//Global Variables
pthread_mutex_t lock;
pthread_mutex_t locks[4194304];    //locks for each vertex
int local_min_buffer[1024];
int global_min_buffer;
int P_global = 256;
int *edges;
int *exist;
int largest=0;
thread_arg_t thread_arg[1024];
pthread_t   thread_handle[1024];   //Max threads and pthread handlers

//Primary Parallel Function
void* do_work(void* args)
{
   //Thread Variables
   volatile thread_arg_t* arg = (thread_arg_t*) args;
   int tid                  = arg->tid;      //thread id
   int P                    = arg->P;        //Total threads
   int* D                   = arg->D;        //contains components
   //Output: Array D,with D[i] being the component
   //to which vertex i belongs
   //
   //int** W                = arg->W;
   int** W_index            = arg->W_index;  //Graph Structure
   int mod                  = 1;             //modularity
   int v                    = 0;             //current vertex
   int iterations           = 0;             //iterations  
   int start =  0;  //tid    * DEG / (arg->P);
   int stop  = 0;   //(tid+1) * DEG / (arg->P);
   double tid_d = tid;
   double P_d = P;
   double largest_d = largest+1.0;

   //Chunk work for threads via double precision
   double start_d = (tid_d) * (largest_d/P_d);
   double stop_d  = (tid_d+1.0) * (largest_d/P_d);
   start =  start_d;//tid    *  (largest+1) / (P);
   stop =  stop_d;//(tid+1) *  (largest+1) / (P);

   pthread_barrier_wait(arg->barrier_total);

   //Each component is its own, first phase
   for(v=start;v<stop;v++)
   {
      D[v] = v;
   }
   //printf("\n started P:%d %d",P, change); 
   pthread_barrier_wait(arg->barrier_total);

   //start connecting, second phase
   while(mod==1)
   { 
      mod=0;
      iterations++;
      for(v=start;v<stop;v++)                  //for each vertex
      { 
         if(exist[v]==1)                       //if vertex exists
         { 
            for(int i = 0; i < edges[v]; i++)   //for each edge
            {
               int neighbor = W_index[v][i];
               //pthread_mutex_lock(&locks[neighbor]);

               if((D[v] < D[neighbor]) && (D[neighbor] == D[D[neighbor]]))
               {
                  mod=1;                      //some change occured
                  D[D[neighbor]] = D[v];
               }				

               //pthread_mutex_unlock(&locks[neighbor]);
            }
         }
      }
      //printf("\n third phase");
      pthread_barrier_wait(arg->barrier_total);

	  //Third phase, assign components
      for(v=start;v<stop;v++)
      {
         while(D[v] != D[D[v]])
         {
            D[v] = D[D[v]];
         }
      }
      /*if(mod==1)
        {
        pthread_mutex_lock(&lock);
        change=1;
        pthread_mutex_lock(&lock);
        }*/
      //if(tid==0)
      //  printf("\n change:%d",mod);

      //pthread_barrier_wait(arg->barrier_total);
   }
   //printf("\n Iterations:%d",iterations);
   pthread_barrier_wait(arg->barrier_total);
   return NULL;
}
{'fraction_non_alphanumeric': 0.13821571238348868, 'fraction_numerical': 0.017043941411451397, 'mean_word_length': 1.776709796672828, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3307362', 'n_tokens_mistral': 2698, 'n_tokens_neox': 2533, 'n_words': 594}