/*
    Copyright (C) 2012 Bartosz Broda, Jacek Bochenek, Łukasz Biłeńkij, 
    Damian Jaworski, Wojciech Mazur, Dominik Piasecki, Maciej Piasecki, 
    Radosław Ramocki
    
    This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.

    This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. 

    See the LICENSE and COPYING files for more details.
*/

#ifndef PARALLELARCHITECT_H
#define PARALLELARCHITECT_H
#include <mpi.h>
#include "Config.h"
#include "Architect.h"
#include "Options.h"
#include "UnigramDictionary.h"
#include "supermatrixfilter.h"
#include "Dictionary.h"

const int SENDING_RESULTS = -150001;
const int ALL_OK = -150002;
const int SENDING_CORPUS_SIZE = -150003;
const int SENDING_DICT = -150004;
const int NOT_YET = -150005;
const int GIVE_WORK = -150006;
const int EXIT_CODE = -150007;
const int GIVE_SHUFFLE_TABLE = -150008;



/**
  * Counts features based on matrixes and frequency of lexical units in corpus
  *
  * \param m_pRowFeatures Output vector with row features
  * \param m_pCRSMatrix CRS Matrix pointer
  * \param m_pColumnFeatures Output vector with column features
  * \param m_pCCSMatrix CCS Matrix pointer
  * \param m_vRowLabels Vector with row labels
  * \param m_vColumnLabels Vector with column labels
  * \param m_mWordTF Map with lexical units frequencies
  *
  */
void PrepareFeatures(Matrices::FeatureVectorPtr &m_pRowFeatures,Matrices::CRSMatrixPtr m_pCRSMatrix,
                     Matrices::FeatureVectorPtr &m_pColumnFeatures,Matrices::CCSMatrixPtr m_pCCSMatrix,
                     std::vector<std::string> m_vRowLabels,std::vector<std::string> m_vColumnLabels,
                     std::map<std::string,size_t> m_mWordTF);

/**
  * Function for master node on grid. Master is always process with rank 0. Responsible for distributing work
  *     through nodes and gathering results.
  *
  * \param ac Input argument count
  * \param av Input arguments
  * \param stat Status for MPI communications
  *
  */
void parallelArchitectMaster(int ac, char *av[],MPI_Status* stat);

/**
  * Function for master to create dictionary in parallel or sequential (if there's only 1 node) way
  * \param stat Status for MPI communications
  */
void parallelMasterDict(MPI_Status* stat);

/**
  * Function for slave to create dictionary in parallel way (won't start if there's only 1 node)
  * \param stat Status for MPI communications
  */
void parallelSlaveDict(MPI_Status* stat);


/**
  * Function for slave nodes on grid. Asks for job, computes, sends results to master, sends dictionary, loops.
  *
  *
  * \param ac Input argument count
  * \param av Input arguments
  * \param stat Status for MPI communications
  *
  */
void parallelArchitectSlave(int ac, char *av[],MPI_Status* stat);


std::set<std::string> loadStopList();

#endif // PARALLELARCHITECT_H
