#ifndef SORT_TENSOR_TASK_HPP
#define SORT_TENSOR_TASK_HPP

#include <iostream>
#include <algorithm>
#include <unistd.h>
#include <cstdlib>
#include <ctime>

#include "Task.hpp"

class SortTensorTask : public Task {
	private:
		int* tensor;
		int n;
		int k;
	public:
		SortTensorTask(int* t , int size_n , int size_k) : tensor(t) , n(size_n) , k(size_k) {}

		void execute_task(int worker_id , int worker_count) {
			srand(time(0)^getpid());
			for(int slice=0; slice<k; slice++) {
				if(slice%worker_count == worker_id%worker_count){

					std::cout<< "PID "<< getpid() << " PPID " << getppid()
							  <<" [Worker " << worker_id << "] taksinomei ti 'selida' "<< slice <<"\n" ;

					int* slice_start = tensor +(slice*n*n);
					for(int r=0; r<n; r++){
						int* row_start=slice_start +(r*n);
						std::sort(row_start,row_start+n);
					}
				}
			}
		}
};

#endif
