void PardisoSolver::setMatrix( cpuCSRMatrix & mat ) { assert(matrix == NULL); assert(mat.getn() == mat.getm()); matrix = &mat; //prepare the internal x,b, and a variables x.assign(mat.getn(),0); b = x; a.resize(mat.geta().size()); for(int i = 0; i < a.size(); i++){ a[i] = 0.0 + mat.geta()[i]; } ia = mat.getia(); for(int i = 0; i < ia.size(); i++){ ia[i]++; } ja = mat.getja(); for(int i = 0; i < ja.size(); i++){ ja[i]++; } if(mat.geta().size() > 0){ //checkMatrix(matrix_type, mat); //factorization: symbolic and numerical int phase = 12; int maxfct =1; /*max nr of factorizations*/ int mnum =1; /* Which factorization to use. */ int n = mat.dim(); checkMatrix(this->matrix_type, a, ia, ja); pardiso (intern_memory, &maxfct, &mnum, &matrix_type, &phase, &n, &a[0], &ia[0], &ja[0], NULL, &nrhs, int_params, &print_stats, NULL, NULL, &error, double_params); } else{ //dummy initialization int phase = 12; int maxfct =1; int mnum =1; int n = mat.dim(); double ddumm; int idumm; pardiso (intern_memory, &maxfct, &mnum, &matrix_type, &phase, &n, &ddumm, &ia[0], &idumm, NULL, &nrhs, int_params, &print_stats, NULL, NULL, &error, double_params); } if(error != 0){ checkMatrix(this->matrix_type, a, ia, ja); throw std::runtime_error("Exception in pardiso solve-"); } }
void Engine::Model::displayDepthMap(DepthMap *dmap, SpotLight *light) { checkMatrix(); dmap->setState(); DeviceContext->VSSetShader(_smProgram->getVertexShader(), NULL, 0); DeviceContext->HSSetShader(_smProgram->getHullShader(), NULL, 0); DeviceContext->DSSetShader(_smProgram->getDomainShader(), NULL, 0); DeviceContext->GSSetShader(_smProgram->getGeometryShader(), NULL, 0); DeviceContext->PSSetShader(_smProgram->getPixelShader(), NULL, 0); _matrix.MVP = *_modelMatrix * light->getVPMatrix(); _matrix.projection = light->getProjectionMatrix(); _matrix.view = light->getViewMatrix(); _matrix.model = *_modelMatrix; _matrix.normal = *_normalMatrix; _matrixBuffer->updateStoreMap(&_matrix); ID3D11Buffer *buf[] = { _matrixBuffer->getBuffer(), }; DeviceContext->VSSetConstantBuffers(0, ARRAYSIZE(buf), buf); DeviceContext->IASetInputLayout(_pInputLayout); DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); for (UINT i = 0; i<_tMesh->size(); i++) if ((*_tMesh)[i]->getMaterial()->getOpacity() == 1.0f) (*_tMesh)[i]->displayShadow(); }
int grammarParse() { push('$'); push('S'); printf("Rule\t\tStep\tStack\n"); printf("\t\t0\t$S\n"); int i = 0; char a; char x; for (i = 0; i < wordlen; ++i){ a = wordToG(wordIndex[i]); FOO: x = pop(); if (isVT(x)) { if (x == a){ printStack(); printf("\n"); continue; } else { printf("Error1!The position is %d\n",i);return 0; } } else { if (x == '$') { if ( x == a) { printf("Success\n");break; } else { printf("Error2!The postition is %d\n",i); return 0; } } else { if (!checkMatrix(x,a,&i)) { printf("(x=%c,a=%c)\n", x,a); printf("Error3!The postition is %d\n",i); return 0; } else{ printf("\b"); printStack(); printf("\n"); goto FOO; } } } printStack(); printf("\n"); } return 1; }
int main(void) { int t, i, j; scanf("%d", &t); scanf("%s", str); myStrrev(str, rev); for(i=0; i<t; i++) { for(j=0; j<t; j++) { checkMatrix(i, j); } } printf("%d\n" ,t - matrix[t][t]); return 0; }
void NormFilterDialog::accept() { // 行列のチェック const QVector< QVector<int> > matrixX(getMatrixX()); const QVector< QVector<int> > matrixY(getMatrixY()); class CheckMatrix { QWidget *parent; public: bool operator()(const QVector< QVector<int> > &matrix) const { if (matrix.empty()) { QMessageBox::warning(parent, tr("Error"), tr("行列の書式が不正です。")); return false; } if (matrix.size() % 2 == 0) { QMessageBox::warning(parent, tr("Error"), tr("行列の行数を奇数にしてください。")); return false; } const int colNum = matrix.first().size(); if (colNum % 2 == 0) { QMessageBox::warning(parent, tr("Error"), tr("行列の列数を奇数にしてください。")); return false; } for (QVector< QVector<int> >::const_iterator it = matrix.begin(); it != matrix.end(); ++it) { if (it->size() != colNum) { QMessageBox::warning(parent, tr("Error"), tr("各行の列数を統一してください。")); return false; } } return true; } CheckMatrix(QWidget *a_parent) : parent(a_parent) { } } checkMatrix(this); if (!(checkMatrix(matrixX) && checkMatrix(matrixY))) { return; } done(QDialog::Accepted); }
void Engine::Model::display(GBuffer *gbuf, PerspCamera *cam) { checkMatrix(); gbuf->setGeometryState(); DeviceContext->VSSetShader(_gProgram->getVertexShader(), NULL, 0); DeviceContext->HSSetShader(_gProgram->getHullShader(), NULL, 0); DeviceContext->DSSetShader(_gProgram->getDomainShader(), NULL, 0); DeviceContext->GSSetShader(_gProgram->getGeometryShader(), NULL, 0); DeviceContext->PSSetShader(_gProgram->getPixelShader(), NULL, 0); _matrix.MVP = *_modelMatrix * cam->getVPMatrix(); _matrix.projection = cam->getProjectionMatrix(); _matrix.view = cam->getViewMatrix(); _matrix.model = *_modelMatrix; _matrix.normal = *_normalMatrix; _matrixBuffer->updateStoreMap(&_matrix); _camera.position = cam->getCameraPosition(); _camera.target = cam->getTargetPosition(); _cameraBuffer->updateStoreMap(&_camera); ID3D11Buffer *buf[] = { _matrixBuffer->getBuffer(), _cameraBuffer->getBuffer(), }; DeviceContext->VSSetConstantBuffers(0, ARRAYSIZE(buf), buf); DeviceContext->IASetInputLayout(_pInputLayout); DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); for (UINT i = 0; i<_tMesh->size(); i++) if ((*_tMesh)[i]->getMaterial()->getOpacity() == 1.0f) { if (_cubeTexture) (*_tMesh)[i]->display(_cubeTexture); else (*_tMesh)[i]->display(); } }
void Engine::StaticModel::displayTransparent(const std::shared_ptr<PerspCamera> &cam) { checkMatrix(); Engine::GraphicsRenderer::Instance().setGeometryState(); glUseProgram(_program->getId()); glUniformMatrix4fv(_MVPMatrixUniformLocation , 1, GL_FALSE, glm::value_ptr(cam->getVPMatrix() * _matrix.model)); glUniformMatrix4fv(_projectionMatrixUniformLocation, 1, GL_FALSE, glm::value_ptr(cam->getProjectionMatrix())); glUniformMatrix4fv(_viewMatrixUniformLocation , 1, GL_FALSE, glm::value_ptr(cam->getViewMatrix())); glUniformMatrix4fv(_modelMatrixUniformLocation , 1, GL_FALSE, glm::value_ptr(_matrix.model)); glUniformMatrix4fv(_normalMatrixUniformLocation , 1, GL_FALSE, glm::value_ptr(_matrix.normal)); for (GLuint i = 0; i < _tMesh->size(); i++) if ((*_tMesh)[i]->getMaterial()->getOpacity() < 1.0f) { if (_cubeTexture) (*_tMesh)[i]->display(_cubeTexture); else (*_tMesh)[i]->display(); } }
int ProcParty::countCheckLetters(const QImage & imgCheck) { //очерняем const int width = imgCheck.width(); const int height = imgCheck.height(); BoolMatrix checkMatrix(imgCheck); for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { QRgb rgb = imgCheck.pixel(x, y); QColor cl(rgb); if (cl.hue() >= 13 && cl.hue() <= 33) { checkMatrix.set(x, y, false); //imgCheck.setPixel(x, y, qRgb(0, 0, 0)); } else { checkMatrix.set(x, y, true); //imgCheck.setPixel(x, y, qRgb(255, 255, 255)); } } } //сканируем рисунок на предмет пробелов int countLetters = 0; int count = 0; bool isBlackLinePrev = true; bool isBlackLineCurr = true; bool isLetterFinish = false; QPoint ptLeft, ptRight; for (int w = 0; w < width; ++w) { isLetterFinish = false; isBlackLineCurr = true; for (int h = 0; h < height; ++h) { if (checkMatrix.at(w, h) == true) { isBlackLineCurr = false; break; } } if ((isBlackLinePrev == true) && (isBlackLineCurr == false)) { countLetters++; isBlackLinePrev = false; } else if ((isBlackLinePrev == false) && (isBlackLineCurr == true)) { isBlackLinePrev = true; isLetterFinish = true; } if (isLetterFinish) { count++; } } return count; }
int main(int argc, char **argv) { // Check number of arguments if (argc != 2) { printf("lab4 [number of threads]\n"); return 0; } // Get max number of threads from command line input int maxThreads = atoi(argv[1]); // Initialize matrixA and matrixB init(); // Initialize time values struct timeval start, end; printf("Threads\t\tSeconds\n"); // Multiply matrix with a single thread gettimeofday(&start, NULL); matrixMultiply(); gettimeofday(&end, NULL); printf("1\t\t%f\n", (((end.tv_sec*MICRO_SEC+end.tv_usec)-(start.tv_sec*MICRO_SEC+start.tv_usec))/MICRO_SEC)); // Create array of threads pthread_t threads[maxThreads]; // Initialize mutex pthread_mutex_init(&mutex, NULL); // Multiply matrices with i threads int i, j; for (i = 2; i <= maxThreads; i++) { numThreads = i; threadCounter = 0; gettimeofday(&start, NULL); for (j = 0; j < i; j++) pthread_create(&threads[j], NULL, &multiplyRows, NULL); for (j = 0; j < i; j++) pthread_join(threads[j], NULL); gettimeofday(&end, NULL); printf("%d\t\t%f\t", i, (((end.tv_sec*MICRO_SEC+end.tv_usec)-(start.tv_sec*MICRO_SEC+start.tv_usec))/MICRO_SEC)); // Verify threaded mutliplication if (checkMatrix() != 0) printf("error in calculation\n"); else printf("no errors\n"); } // Print statements // printMatrixASelection(0, 0); // printMatrixBSelection(0, 0); // printMatrixResultSelection(0, 0); // printMatrixResultSelection(0, 0); // Clean up mutex pthread_mutex_destroy(&mutex); return 0; }