Changeset 2583 in Sophya for trunk/SophyaLib/TArray/tmatrix.cc
- Timestamp:
- Jul 30, 2004, 12:24:12 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/tmatrix.cc
r2575 r2583 1 // $Id: tmatrix.cc,v 1.2 6 2004-07-29 12:31:16 ansariExp $1 // $Id: tmatrix.cc,v 1.27 2004-07-30 10:24:12 cmv Exp $ 2 2 // C.Magneville 04/99 3 3 #include "machdefs.h" … … 6 6 #include "pexceptions.h" 7 7 #include "tmatrix.h" 8 9 //#define DO_NOT_OPTIMIZE_PRODUCT10 8 11 9 /*! … … 448 446 template <class T> 449 447 TMatrix<T> TMatrix<T>::Multiply(const TMatrix<T>& b, short mm) const 448 // Calcul de C= rm = A*B (A=*this) 449 // Remember: C-like matrices are column packed 450 // Fortan-like matrices are line packed 450 451 { 451 452 if (NCols() != b.NRows()) 452 453 throw(SzMismatchError("TMatrix<T>::Multiply(b) NCols() != b.NRows() ") ); 453 454 454 // Commentaire: pas de difference de vitesse notable selon le s mappings choisis pourla matrice produit "rm"455 // Commentaire: pas de difference de vitesse notable selon le mapping de la matrice produit "rm" 455 456 if (mm == SameMemoryMapping) mm = GetMemoryMapping(); 456 457 TMatrix<T> rm(NRows(), b.NCols(), mm); 457 rm = (T) 0; // Rien ne garantit que rm soit mise a zero a la creation !458 458 459 459 // Les "steps" pour l'adressage des colonnes de A et des lignes de B … … 461 461 sa_size_t stepb = b.Step(b.RowsKA()); 462 462 463 // On decide si on optimise ou non selon les dimensions de A et B 464 // (il semble que optimiser ou non ne degrade pas notablement la vitesse pour les petites matrices) 465 #ifdef DO_NOT_OPTIMIZE_PRODUCT 466 bool no_optim = true; 467 #else 468 bool no_optim = false; 469 //NON juste pour memoire: if((stepa+stepb)*NCols()*sizeof(T)<100000) no_optim=true; 470 #endif 471 472 // Calcul de C=rm = A*B (A=*this) 473 // Remember: C-like matrices are column packed 474 // Fortan-like matrices are line packed 463 // Taille totale des matrices A et B 464 size_t totsiza = this->DataBlock().Size(); 465 size_t totsizb = b.DataBlock().Size(); 466 467 468 /////////////////////////////////////////////////////////////////// 469 // On decide si on optimise ou non selon les dimensions de A et B // 470 // (il semble que optimiser ou non ne degrade pas // 471 // beaucoup la vitesse pour les petites matrices) // 472 //////////////////////////////////////////////////////////////////// 473 474 uint_2 popt = GetMatProdOpt(); 475 bool no_optim = false; // optimization demandee par default 476 if( (popt&(uint_2)1) == 0 ) { // pas d'optimization explicitement demande 477 no_optim = true; 478 } else if( (popt&(uint_2)2) == 0 ) { // pas d'optimization forcee, la methode decide 479 // On part sur une disponibilite dans le cache processeur de 100 ko 480 // (A et B peuvent etre stoquees dans le cache) 481 if((totsiza+totsizb)*sizeof(T)<100000) no_optim = true; 482 } 483 475 484 sa_size_t r,c,k; 476 485 T sum; 477 486 const T * pe; 478 487 479 // Pas d'optimisation demandee 488 489 ///////////////////////////////// 490 // Pas d'optimisation demandee // 491 ///////////////////////////////// 492 480 493 if( no_optim ) { 481 494 //cout<<"no_optim("<<no_optim<<") "<<stepa<<" "<<stepb<<endl; … … 493 506 } 494 507 } 495 } 496 // A.col est packed et B.row est packed (on a interet a optimiser quand meme) 497 else if(stepa==1 && stepb==1) { 508 return rm; 509 } 510 511 512 ////////////////////////////////////////////////////////////////////////////////// 513 // A.col est packed et B.row est packed (on a interet a optimiser quand meme) // 514 ////////////////////////////////////////////////////////////////////////////////// 515 516 if(stepa==1 && stepb==1) { 498 517 //cout<<"A.col packed && B.row not packed "<<stepa<<" "<<stepb<<endl; 499 518 T * pea = new T[rm.NCols()]; … … 510 529 } 511 530 delete [] pea; 512 } 513 // A.col est packed et B.row n'est pas packed 514 else if(stepa==1 && stepb!=1) { 531 return rm; 532 } 533 534 535 ////////////////////////////////////////////////// 536 // A.col est packed et B.row n'est pas packed // 537 ////////////////////////////////////////////////// 538 539 if(stepa==1 && stepb!=1) { 515 540 //cout<<"A.col packed && B.row not packed "<<stepa<<" "<<stepb<<endl; 516 541 const T * pea; … … 527 552 } 528 553 delete [] peb; 529 } 530 // A.col n'est pas packed et B.row est packed 531 else if(stepa!=1 && stepb==1) { 554 return rm; 555 } 556 557 558 ////////////////////////////////////////////////// 559 // A.col n'est pas packed et B.row est packed // 560 ////////////////////////////////////////////////// 561 562 if(stepa!=1 && stepb==1) { 532 563 //cout<<"A.col not packed && B.row packed "<<stepa<<" "<<stepb<<endl; 533 564 T * pea = new T[rm.NCols()]; … … 544 575 } 545 576 delete [] pea; 546 } 547 // A.col n'est pas packed et B.row n'est pas packed, stepb>stepa 548 else if(stepa!=1 && stepb!=1 && stepb>stepa) { 577 return rm; 578 } 579 580 581 //////////////////////////////////////////////////////// 582 // A.col n'est pas packed et B.row n'est pas packed // 583 //////////////////////////////////////////////////////// 584 585 //---- On demande l'optimization par copie d'une des matrices 586 587 if( (popt&(uint_2)4) ) { 588 // On copie la plus petite 589 if(totsiza<totsizb) { // on copie A 590 //cout<<"A.col not packed && B.row not packed ==> copy A to optimize "<<stepa<<" "<<stepb<<endl; 591 // Acopy doit etre C-like pour etre column-packed 592 TMatrix<T> acopy(NRows(),NCols(),BaseArray::CMemoryMapping); 593 acopy = *this; 594 rm = acopy.Multiply(b,mm); 595 } else { // on copie B 596 //cout<<"A.col not packed && B.row not packed ==> copy B to optimize "<<stepa<<" "<<stepb<<endl; 597 // Bcopy doit etre Fortran-like pour etre column-packed 598 TMatrix<T> bcopy(b.NRows(),b.NCols(),BaseArray::FortranMemoryMapping); 599 bcopy = b; 600 rm = Multiply(bcopy,mm); 601 } 602 return rm; 603 } 604 605 //---- stepb>stepa 606 607 if(stepa!=1 && stepb!=1 && stepb>stepa) { 549 608 //cout<<"A.col not packed && B.row not packed ==> optimize on B "<<stepa<<" "<<stepb<<endl; 550 609 const T * pea; … … 561 620 } 562 621 delete [] peb; 563 } 564 // A.col n'est pas packed et B.row n'est pas packed, stepa>=stepb 565 else if(stepa!=1 && stepb!=1) { 622 return rm; 623 } 624 625 //---- stepa>=stepb 626 627 if(stepa!=1 && stepb!=1) { 566 628 //cout<<"A.col not packed && B.row not packed ==> optimize on A "<<stepa<<" "<<stepb<<endl; 567 629 T * pea = new T[rm.NCols()]; … … 578 640 } 579 641 delete [] pea; 580 } 581 else { 582 cout<<"TMatrix<T>::Multiply(b) Optimize case not treated... Please report BUG !!! "<<endl; 583 throw(SzMismatchError("TMatrix<T>::Multiply(b) Optimize case not treated... Please report BUG !!! ") ); 584 } 585 642 return rm; 643 } 644 645 646 ////////////////////////////////////////////////// 647 // Cas non prevu, on ne doit JAMAIS arriver ici // 648 ////////////////////////////////////////////////// 649 cout<<"TMatrix<T>::Multiply(b) Optimize case not treated... Please report BUG !!! "<<endl; 650 throw(SzMismatchError("TMatrix<T>::Multiply(b) Optimize case not treated... Please report BUG !!! ") ); 586 651 return rm; 587 652 }
Note:
See TracChangeset
for help on using the changeset viewer.