#ifndef SORT_TENSOR_TASK
#define SORT_TENSOR_TASK

#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) override {
			srand(time(0)^getpid());
			for(int slice=0; slice<k; slice++){
				if(slice%worker_count == worker_id%worker_count){
				
//				int delay = 1+rand()%3;
				std::cout<<"PID "<< getpid() <<" PPID " << getppid() 
						 << " [Worker " << worker_id << "] taksinomei ti 'selida' " << slice << "\n";
				int* slice_start = tensor + (slice*n*n);
				for (int row=0; row<n; row++){
					int* row_start=slice_start + (row*n);
					std::sort(row_start, row_start+n);
				}
			}
		}
	}

};

#endif
