Ejemplo n.º 1
0
int main(void) {
	e_iap_status iap_status;

	/* Fill the flash with payload and hash data */
	iap_status = (e_iap_status) generator_init();
	if (iap_status != CMD_SUCCESS)
		while (1)
			;   // Error !!!

	Details d;

	initButton();
    initDMA();
	initDetails(&d, getNumberOfChunks(), getSizeOfChunk());

	while (buttonIterrupt) {
	}

	int res = mainFunction(&d, 32);

	if(res==0) {
		blinkLed(1000000);
	}
	else {
		blinkLed(100);
	}


	return 0;
}
Ejemplo n.º 2
0
/**
 * constructor
 */
SellCSigma_Matrix::SellCSigma_Matrix( MMreader mmMatrix, int C, int const sigma )
:C_(C), sigma_(sigma)
,M_(mmMatrix.getRows()), N_(mmMatrix.getCols())
,nz_(mmMatrix.getNonZeros()), numberOfChunks_((M_-1)/C+1)
,colInd_(nullptr)
,chunkPtr_(new int[numberOfChunks_]), chunkLength_(new int[numberOfChunks_])
,permute_(new int[M_]), antiPermute_(new int[M_])
,val_(nullptr)
{

    // sort input Matrix by row ID
    if( !mmMatrix.isRowSorted() )
        sortByRow(mmMatrix);


    std::vector< std::tuple<int,int,double> > & mmData = mmMatrix.getMatrx();
    std::vector< std::tuple<int, int> > rowLengths = getRowLengths(mmMatrix);

    // sort sigam chunks by row length
    auto begin = rowLengths.begin();
    auto end   = rowLengths.begin() + getSigma();
    for (; end <= rowLengths.end(); begin += getSigma(), end += getSigma() )
    {
        std::sort(begin, end,
                  [](std::tuple<int,int> const & a, std::tuple<int,int> const & b)
                  {return std::get<1>(a) < std::get<1>(b);}
                 );
    }
    begin -= getSigma();
    std::sort(begin, rowLengths.end(),
                [](std::tuple<int,int> const & a, std::tuple<int,int> const & b)
                {return std::get<1>(a) < std::get<1>(b);}
                );


    // determine chunk length and size
    // and set backword permutation
    std::vector<int> valuesPerChunk( getNumberOfChunks() );
#ifdef _OPENMP
    #pragma omp parallel for schedule(runtime)
#endif
    for (int chunk=0; chunk < getNumberOfChunks(); ++chunk)
    {
        int maxRowLenghth = 0;

        for (int i=0,            row=chunk*getChunkSize();
             i<getChunkSize() && row<getRows();
             ++i,                ++row
            )
        {
            if ( maxRowLenghth < std::get<1>(rowLengths[row]) )
                maxRowLenghth = std::get<1>(rowLengths[row]);

            // set backword permutation
            antiPermute_[ std::get<0>(rowLengths[row]) ] = row;
        }

        chunkLength_[chunk] = maxRowLenghth;
        valuesPerChunk[chunk] = maxRowLenghth * getChunkSize();
    }


    // calculate memory usage and allocate memmory for values and colum IDs
    capasety_ = std::accumulate(std::begin(valuesPerChunk),
                                std::end(valuesPerChunk),
                                0
                               );

    val_    = new double[capasety_];
    colInd_ = new int   [capasety_];

    // calulate memory overhead
    overhead_ = capasety_ - getNonZeros();


    // creat Sell-C-sigma data
    std::vector<int> chunkOffset = getOffsets(valuesPerChunk);
    std::vector<int> rowOffset   = getOffsets(getValsPerRow(mmMatrix));

#ifdef _OPENMP
    #pragma omp parallel for schedule(runtime)
#endif
    for (int chunk=0; chunk < getNumberOfChunks(); ++chunk)
    {
        chunkPtr_[chunk] = chunkOffset[chunk];

        for (int j=0; j<chunkLength_[chunk]; ++j)
        {
            for (int i=0,            row=chunk*getChunkSize();
                 i<getChunkSize();
                 ++i,                ++row
                )
            {
                int    col;
                double val;

                if (row<getRows())
                {
                    // set permutation
                    permute_[row] = std::get<0>(rowLengths[row]);

                    // finde values and collumn index
                    if ( j < std::get<1>(rowLengths[row]) )
                    {   // fill with matrix values
                        int id = rowOffset[ permute_[row] ] + j;

                        val = std::get<2>( mmData[id] );
                        col = std::get<1>( mmData[id] );
                    }
                    else
                    {   // fill chunk with 0
                        val = 0.;
                        col = 0;
                    }
                }
                else
                { // add zero rows to end of matrix fill up last chunk
                    val = 0.;
                    col = 0;
                }

                val_   [chunkPtr_[chunk] + i + j*getChunkSize()] = val;
                colInd_[chunkPtr_[chunk] + i + j*getChunkSize()] = antiPermute_[col];
            }
        }
    }

    /*
    std::cout << "Sell-C-sigma constructed:"
              << "\nC: " << getChunkSize() << " sigma: " << getSigma()
              << "\n(" << getRows() << "," << getCols() << ") " << getNonZeros()
              << ":\n";
    for (int i=0; i<valueMemoryUsage; ++i)
    {
        std::cout << getValues()[i] << " (" << getColInd()[i] << ")\n";
    }
    std::cout << std::endl;
    */
}