#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

#include "matrix.h"

void *thread_func(void *argument) {
	int index, position, start, stop, line, column;
	index = *((int *) argument);
	start = index * range;
	stop = start + range;
	for (position = start; position < stop; position ++) {
		line  = position / DIMENSION;
		column = position % DIMENSION;
		matrixProduct[line][column] = scalar_product(matrixA[line], matrixB[column]);
	}
	return NULL;
}

int main(int argc, char *argv[]){
	int i, *indice;
	pthread_t *threads;
		
	initialize(argc, argv);

	indice = (int *) malloc (size * sizeof(int));
	threads = (pthread_t *) malloc (size * sizeof(pthread_t));
	
	for(i = 0; i < size; i++){
		indice[i] = i;
		pthread_create(&(threads[i]), NULL, thread_func, &(indice[i]));
	}
	for(i = 0; i < size; i++){
		pthread_join(threads[i], NULL);
	}

	return 0;
}