Commit 14d3d492 authored by Alberto Gonzalez's avatar Alberto Gonzalez

Commit 1 concept fork

parent abde05fe
......@@ -57,6 +57,16 @@
#include <chrono>
//END ALBERTO
//ALBERTO CONCEPT FORK
#include <iostream>
#include <vector>
#include <semaphore.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <unistd.h>
//END ALBERTO CONCEPT FORK
//! \ingroup EncoderLib
//! \{
......@@ -65,6 +75,17 @@
int EncCu::iter = 0;
//END ALBERTO
//ALBERTO CONCEPT FORK
struct vectorModeCostStruct {
int mode;
double cost;
};
const int VECTOR_SIZE = 1 << 10; // 4^10
const int VECTOR_BYTES = VECTOR_SIZE * sizeof(int);
sem_t* sem;
vectorModeCostStruct* vector;
//END ALBERTO CONCEPT FORK
// ====================================================================================================================
const MergeIdxPair EncCu::m_geoModeTest[GEO_MAX_NUM_CANDS] = {
......@@ -261,6 +282,23 @@ void EncCu::init( EncLib* pcEncLib, const SPS& sps )
void EncCu::compressCtu(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr, const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP)
{
//ALBERTO CONCEPT FORK
// Crear memoria compartida para el vector y el semáforo
int fd = shm_open("/myshm", O_CREAT | O_RDWR, 0666);
ftruncate(fd, VECTOR_BYTES + sizeof(sem_t));
vector = (vectorModeCostStruct*) mmap(NULL, VECTOR_BYTES, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
sem = (sem_t*) (vector + VECTOR_SIZE);
sem_init(sem, 1, 1);
for (int i = 0; i < VECTOR_SIZE; i++) {
pid_t pid = fork();
if (pid == 0) { // proceso hijo
// acceder al vector en la posición i
sem_wait(sem);
vectorModeCostStruct structura;
vector[i] = structura;
sem_post(sem);
//END ALBERTO CONCEPT FORK
m_modeCtrl->initCTUEncoding( *cs.slice );
cs.treeType = TREE_D;
......@@ -346,6 +384,13 @@ void EncCu::compressCtu(CodingStructure &cs, const UnitArea &area, const unsigne
CHECK( bestCS->cus.empty() , "No possible encoding found" );
CHECK( bestCS->cus[0]->predMode == NUMBER_OF_PREDICTION_MODES, "No possible encoding found" );
CHECK( bestCS->cost == MAX_DOUBLE , "No possible encoding found" );
//ALBERTO CONCEPT FORK
exit(0);
}
}
//END ALBERTO CONCEPT FORK
munmap(vector, VECTOR_BYTES);
shm_unlink("/myshm");
}
// ====================================================================================================================
......@@ -723,6 +768,34 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
m_bestBcwCost.fill(std::numeric_limits<double>::max());
m_bestBcwIdx.fill(BCW_NUM);
}
//ALBERTO CONCEPT FORK
std::cout << "-----------------------------------------------------" << std::endl;
int mode = 5;
int lastMode = m_modeCtrl->currTestMode().type;
/*Se avanza hasta el modo actual requerido por el proceso*/
while (lastMode != mode)
{
std::cout << "Avanzando modo: " << lastMode << ", buscando modo: " << mode << std::endl;
if (lastMode == mode || !(m_modeCtrl->nextMode(*tempCS, partitioner))) //Si se encuntra mode o no hay mas modes salimos del bucle
{
std::cout << "No otros modos" << ", modo reciente: <" << lastMode << ">" << std::endl;
break;
}
lastMode = m_modeCtrl->currTestMode().type;
}
if (lastMode != mode)
{
std::cout << "El proceso que busca el modo " << mode << " NO ha resultado satisfactorio, no se puede aplicar ese modo para CU" << std::endl;
return; //NO SE PUEDE APLICAR MODO PARA ESTA CU
}
else
{
std::cout << "El proceso que busca el modo " << mode << " SI ha resultado satisfactorio" << std::endl;
}
std::cout << "-----------------------------------------------------" << std::endl;
//END ALBERTO CONCEPT FORK
do
{
for (int i = compBegin; i < (compBegin + numComp); i++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment