void finalizeComputestep1Local() { /* Get the size of the serialized input */ MPI_Bcast( &perNodeArchLength, sizeof(size_t), MPI_CHAR, mpiRoot, MPI_COMM_WORLD ); byte *nodeResults = new byte[ perNodeArchLength ]; /* Transfer partial results from the root node */ MPI_Scatter(serializedData.get(), perNodeArchLength, MPI_CHAR, nodeResults, perNodeArchLength, MPI_CHAR, mpiRoot, MPI_COMM_WORLD); /* Deserialize partial results from step 2 */ OutputDataArchive dataArch( nodeResults, perNodeArchLength ); services::SharedPtr<data_management::DataCollection> dataFromStep2ForStep3 = services::SharedPtr<data_management::DataCollection>( new data_management::DataCollection() ); dataFromStep2ForStep3->deserialize(dataArch); delete[] nodeResults; /* Create an algorithm to compute QR decomposition on the master node */ qr::Distributed<step3Local> alg; alg.input.set( qr::inputOfStep3FromStep1, dataFromStep1ForStep3 ); alg.input.set( qr::inputOfStep3FromStep2, dataFromStep2ForStep3 ); /* Compute QR decomposition */ alg.compute(); alg.finalizeCompute(); services::SharedPtr<qr::Result> res = alg.getResult(); Qi = res->get(qr::matrixQ); }
void computeOnMasterNode() { /* Create an algorithm to compute QR decomposition on the master node */ qr::Distributed<step2Master> alg; for (size_t i = 0; i < nBlocks; i++) { /* Deserialize partial results from step 1 */ OutputDataArchive dataArch( serializedData.get() + perNodeArchLength * i, perNodeArchLength ); services::SharedPtr<data_management::DataCollection> dataForStep2FromStep1 = services::SharedPtr<data_management::DataCollection>( new data_management::DataCollection() ); dataForStep2FromStep1->deserialize(dataArch); alg.input.add( qr::inputOfStep2FromStep1, i, dataForStep2FromStep1 ); } /* Compute QR decomposition */ alg.compute(); services::SharedPtr<qr::DistributedPartialResult> pres = alg.getPartialResult(); services::SharedPtr<KeyValueDataCollection> inputForStep3FromStep2 = pres->get( qr::outputOfStep2ForStep3 ); for (size_t i = 0; i < nBlocks; i++) { /* Serialize partial results to transfer to local nodes for step 3 */ InputDataArchive dataArch; (*inputForStep3FromStep2)[i]->serialize( dataArch ); if( i == 0 ) { perNodeArchLength = dataArch.getSizeOfArchive(); /* Serialized data is of equal size for each node if it was equal in step 1 */ serializedData = services::SharedPtr<byte>( new byte[ perNodeArchLength * nBlocks ] ); } dataArch.copyArchiveToArray( serializedData.get() + perNodeArchLength * i, perNodeArchLength ); } services::SharedPtr<qr::Result> res = alg.getResult(); R = res->get(qr::matrixR); }
void computestep1Local() { /* Initialize FileDataSource<CSVFeatureManager> to retrieve the input data from a .csv file */ FileDataSource<CSVFeatureManager> dataSource(datasetFileNames[rankId], DataSource::doAllocateNumericTable, DataSource::doDictionaryFromContext); /* Retrieve the input data */ dataSource.loadDataBlock(); /* Create an algorithm to compute QR decomposition on local nodes */ qr::Distributed<step1Local> alg; alg.input.set( qr::data, dataSource.getNumericTable() ); /* Compute QR decomposition */ alg.compute(); services::SharedPtr<data_management::DataCollection> dataFromStep1ForStep2; dataFromStep1ForStep2 = alg.getPartialResult()->get( qr::outputOfStep1ForStep2 ); dataFromStep1ForStep3 = alg.getPartialResult()->get( qr::outputOfStep1ForStep3 ); /* Serialize partial results required by step 2 */ InputDataArchive dataArch; dataFromStep1ForStep2->serialize( dataArch ); perNodeArchLength = dataArch.getSizeOfArchive(); /* Serialized data is of equal size on each node if each node called compute() equal number of times */ if (rankId == mpiRoot) { serializedData = services::SharedPtr<byte>( new byte[ perNodeArchLength * nBlocks ] ); } byte *nodeResults = new byte[ perNodeArchLength ]; dataArch.copyArchiveToArray( nodeResults, perNodeArchLength ); /* Transfer partial results to step 2 on the root node */ MPI_Gather( nodeResults, perNodeArchLength, MPI_CHAR, serializedData.get(), perNodeArchLength, MPI_CHAR, mpiRoot, MPI_COMM_WORLD); delete[] nodeResults; }