diff options
115 files changed, 8825 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 033e45ae4..95d5ff1a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,12 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.4) OPTION(BUILD_TESTS "Build tests" OFF) OPTION(BUILD_DOC "Build documentation and examples" OFF) OPTION(BUILD_DEMOS "Build demos" OFF) -OPTION(TEST_LIB "Build the unit tests using the library (disable -pedantic)" OFF) +OPTION(BUILD_LIB "Build the binary shared library" OFF) +OPTION(BUILD_BTL "Build benchmark suite" OFF) + +IF(BUILD_LIB) + OPTION(TEST_LIB "Build the unit tests using the library (disable -pedantic)" OFF) +ENDIF(BUILD_LIB) SET(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -35,4 +40,8 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}) ADD_SUBDIRECTORY(Eigen) ADD_SUBDIRECTORY(test) ADD_SUBDIRECTORY(doc) -ADD_SUBDIRECTORY(demos)
\ No newline at end of file +ADD_SUBDIRECTORY(demos) + +IF(BUILD_BTL) +ADD_SUBDIRECTORY(bench/btl) +ENDIF(BUILD_BTL) diff --git a/bench/btl/CMakeLists.txt b/bench/btl/CMakeLists.txt new file mode 100644 index 000000000..adcb62a52 --- /dev/null +++ b/bench/btl/CMakeLists.txt @@ -0,0 +1,74 @@ +PROJECT(BTL) + +CMAKE_MINIMUM_REQUIRED(VERSION 2.4) + +set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) +include(MacroOptionalAddSubdirectory) + +OPTION(BTL_NOVEC "Disable SSE/Altivec optimizations when possible" OFF) + +SET(CMAKE_INCLUDE_CURRENT_DIR ON) + +IF(CMAKE_COMPILER_IS_GNUCXX) + SET(CMAKE_CXX_FLAGS "-g0 -O3 -DNDEBUG") + IF(NOT BTL_NOVEC) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2") + ELSE(NOT BTL_NOVEC) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DEIGEN_DONT_VECTORIZE") + ENDIF(NOT BTL_NOVEC) +ENDIF(CMAKE_COMPILER_IS_GNUCXX) + +include_directories( + ${PROJECT_SOURCE_DIR}/actions + ${PROJECT_SOURCE_DIR}/generic_bench + ${PROJECT_SOURCE_DIR}/generic_bench/utils + ${PROJECT_SOURCE_DIR}/libs/STL) + + +MACRO(BTL_ADD_BENCH targetname) + ADD_EXECUTABLE(${ARGV}) + ADD_TEST(${targetname} "${targetname}") +ENDMACRO(BTL_ADD_BENCH) + +ENABLE_TESTING() + +# Eigen2 +find_package(Eigen2) +if (EIGEN2_FOUND) + macro_optional_add_subdirectory(libs/eigen2 ON) +endif (EIGEN2_FOUND) + +# GMM++ +find_package(GMM) +if (GMM_FOUND) + macro_optional_add_subdirectory(libs/gmm ON) +endif (GMM_FOUND) + +# Boost +find_package(Boost) +if (Boost_FOUND) + include_directories(${Boost_INCLUDE_DIRS}) + macro_optional_add_subdirectory(libs/ublas ON) +endif (Boost_FOUND) + +# blitz +find_package(Blitz) +if (BLITZ_FOUND) + macro_optional_add_subdirectory(libs/blitz ON) + macro_optional_add_subdirectory(libs/tiny_blitz ON) +endif (BLITZ_FOUND) + +# cblas +find_package(CBLAS) +if (CBLAS_FOUND) + macro_optional_add_subdirectory(libs/C_BLAS ON) +endif (CBLAS_FOUND) + + +macro_optional_add_subdirectory(libs/f77 ON) +macro_optional_add_subdirectory(libs/C ON) +macro_optional_add_subdirectory(libs/STL ON) +macro_optional_add_subdirectory(libs/STL_algo ON) + +add_subdirectory(data) + diff --git a/bench/btl/COPYING b/bench/btl/COPYING new file mode 100644 index 000000000..486449cc3 --- /dev/null +++ b/bench/btl/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 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 + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/bench/btl/README b/bench/btl/README new file mode 100644 index 000000000..6d5712bb6 --- /dev/null +++ b/bench/btl/README @@ -0,0 +1,143 @@ +Bench Template Library + +**************************************** +Introduction : + +The aim of this project is to compare the performance +of available numerical libraries. The code is designed +as generic and modular as possible. Thus, adding new +numerical libraries or new numerical tests should +require minimal effort. + + +***************************************** + +Installation : + +BTL uses cmake / ctest: + +1 - create a build directory: + + $ mkdir build + $ cd build + +2 - configure: + + $ ccmake .. + +3 - run the bench using ctest: + + $ ctest -V + +You can also run a single bench, e.g.: ctest -V -R eigen + +4 : Analyze the result. different data files (.dat) are produced in each libs directories. + If gnuplot is available, choose a directory name in the data directory to store the results and type + cd data + mkdir my_directory + cp ../libs/*/*.dat my_directory + Build the data utilities in this (data) directory + make + Then you can look the raw data, + go_mean my_directory + or smooth the data first : + smooth_all.sh my_directory + go_mean my_directory_smooth + + +************************************************* + +Files and directories : + + generic_bench : all the bench sources common to all libraries + + actions : sources for different action wrappers (axpy, matrix-matrix product) to be tested. + + libs/* : bench sources specific to each tested libraries. + + machine_dep : directory used to store machine specific Makefile.in + + data : directory used to store gnuplot scripts and data analysis utilities + +************************************************** + +Principles : the code modularity is achieved by defining two concepts : + + ****** Action concept : This is a class defining which kind + of test must be performed (e.g. a matrix_vector_product). + An Action should define the following methods : + + *** Ctor using the size of the problem (matrix or vector size) as an argument + Action action(size); + *** initialize : this method initialize the calculation (e.g. initialize the matrices and vectors arguments) + action.initialize(); + *** calculate : this method actually launch the calculation to be benchmarked + action.calculate; + *** nb_op_base() : this method returns the complexity of the calculate method (allowing the mflops evaluation) + *** name() : this method returns the name of the action (std::string) + + ****** Interface concept : This is a class or namespace defining how to use a given library and + its specific containers (matrix and vector). Up to now an interface should following types + + *** real_type : kind of float to be used (float or double) + *** stl_vector : must correspond to std::vector<real_type> + *** stl_matrix : must correspond to std::vector<stl_vector> + *** gene_vector : the vector type for this interface --> e.g. (real_type *) for the C_interface + *** gene_matrix : the matrix type for this interface --> e.g. (gene_vector *) for the C_interface + + + the following common methods + + *** free_matrix(gene_matrix & A, int N) dealocation of a N sized gene_matrix A + *** free_vector(gene_vector & B) dealocation of a N sized gene_vector B + *** matrix_from_stl(gene_matrix & A, stl_matrix & A_stl) copy the content of an stl_matrix A_stl into a gene_matrix A. + The allocation of A is done in this function. + *** vector_to_stl(gene_vector & B, stl_vector & B_stl) copy the content of an stl_vector B_stl into a gene_vector B. + The allocation of B is done in this function. + *** matrix_to_stl(gene_matrix & A, stl_matrix & A_stl) copy the content of an gene_matrix A into an stl_matrix A_stl. + The size of A_STL must corresponds to the size of A. + *** vector_to_stl(gene_vector & A, stl_vector & A_stl) copy the content of an gene_vector A into an stl_vector A_stl. + The size of B_STL must corresponds to the size of B. + *** copy_matrix(gene_matrix & source, gene_matrix & cible, int N) : copy the content of source in cible. Both source + and cible must be sized NxN. + *** copy_vector(gene_vector & source, gene_vector & cible, int N) : copy the content of source in cible. Both source + and cible must be sized N. + + and the following method corresponding to the action one wants to be benchmarked : + + *** matrix_vector_product(const gene_matrix & A, const gene_vector & B, gene_vector & X, int N) + *** matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N) + *** ata_product(const gene_matrix & A, gene_matrix & X, int N) + *** aat_product(const gene_matrix & A, gene_matrix & X, int N) + *** axpy(real coef, const gene_vector & X, gene_vector & Y, int N) + + The bench algorithm (generic_bench/bench.hh) is templated with an action itself templated with + an interface. A typical main.cpp source stored in a given library directory libs/A_LIB + looks like : + + bench< AN_ACTION < AN_INTERFACE > >( 10 , 1000 , 50 ) ; + + this function will produce XY data file containing measured mflops as a function of the size for 50 + sizes between 10 and 10000. + + This algorithm can be adapted by providing a given Perf_Analyzer object which determines how the time + measurements must be done. For example, the X86_Perf_Analyzer use the asm rdtsc function and provides + a very fast and accurate (but less portable) timing method. The default is the Portable_Perf_Analyzer + so + + bench< AN_ACTION < AN_INTERFACE > >( 10 , 1000 , 50 ) ; + + is equivalent to + + bench< Portable_Perf_Analyzer,AN_ACTION < AN_INTERFACE > >( 10 , 1000 , 50 ) ; + + If your system supports it we suggest to use a mixed implementation (X86_perf_Analyzer+Portable_Perf_Analyzer). + replace + bench<Portable_Perf_Analyzer,Action>(size_min,size_max,nb_point); + with + bench<Mixed_Perf_Analyzer,Action>(size_min,size_max,nb_point); + in generic/bench.hh + +. + + + diff --git a/bench/btl/actions/action_aat_product.hh b/bench/btl/actions/action_aat_product.hh new file mode 100644 index 000000000..3d11e7d6f --- /dev/null +++ b/bench/btl/actions/action_aat_product.hh @@ -0,0 +1,145 @@ +//===================================================== +// File : action_aat_product.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef ACTION_AAT_PRODUCT +#define ACTION_AAT_PRODUCT +#include "utilities.h" +#include "STL_interface.hh" +#include <string> +#include "init/init_function.hh" +#include "init/init_vector.hh" +#include "init/init_matrix.hh" + +using namespace std; + +template<class Interface> +class Action_aat_product { + +public : + + // Ctor + + Action_aat_product( int size ):_size(size) + { + MESSAGE("Action_aat_product Ctor"); + + // STL matrix and vector initialization + + init_matrix<pseudo_random>(A_stl,_size); + init_matrix<null_function>(X_stl,_size); + init_matrix<null_function>(resu_stl,_size); + + // generic matrix and vector initialization + + Interface::matrix_from_stl(A_ref,A_stl); + Interface::matrix_from_stl(X_ref,X_stl); + + Interface::matrix_from_stl(A,A_stl); + Interface::matrix_from_stl(X,X_stl); + + } + + // invalidate copy ctor + + Action_aat_product( const Action_aat_product & ) + { + INFOS("illegal call to Action_aat_product Copy Ctor"); + exit(0); + } + + // Dtor + + ~Action_aat_product( void ){ + + MESSAGE("Action_aat_product Dtor"); + + // deallocation + + Interface::free_matrix(A,_size); + Interface::free_matrix(X,_size); + + Interface::free_matrix(A_ref,_size); + Interface::free_matrix(X_ref,_size); + + } + + // action name + + static inline std::string name( void ) + { + return "aat_"+Interface::name(); + } + + double nb_op_base( void ){ + return 2.0*_size*_size*_size; + } + + inline void initialize( void ){ + + Interface::copy_matrix(A_ref,A,_size); + Interface::copy_matrix(X_ref,X,_size); + + } + + inline void calculate( void ) { + + Interface::aat_product(A,X,_size); + + } + + void check_result( void ){ + + // calculation check + + Interface::matrix_to_stl(X,resu_stl); + + STL_interface<typename Interface::real_type>::aat_product(A_stl,X_stl,_size); + + typename Interface::real_type error= + STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl); + + if (error>1.e-6){ + INFOS("WRONG CALCULATION...residual=" << error); + exit(1); + } + + } + +private : + + typename Interface::stl_matrix A_stl; + typename Interface::stl_matrix X_stl; + typename Interface::stl_matrix resu_stl; + + typename Interface::gene_matrix A_ref; + typename Interface::gene_matrix X_ref; + + typename Interface::gene_matrix A; + typename Interface::gene_matrix X; + + + int _size; + +}; + + +#endif + + + diff --git a/bench/btl/actions/action_ata_product.hh b/bench/btl/actions/action_ata_product.hh new file mode 100644 index 000000000..47531d607 --- /dev/null +++ b/bench/btl/actions/action_ata_product.hh @@ -0,0 +1,145 @@ +//===================================================== +// File : action_ata_product.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef ACTION_ATA_PRODUCT +#define ACTION_ATA_PRODUCT +#include "utilities.h" +#include "STL_interface.hh" +#include <string> +#include "init/init_function.hh" +#include "init/init_vector.hh" +#include "init/init_matrix.hh" + +using namespace std; + +template<class Interface> +class Action_ata_product { + +public : + + // Ctor + + Action_ata_product( int size ):_size(size) + { + MESSAGE("Action_ata_product Ctor"); + + // STL matrix and vector initialization + + init_matrix<pseudo_random>(A_stl,_size); + init_matrix<null_function>(X_stl,_size); + init_matrix<null_function>(resu_stl,_size); + + // generic matrix and vector initialization + + Interface::matrix_from_stl(A_ref,A_stl); + Interface::matrix_from_stl(X_ref,X_stl); + + Interface::matrix_from_stl(A,A_stl); + Interface::matrix_from_stl(X,X_stl); + + } + + // invalidate copy ctor + + Action_ata_product( const Action_ata_product & ) + { + INFOS("illegal call to Action_ata_product Copy Ctor"); + exit(0); + } + + // Dtor + + ~Action_ata_product( void ){ + + MESSAGE("Action_ata_product Dtor"); + + // deallocation + + Interface::free_matrix(A,_size); + Interface::free_matrix(X,_size); + + Interface::free_matrix(A_ref,_size); + Interface::free_matrix(X_ref,_size); + + } + + // action name + + static inline std::string name( void ) + { + return "ata_"+Interface::name(); + } + + double nb_op_base( void ){ + return 2.0*_size*_size*_size; + } + + inline void initialize( void ){ + + Interface::copy_matrix(A_ref,A,_size); + Interface::copy_matrix(X_ref,X,_size); + + } + + inline void calculate( void ) { + + Interface::ata_product(A,X,_size); + + } + + void check_result( void ){ + + // calculation check + + Interface::matrix_to_stl(X,resu_stl); + + STL_interface<typename Interface::real_type>::ata_product(A_stl,X_stl,_size); + + typename Interface::real_type error= + STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl); + + if (error>1.e-6){ + INFOS("WRONG CALCULATION...residual=" << error); + exit(1); + } + + } + +private : + + typename Interface::stl_matrix A_stl; + typename Interface::stl_matrix X_stl; + typename Interface::stl_matrix resu_stl; + + typename Interface::gene_matrix A_ref; + typename Interface::gene_matrix X_ref; + + typename Interface::gene_matrix A; + typename Interface::gene_matrix X; + + + int _size; + +}; + + +#endif + + + diff --git a/bench/btl/actions/action_atv_product.hh b/bench/btl/actions/action_atv_product.hh new file mode 100644 index 000000000..9041885fc --- /dev/null +++ b/bench/btl/actions/action_atv_product.hh @@ -0,0 +1,131 @@ +//===================================================== +// File : action_atv_product.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef ACTION_ATV_PRODUCT +#define ACTION_ATV_PRODUCT +#include "utilities.h" +#include "STL_interface.hh" +#include <string> +#include "init/init_function.hh" +#include "init/init_vector.hh" +#include "init/init_matrix.hh" + +using namespace std; + +template<class Interface> +class Action_atv_product { + +public : + + Action_atv_product( int size ) : _size(size) + { + MESSAGE("Action_atv_product Ctor"); + + // STL matrix and vector initialization + + init_matrix<pseudo_random>(A_stl,_size); + init_vector<pseudo_random>(B_stl,_size); + init_vector<null_function>(X_stl,_size); + init_vector<null_function>(resu_stl,_size); + + // generic matrix and vector initialization + + Interface::matrix_from_stl(A_ref,A_stl); + Interface::vector_from_stl(B_ref,B_stl); + Interface::vector_from_stl(X_ref,X_stl); + + Interface::matrix_from_stl(A,A_stl); + Interface::vector_from_stl(B,B_stl); + Interface::vector_from_stl(X,X_stl); + } + + // invalidate copy ctor + Action_atv_product( const Action_atv_product & ) + { + INFOS("illegal call to Action_atv_product Copy Ctor"); + exit(1); + } + + ~Action_atv_product( void ) + { + MESSAGE("Action_atv_product Dtor"); + + Interface::free_matrix(A,_size); + Interface::free_vector(B); + Interface::free_vector(X); + + Interface::free_matrix(A_ref,_size); + Interface::free_vector(B_ref); + Interface::free_vector(X_ref); + } + + static inline std::string name() { return "atv_" + Interface::name(); } + + double nb_op_base( void ) { return 2.0*_size*_size; } + + inline void initialize( void ){ + Interface::copy_matrix(A_ref,A,_size); + Interface::copy_vector(B_ref,B,_size); + Interface::copy_vector(X_ref,X,_size); + } + + inline void calculate( void ) { + Interface::atv_product(A,B,X,_size); + } + + void check_result( void ) + { + Interface::vector_to_stl(X,resu_stl); + + STL_interface<typename Interface::real_type>::atv_product(A_stl,B_stl,X_stl,_size); + + typename Interface::real_type error= + STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl); + + if (error>1.e-6){ + INFOS("WRONG CALCULATION...residual=" << error); + exit(0); + } + } + +private : + + typename Interface::stl_matrix A_stl; + typename Interface::stl_vector B_stl; + typename Interface::stl_vector X_stl; + typename Interface::stl_vector resu_stl; + + typename Interface::gene_matrix A_ref; + typename Interface::gene_vector B_ref; + typename Interface::gene_vector X_ref; + + typename Interface::gene_matrix A; + typename Interface::gene_vector B; + typename Interface::gene_vector X; + + + int _size; + +}; + + +#endif + + + diff --git a/bench/btl/actions/action_axpy.hh b/bench/btl/actions/action_axpy.hh new file mode 100644 index 000000000..8740e413d --- /dev/null +++ b/bench/btl/actions/action_axpy.hh @@ -0,0 +1,137 @@ +//===================================================== +// File : action_axpy.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef ACTION_AXPY +#define ACTION_AXPY +#include "utilities.h" +#include "STL_interface.hh" +#include <string> +#include "init/init_function.hh" +#include "init/init_vector.hh" +#include "init/init_matrix.hh" + +using namespace std; + +template<class Interface> +class Action_axpy { + +public : + + // Ctor + + Action_axpy( int size ):_size(size),_coef(1.0) + { + MESSAGE("Action_axpy Ctor"); + + // STL vector initialization + + init_vector<pseudo_random>(X_stl,_size); + init_vector<pseudo_random>(Y_stl,_size); + init_vector<null_function>(resu_stl,_size); + + // generic matrix and vector initialization + + Interface::vector_from_stl(X_ref,X_stl); + Interface::vector_from_stl(Y_ref,Y_stl); + + Interface::vector_from_stl(X,X_stl); + Interface::vector_from_stl(Y,Y_stl); + + + } + + // invalidate copy ctor + + Action_axpy( const Action_axpy & ) + { + INFOS("illegal call to Action_axpy Copy Ctor"); + exit(1); + } + + // Dtor + + ~Action_axpy( void ){ + + MESSAGE("Action_axpy Dtor"); + + // deallocation + + Interface::free_vector(X_ref); + Interface::free_vector(Y_ref); + + Interface::free_vector(X); + Interface::free_vector(Y); + } + + // action name + + static inline std::string name( void ) + { + return "axpy_"+Interface::name(); + } + + double nb_op_base( void ){ + return 2.0*_size; + } + + inline void initialize( void ){ + Interface::copy_vector(X_ref,X,_size); + Interface::copy_vector(Y_ref,Y,_size); + } + + inline void calculate( void ) { + Interface::axpy(_coef,X,Y,_size); + } + + void check_result( void ){ + + // calculation check + + Interface::vector_to_stl(Y,resu_stl); + + STL_interface<typename Interface::real_type>::axpy(_coef,X_stl,Y_stl,_size); + + typename Interface::real_type error= + STL_interface<typename Interface::real_type>::norm_diff(Y_stl,resu_stl); + + if (error>1.e-6){ + INFOS("WRONG CALCULATION...residual=" << error); + exit(0); + } + + } + +private : + + typename Interface::stl_vector X_stl; + typename Interface::stl_vector Y_stl; + typename Interface::stl_vector resu_stl; + + typename Interface::gene_vector X_ref; + typename Interface::gene_vector Y_ref; + + typename Interface::gene_vector X; + typename Interface::gene_vector Y; + + typename Interface::real_type _coef; + + int _size; +}; + +#endif diff --git a/bench/btl/actions/action_lu_solve.hh b/bench/btl/actions/action_lu_solve.hh new file mode 100644 index 000000000..5a81e6341 --- /dev/null +++ b/bench/btl/actions/action_lu_solve.hh @@ -0,0 +1,136 @@ +//===================================================== +// File : action_lu_solve.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef ACTION_LU_SOLVE +#define ACTION_LU_SOLVE +#include "utilities.h" +#include "STL_interface.hh" +#include <string> +#include "init/init_function.hh" +#include "init/init_vector.hh" +#include "init/init_matrix.hh" + +using namespace std; + +template<class Interface> +class Action_lu_solve +{ + +public : + + static inline std::string name( void ) + { + return "lu_solve_"+Interface::name(); + } + + static double nb_op_base(int size){ + return 2.0*size*size*size/3.0; // questionable but not really important + } + + + static double calculate( int nb_calc, int size ) { + + // STL matrix and vector initialization + + typename Interface::stl_matrix A_stl; + typename Interface::stl_vector B_stl; + typename Interface::stl_vector X_stl; + + init_matrix<pseudo_random>(A_stl,size); + init_vector<pseudo_random>(B_stl,size); + init_vector<null_function>(X_stl,size); + + // generic matrix and vector initialization + + typename Interface::gene_matrix A; + typename Interface::gene_vector B; + typename Interface::gene_vector X; + + typename Interface::gene_matrix LU; + + Interface::matrix_from_stl(A,A_stl); + Interface::vector_from_stl(B,B_stl); + Interface::vector_from_stl(X,X_stl); + Interface::matrix_from_stl(LU,A_stl); + + // local variable : + + typename Interface::Pivot_Vector pivot; // pivot vector + Interface::new_Pivot_Vector(pivot,size); + + // timer utilities + + Portable_Timer chronos; + + // time measurement + + chronos.start(); + + for (int ii=0;ii<nb_calc;ii++){ + + // LU factorization + Interface::copy_matrix(A,LU,size); + Interface::LU_factor(LU,pivot,size); + + // LU solve + + Interface::LU_solve(LU,pivot,B,X,size); + + } + + // Time stop + + chronos.stop(); + + double time=chronos.user_time(); + + // check result : + + typename Interface::stl_vector B_new_stl(size); + Interface::vector_to_stl(X,X_stl); + + STL_interface<typename Interface::real_type>::matrix_vector_product(A_stl,X_stl,B_new_stl,size); + + typename Interface::real_type error= + STL_interface<typename Interface::real_type>::norm_diff(B_stl,B_new_stl); + + if (error>1.e-5){ + INFOS("WRONG CALCULATION...residual=" << error); + STL_interface<typename Interface::real_type>::display_vector(B_stl); + STL_interface<typename Interface::real_type>::display_vector(B_new_stl); + exit(0); + } + + // deallocation and return time + + Interface::free_matrix(A,size); + Interface::free_vector(B); + Interface::free_vector(X); + Interface::free_Pivot_Vector(pivot); + + return time; + } + +}; + + +#endif + + + diff --git a/bench/btl/actions/action_matrix_matrix_product.hh b/bench/btl/actions/action_matrix_matrix_product.hh new file mode 100644 index 000000000..9de677a7f --- /dev/null +++ b/bench/btl/actions/action_matrix_matrix_product.hh @@ -0,0 +1,152 @@ +//===================================================== +// File : action_matrix_matrix_product.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef ACTION_MATRIX_MATRIX_PRODUCT +#define ACTION_MATRIX_MATRIX_PRODUCT +#include "utilities.h" +#include "STL_interface.hh" +#include <string> +#include "init/init_function.hh" +#include "init/init_vector.hh" +#include "init/init_matrix.hh" + +using namespace std; + +template<class Interface> +class Action_matrix_matrix_product { + +public : + + // Ctor + + Action_matrix_matrix_product( int size ):_size(size) + { + MESSAGE("Action_matrix_matrix_product Ctor"); + + // STL matrix and vector initialization + + init_matrix<pseudo_random>(A_stl,_size); + init_matrix<pseudo_random>(B_stl,_size); + init_matrix<null_function>(X_stl,_size); + init_matrix<null_function>(resu_stl,_size); + + // generic matrix and vector initialization + + Interface::matrix_from_stl(A_ref,A_stl); + Interface::matrix_from_stl(B_ref,B_stl); + Interface::matrix_from_stl(X_ref,X_stl); + + Interface::matrix_from_stl(A,A_stl); + Interface::matrix_from_stl(B,B_stl); + Interface::matrix_from_stl(X,X_stl); + + } + + // invalidate copy ctor + + Action_matrix_matrix_product( const Action_matrix_matrix_product & ) + { + INFOS("illegal call to Action_matrix_matrix_product Copy Ctor"); + exit(0); + } + + // Dtor + + ~Action_matrix_matrix_product( void ){ + + MESSAGE("Action_matrix_matrix_product Dtor"); + + // deallocation + + Interface::free_matrix(A,_size); + Interface::free_matrix(B,_size); + Interface::free_matrix(X,_size); + + Interface::free_matrix(A_ref,_size); + Interface::free_matrix(B_ref,_size); + Interface::free_matrix(X_ref,_size); + + } + + // action name + + static inline std::string name( void ) + { + return "matrix_matrix_"+Interface::name(); + } + + double nb_op_base( void ){ + return 2.0*_size*_size*_size; + } + + inline void initialize( void ){ + + Interface::copy_matrix(A_ref,A,_size); + Interface::copy_matrix(B_ref,B,_size); + Interface::copy_matrix(X_ref,X,_size); + + } + + inline void calculate( void ) { + Interface::matrix_matrix_product(A,B,X,_size); + } + + void check_result( void ){ + + // calculation check + + Interface::matrix_to_stl(X,resu_stl); + + STL_interface<typename Interface::real_type>::matrix_matrix_product(A_stl,B_stl,X_stl,_size); + + typename Interface::real_type error= + STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl); + + if (error>1.e-6){ + INFOS("WRONG CALCULATION...residual=" << error); + exit(1); + } + + } + +private : + + typename Interface::stl_matrix A_stl; + typename Interface::stl_matrix B_stl; + typename Interface::stl_matrix X_stl; + typename Interface::stl_matrix resu_stl; + + typename Interface::gene_matrix A_ref; + typename Interface::gene_matrix B_ref; + typename Interface::gene_matrix X_ref; + + typename Interface::gene_matrix A; + typename Interface::gene_matrix B; + typename Interface::gene_matrix X; + + + int _size; + +}; + + +#endif + + + diff --git a/bench/btl/actions/action_matrix_matrix_product_bis.hh b/bench/btl/actions/action_matrix_matrix_product_bis.hh new file mode 100644 index 000000000..29c10a6e2 --- /dev/null +++ b/bench/btl/actions/action_matrix_matrix_product_bis.hh @@ -0,0 +1,152 @@ +//===================================================== +// File : action_matrix_matrix_product_bis.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef ACTION_MATRIX_MATRIX_PRODUCT_BIS +#define ACTION_MATRIX_MATRIX_PRODUCT_BIS +#include "utilities.h" +#include "STL_interface.hh" +#include "STL_timer.hh" +#include <string> +#include "init_function.hh" +#include "init_vector.hh" +#include "init_matrix.hh" + +using namespace std; + +template<class Interface> +class Action_matrix_matrix_product_bis { + +public : + + static inline std::string name( void ) + { + return "matrix_matrix_"+Interface::name(); + } + + static double nb_op_base(int size){ + return 2.0*size*size*size; + } + + static double calculate( int nb_calc, int size ) { + + // STL matrix and vector initialization + + typename Interface::stl_matrix A_stl; + typename Interface::stl_matrix B_stl; + typename Interface::stl_matrix X_stl; + + init_matrix<pseudo_random>(A_stl,size); + init_matrix<pseudo_random>(B_stl,size); + init_matrix<null_function>(X_stl,size); + + // generic matrix and vector initialization + + typename Interface::gene_matrix A_ref; + typename Interface::gene_matrix B_ref; + typename Interface::gene_matrix X_ref; + + typename Interface::gene_matrix A; + typename Interface::gene_matrix B; + typename Interface::gene_matrix X; + + + Interface::matrix_from_stl(A_ref,A_stl); + Interface::matrix_from_stl(B_ref,B_stl); + Interface::matrix_from_stl(X_ref,X_stl); + + Interface::matrix_from_stl(A,A_stl); + Interface::matrix_from_stl(B,B_stl); + Interface::matrix_from_stl(X,X_stl); + + + // STL_timer utilities + + STL_timer chronos; + + // Baseline evaluation + + chronos.start_baseline(nb_calc); + + do { + + Interface::copy_matrix(A_ref,A,size); + Interface::copy_matrix(B_ref,B,size); + Interface::copy_matrix(X_ref,X,size); + + + // Interface::matrix_matrix_product(A,B,X,size); This line must be commented !!!! + } + while(chronos.check()); + + chronos.report(true); + + // Time measurement + + chronos.start(nb_calc); + + do { + + Interface::copy_matrix(A_ref,A,size); + Interface::copy_matrix(B_ref,B,size); + Interface::copy_matrix(X_ref,X,size); + + Interface::matrix_matrix_product(A,B,X,size); // here it is not commented !!!! + } + while(chronos.check()); + + chronos.report(true); + + double time=chronos.calculated_time/2000.0; + + // calculation check + + typename Interface::stl_matrix resu_stl(size); + + Interface::matrix_to_stl(X,resu_stl); + + STL_interface<typename Interface::real_type>::matrix_matrix_product(A_stl,B_stl,X_stl,size); + + typename Interface::real_type error= + STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl); + + if (error>1.e-6){ + INFOS("WRONG CALCULATION...residual=" << error); + exit(1); + } + + // deallocation and return time + + Interface::free_matrix(A,size); + Interface::free_matrix(B,size); + Interface::free_matrix(X,size); + + Interface::free_matrix(A_ref,size); + Interface::free_matrix(B_ref,size); + Interface::free_matrix(X_ref,size); + + return time; + } + +}; + + +#endif + + + diff --git a/bench/btl/actions/action_matrix_vector_product.hh b/bench/btl/actions/action_matrix_vector_product.hh new file mode 100644 index 000000000..ee9110d06 --- /dev/null +++ b/bench/btl/actions/action_matrix_vector_product.hh @@ -0,0 +1,154 @@ +//===================================================== +// File : action_matrix_vector_product.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef ACTION_MATRIX_VECTOR_PRODUCT +#define ACTION_MATRIX_VECTOR_PRODUCT +#include "utilities.h" +#include "STL_interface.hh" +#include <string> +#include "init/init_function.hh" +#include "init/init_vector.hh" +#include "init/init_matrix.hh" + +using namespace std; + +template<class Interface> +class Action_matrix_vector_product { + +public : + + // Ctor + + Action_matrix_vector_product( int size ):_size(size) + { + MESSAGE("Action_matrix_vector_product Ctor"); + + // STL matrix and vector initialization + + init_matrix<pseudo_random>(A_stl,_size); + init_vector<pseudo_random>(B_stl,_size); + init_vector<null_function>(X_stl,_size); + init_vector<null_function>(resu_stl,_size); + + // generic matrix and vector initialization + + Interface::matrix_from_stl(A_ref,A_stl); + Interface::vector_from_stl(B_ref,B_stl); + Interface::vector_from_stl(X_ref,X_stl); + + Interface::matrix_from_stl(A,A_stl); + Interface::vector_from_stl(B,B_stl); + Interface::vector_from_stl(X,X_stl); + + } + + // invalidate copy ctor + + Action_matrix_vector_product( const Action_matrix_vector_product & ) + { + INFOS("illegal call to Action_matrix_vector_product Copy Ctor"); + exit(1); + } + + // Dtor + + ~Action_matrix_vector_product( void ){ + + MESSAGE("Action_matrix_vector_product Dtor"); + + // deallocation + + Interface::free_matrix(A,_size); + Interface::free_vector(B); + Interface::free_vector(X); + + Interface::free_matrix(A_ref,_size); + Interface::free_vector(B_ref); + Interface::free_vector(X_ref); + + } + + // action name + + static inline std::string name( void ) + { + return "matrix_vector_"+Interface::name(); + } + + double nb_op_base( void ){ + return 2.0*_size*_size; + } + + inline void initialize( void ){ + + Interface::copy_matrix(A_ref,A,_size); + Interface::copy_vector(B_ref,B,_size); + Interface::copy_vector(X_ref,X,_size); + + } + + inline void calculate( void ) { + + Interface::matrix_vector_product(A,B,X,_size); + + } + + void check_result( void ){ + + // calculation check + + Interface::vector_to_stl(X,resu_stl); + + STL_interface<typename Interface::real_type>::matrix_vector_product(A_stl,B_stl,X_stl,_size); + + typename Interface::real_type error= + STL_interface<typename Interface::real_type>::norm_diff(X_stl,resu_stl); + + if (error>1.e-6){ + INFOS("WRONG CALCULATION...residual=" << error); + exit(0); + } + + } + +private : + + typename Interface::stl_matrix A_stl; + typename Interface::stl_vector B_stl; + typename Interface::stl_vector X_stl; + typename Interface::stl_vector resu_stl; + + typename Interface::gene_matrix A_ref; + typename Interface::gene_vector B_ref; + typename Interface::gene_vector X_ref; + + typename Interface::gene_matrix A; + typename Interface::gene_vector B; + typename Interface::gene_vector X; + + + int _size; + +}; + + +#endif + + + diff --git a/bench/btl/cmake/FindBlitz.cmake b/bench/btl/cmake/FindBlitz.cmake new file mode 100644 index 000000000..99795f475 --- /dev/null +++ b/bench/btl/cmake/FindBlitz.cmake @@ -0,0 +1,40 @@ +# - Try to find blitz lib +# Once done this will define +# +# BLITZ_FOUND - system has blitz lib +# BLITZ_INCLUDES - the blitz include directory +# BLITZ_LIBRARIES - The libraries needed to use blitz + +# Copyright (c) 2006, Montel Laurent, <montel@kde.org> +# Copyright (c) 2007, Allen Winter, <winter@kde.org> +# Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +# include(FindLibraryWithDebug) + +if (BLITZ_INCLUDES AND BLITZ_LIBRARIES) + set(Blitz_FIND_QUIETLY TRUE) +endif (BLITZ_INCLUDES AND BLITZ_LIBRARIES) + +find_path(BLITZ_INCLUDES + NAMES + blitz/array.h + PATH_SUFFIXES blitz* + PATHS + $ENV{BLITZDIR}/include + ${INCLUDE_INSTALL_DIR} +) + +find_library(BLITZ_LIBRARIES + blitz + PATHS + $ENV{BLITZDIR}/lib + ${LIB_INSTALL_DIR} +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Blitz DEFAULT_MSG + BLITZ_INCLUDES BLITZ_LIBRARIES) + +mark_as_advanced(BLITZ_INCLUDES BLITZ_LIBRARIES) diff --git a/bench/btl/cmake/FindCBLAS.cmake b/bench/btl/cmake/FindCBLAS.cmake new file mode 100644 index 000000000..554f0291b --- /dev/null +++ b/bench/btl/cmake/FindCBLAS.cmake @@ -0,0 +1,34 @@ +# include(FindLibraryWithDebug) + +if (CBLAS_INCLUDES AND CBLAS_LIBRARIES) + set(CBLAS_FIND_QUIETLY TRUE) +endif (CBLAS_INCLUDES AND CBLAS_LIBRARIES) + +find_path(CBLAS_INCLUDES + NAMES + cblas.h + PATHS + $ENV{CBLASDIR}/include + ${INCLUDE_INSTALL_DIR} +) + +find_library(CBLAS_LIBRARIES + cblas + PATHS + $ENV{CBLASDIR}/lib + ${LIB_INSTALL_DIR} +) + +find_file(CBLAS_LIBRARIES + libcblas.so.3 + PATHS + /usr/lib + $ENV{CBLASDIR}/lib + ${LIB_INSTALL_DIR} +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CBLAS DEFAULT_MSG + CBLAS_INCLUDES CBLAS_LIBRARIES) + +mark_as_advanced(CBLAS_INCLUDES CBLAS_LIBRARIES) diff --git a/bench/btl/cmake/FindEigen.cmake b/bench/btl/cmake/FindEigen.cmake new file mode 100644 index 000000000..1a5fe34fd --- /dev/null +++ b/bench/btl/cmake/FindEigen.cmake @@ -0,0 +1,30 @@ +# - Try to find eigen lib +# Once done this will define +# +# EIGEN_FOUND - system has eigen lib +# EIGEN_INCLUDE_DIR - the eigen include directory + +# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org> +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +if (EIGEN_INCLUDE_DIR) + + # in cache already + set(EIGEN_FOUND TRUE) + +else (EIGEN_INCLUDE_DIR) + +find_path(EIGEN_INCLUDE_DIR NAMES eigen/matrix.h + PATHS + ${INCLUDE_INSTALL_DIR} + ) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Eigen DEFAULT_MSG EIGEN_INCLUDE_DIR ) + + +mark_as_advanced(EIGEN_INCLUDE_DIR) + +endif(EIGEN_INCLUDE_DIR) + diff --git a/bench/btl/cmake/FindEigen2.cmake b/bench/btl/cmake/FindEigen2.cmake new file mode 100644 index 000000000..a1b8a4645 --- /dev/null +++ b/bench/btl/cmake/FindEigen2.cmake @@ -0,0 +1,32 @@ +# - Try to find eigen2 headers +# Once done this will define +# +# EIGEN2_FOUND - system has eigen2 lib +# EIGEN2_INCLUDE_DIR - the eigen2 include directory +# +# Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +# Adapted from FindEigen.cmake: +# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org> +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +if (EIGEN2_INCLUDE_DIR) + + # in cache already + set(EIGEN2_FOUND TRUE) + +else (EIGEN2_INCLUDE_DIR) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Eigen2 DEFAULT_MSG EIGEN2_INCLUDE_DIR) + +find_path(EIGEN2_INCLUDE_DIR NAMES Eigen/Core + PATHS + ${Eigen_SOURCE_DIR}/ + ${INCLUDE_INSTALL_DIR} + ) + +mark_as_advanced(EIGEN2_INCLUDE_DIR) + +endif(EIGEN2_INCLUDE_DIR) + diff --git a/bench/btl/cmake/FindGMM.cmake b/bench/btl/cmake/FindGMM.cmake new file mode 100644 index 000000000..5049c64ed --- /dev/null +++ b/bench/btl/cmake/FindGMM.cmake @@ -0,0 +1,17 @@ +if (GMM_INCLUDE_DIR) + # in cache already + set(GMM_FOUND TRUE) +else (GMM_INCLUDE_DIR) + +find_path(GMM_INCLUDE_DIR NAMES gmm/gmm.h + PATHS + ${INCLUDE_INSTALL_DIR} + ${GMM_INCLUDE_PATH} + ) + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMM DEFAULT_MSG GMM_INCLUDE_DIR ) + +mark_as_advanced(GMM_INCLUDE_DIR) + +endif(GMM_INCLUDE_DIR) diff --git a/bench/btl/cmake/MacroOptionalAddSubdirectory.cmake b/bench/btl/cmake/MacroOptionalAddSubdirectory.cmake new file mode 100644 index 000000000..545048b68 --- /dev/null +++ b/bench/btl/cmake/MacroOptionalAddSubdirectory.cmake @@ -0,0 +1,31 @@ +# - MACRO_OPTIONAL_ADD_SUBDIRECTORY() combines ADD_SUBDIRECTORY() with an OPTION() +# MACRO_OPTIONAL_ADD_SUBDIRECTORY( <dir> ) +# If you use MACRO_OPTIONAL_ADD_SUBDIRECTORY() instead of ADD_SUBDIRECTORY(), +# this will have two effects +# 1 - CMake will not complain if the directory doesn't exist +# This makes sense if you want to distribute just one of the subdirs +# in a source package, e.g. just one of the subdirs in kdeextragear. +# 2 - If the directory exists, it will offer an option to skip the +# subdirectory. +# This is useful if you want to compile only a subset of all +# directories. + +# Copyright (c) 2007, Alexander Neundorf, <neundorf@kde.org> +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + +MACRO (MACRO_OPTIONAL_ADD_SUBDIRECTORY _dir ) + GET_FILENAME_COMPONENT(_fullPath ${_dir} ABSOLUTE) + IF(EXISTS ${_fullPath}) + IF(${ARGC} EQUAL 2) + OPTION(BUILD_${_dir} "Build directory ${_dir}" ${ARGV1}) + ELSE(${ARGC} EQUAL 2) + OPTION(BUILD_${_dir} "Build directory ${_dir}" TRUE) + ENDIF(${ARGC} EQUAL 2) + IF(BUILD_${_dir}) + ADD_SUBDIRECTORY(${_dir}) + ENDIF(BUILD_${_dir}) + ENDIF(EXISTS ${_fullPath}) +ENDMACRO (MACRO_OPTIONAL_ADD_SUBDIRECTORY) diff --git a/bench/btl/data/CMakeLists.txt b/bench/btl/data/CMakeLists.txt new file mode 100644 index 000000000..365652ca9 --- /dev/null +++ b/bench/btl/data/CMakeLists.txt @@ -0,0 +1,18 @@ + +ADD_CUSTOM_TARGET(copy_scripts) + +SET(script_files go_mean aat.hh ata.hh axpy.hh order_lib mk_mean_script.sh mk_new_gnuplot.sh mk_gnuplot_script.sh matrix_matrix.hh matrix_vector.hh) + +FOREACH(script_file ${script_files}) +ADD_CUSTOM_COMMAND( + TARGET copy_scripts + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${script_file} ${CMAKE_CURRENT_BINARY_DIR}/ + ARGS +) +ENDFOREACH(script_file) + +add_executable(smooth smooth.cxx) +add_executable(regularize regularize.cxx) +add_executable(main mean.cxx) +add_dependencies(main copy_scripts) diff --git a/bench/btl/data/aat.hh b/bench/btl/data/aat.hh new file mode 100644 index 000000000..d91f4e3bf --- /dev/null +++ b/bench/btl/data/aat.hh @@ -0,0 +1,108 @@ +#!/usr/bin/gnuplot -persist +# +# +# G N U P L O T +# Linux version 3.7 +# patchlevel 0 +# last modified Thu Jan 14 19:34:53 BST 1999 +# +# Copyright(C) 1986 - 1993, 1998, 1999 +# Thomas Williams, Colin Kelley and many others +# +# Type `help` to access the on-line reference manual +# The gnuplot FAQ is available from +# <http://www.uni-karlsruhe.de/~ig25/gnuplot-faq/> +# +# Send comments and requests for help to <info-gnuplot@dartmouth.edu> +# Send bugs, suggestions and mods to <bug-gnuplot@dartmouth.edu> +# +# set terminal postscript landscape noenhanced monochrome dashed defaultplex "Helvetica" 14 +# set output 'bench_gcc.ps' +set noclip points +set clip one +set noclip two +set bar 1.000000 +set border 31 lt -1 lw 1.000 +set xdata +set ydata +set zdata +set x2data +set y2data +set boxwidth +set dummy x,y +set format x "%g" +set format y "%g" +set format x2 "%g" +set format y2 "%g" +set format z "%g" +set angles radians +set nogrid +set key title "" +set key right top Right noreverse box linetype -2 linewidth 1.000 samplen 4 spacing 1 width 0 +set nolabel +set noarrow +set nolinestyle +set nologscale +set logscale x 10 +set offsets 0, 0, 0, 0 +set pointsize 1 +set encoding default +set nopolar +set noparametric +set view 60, 30, 1, 1 +set samples 100, 100 +set isosamples 10, 10 +set surface +set nocontour +set clabel '%8.3g' +set mapping cartesian +set nohidden3d +set cntrparam order 4 +set cntrparam linear +set cntrparam levels auto 5 +set cntrparam points 5 +set size ratio 0 1,1 +set origin 0,0 +set data style linespoints +set function style lines +set xzeroaxis lt -2 lw 1.000 +set x2zeroaxis lt -2 lw 1.000 +set yzeroaxis lt -2 lw 1.000 +set y2zeroaxis lt -2 lw 1.000 +set tics in +set ticslevel 0.5 +set ticscale 1 0.5 +set mxtics default +set mytics default +set mx2tics default +set my2tics default +set xtics border mirror norotate autofreq +set ytics border mirror norotate autofreq +set ztics border nomirror norotate autofreq +set nox2tics +set noy2tics +set title "A x At product " 0.000000,0.000000 "" +set timestamp "" bottom norotate 0.000000,0.000000 "" +set rrange [ * : * ] noreverse nowriteback # (currently [-0:10] ) +set trange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set urange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set vrange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set xlabel "matrix size" 0.000000,0.000000 "" +set x2label "" 0.000000,0.000000 "" +set timefmt "%d/%m/%y\n%H:%M" +set xrange [ 10 : 1000 ] noreverse nowriteback +set x2range [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set ylabel "MFLOPS" 0.000000,0.000000 "" +set y2label "" 0.000000,0.000000 "" +set yrange [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set y2range [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set zlabel "" 0.000000,0.000000 "" +set zrange [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set zero 1e-08 +set lmargin -1 +set bmargin -1 +set rmargin -1 +set tmargin -1 +set locale "C" +set xrange [10:1000] +##set yrange [0:400] diff --git a/bench/btl/data/ata.hh b/bench/btl/data/ata.hh new file mode 100644 index 000000000..d553f7000 --- /dev/null +++ b/bench/btl/data/ata.hh @@ -0,0 +1,108 @@ +#!/usr/bin/gnuplot -persist +# +# +# G N U P L O T +# Linux version 3.7 +# patchlevel 0 +# last modified Thu Jan 14 19:34:53 BST 1999 +# +# Copyright(C) 1986 - 1993, 1998, 1999 +# Thomas Williams, Colin Kelley and many others +# +# Type `help` to access the on-line reference manual +# The gnuplot FAQ is available from +# <http://www.uni-karlsruhe.de/~ig25/gnuplot-faq/> +# +# Send comments and requests for help to <info-gnuplot@dartmouth.edu> +# Send bugs, suggestions and mods to <bug-gnuplot@dartmouth.edu> +# +# set terminal postscript landscape noenhanced monochrome dashed defaultplex "Helvetica" 14 +# set output 'bench_gcc.ps' +set noclip points +set clip one +set noclip two +set bar 1.000000 +set border 31 lt -1 lw 1.000 +set xdata +set ydata +set zdata +set x2data +set y2data +set boxwidth +set dummy x,y +set format x "%g" +set format y "%g" +set format x2 "%g" +set format y2 "%g" +set format z "%g" +set angles radians +set nogrid +set key title "" +set key right top Right noreverse box linetype -2 linewidth 1.000 samplen 4 spacing 1 width 0 +set nolabel +set noarrow +set nolinestyle +set nologscale +set logscale x 10 +set offsets 0, 0, 0, 0 +set pointsize 1 +set encoding default +set nopolar +set noparametric +set view 60, 30, 1, 1 +set samples 100, 100 +set isosamples 10, 10 +set surface +set nocontour +set clabel '%8.3g' +set mapping cartesian +set nohidden3d +set cntrparam order 4 +set cntrparam linear +set cntrparam levels auto 5 +set cntrparam points 5 +set size ratio 0 1,1 +set origin 0,0 +set data style linespoints +set function style lines +set xzeroaxis lt -2 lw 1.000 +set x2zeroaxis lt -2 lw 1.000 +set yzeroaxis lt -2 lw 1.000 +set y2zeroaxis lt -2 lw 1.000 +set tics in +set ticslevel 0.5 +set ticscale 1 0.5 +set mxtics default +set mytics default +set mx2tics default +set my2tics default +set xtics border mirror norotate autofreq +set ytics border mirror norotate autofreq +set ztics border nomirror norotate autofreq +set nox2tics +set noy2tics +set title "At x A product " 0.000000,0.000000 "" +set timestamp "" bottom norotate 0.000000,0.000000 "" +set rrange [ * : * ] noreverse nowriteback # (currently [-0:10] ) +set trange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set urange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set vrange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set xlabel "matrix size" 0.000000,0.000000 "" +set x2label "" 0.000000,0.000000 "" +set timefmt "%d/%m/%y\n%H:%M" +set xrange [ 10 : 1000 ] noreverse nowriteback +set x2range [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set ylabel "MFLOPS" 0.000000,0.000000 "" +set y2label "" 0.000000,0.000000 "" +set yrange [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set y2range [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set zlabel "" 0.000000,0.000000 "" +set zrange [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set zero 1e-08 +set lmargin -1 +set bmargin -1 +set rmargin -1 +set tmargin -1 +set locale "C" +set xrange [10:1000] +##set yrange [0:400] diff --git a/bench/btl/data/axpy.hh b/bench/btl/data/axpy.hh new file mode 100644 index 000000000..9f53397e3 --- /dev/null +++ b/bench/btl/data/axpy.hh @@ -0,0 +1,108 @@ +#!/usr/bin/gnuplot -persist +# +# +# G N U P L O T +# Linux version 3.7 +# patchlevel 0 +# last modified Thu Jan 14 19:34:53 BST 1999 +# +# Copyright(C) 1986 - 1993, 1998, 1999 +# Thomas Williams, Colin Kelley and many others +# +# Type `help` to access the on-line reference manual +# The gnuplot FAQ is available from +# <http://www.uni-karlsruhe.de/~ig25/gnuplot-faq/> +# +# Send comments and requests for help to <info-gnuplot@dartmouth.edu> +# Send bugs, suggestions and mods to <bug-gnuplot@dartmouth.edu> +# +# set terminal postscript landscape noenhanced monochrome dashed defaultplex "Helvetica" 14 +# set output 'bench_gcc.ps' +set noclip points +set clip one +set noclip two +set bar 1.000000 +set border 31 lt -1 lw 1.000 +set xdata +set ydata +set zdata +set x2data +set y2data +set boxwidth +set dummy x,y +set format x "%g" +set format y "%g" +set format x2 "%g" +set format y2 "%g" +set format z "%g" +set angles radians +set nogrid +set key title "" +set key right top Right noreverse box linetype -2 linewidth 1.000 samplen 4 spacing 1 width 0 +set nolabel +set noarrow +set nolinestyle +set nologscale +set logscale x 10 +set offsets 0, 0, 0, 0 +set pointsize 1 +set encoding default +set nopolar +set noparametric +set view 60, 30, 1, 1 +set samples 100, 100 +set isosamples 10, 10 +set surface +set nocontour +set clabel '%8.3g' +set mapping cartesian +set nohidden3d +set cntrparam order 4 +set cntrparam linear +set cntrparam levels auto 5 +set cntrparam points 5 +set size ratio 0 1,1 +set origin 0,0 +set data style linespoints +set function style lines +set xzeroaxis lt -2 lw 1.000 +set x2zeroaxis lt -2 lw 1.000 +set yzeroaxis lt -2 lw 1.000 +set y2zeroaxis lt -2 lw 1.000 +set tics in +set ticslevel 0.5 +set ticscale 1 0.5 +set mxtics default +set mytics default +set mx2tics default +set my2tics default +set xtics border mirror norotate autofreq +set ytics border mirror norotate autofreq +set ztics border nomirror norotate autofreq +set nox2tics +set noy2tics +set title "Y+=alpha*X " 0.000000,0.000000 "" +set timestamp "" bottom norotate 0.000000,0.000000 "" +set rrange [ * : * ] noreverse nowriteback # (currently [-0:10] ) +set trange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set urange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set vrange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set xlabel "vector size" 0.000000,0.000000 "" +set x2label "" 0.000000,0.000000 "" +set timefmt "%d/%m/%y\n%H:%M" +set xrange [ 10 : 1000 ] noreverse nowriteback +set x2range [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set ylabel "MFLOPS" 0.000000,0.000000 "" +set y2label "" 0.000000,0.000000 "" +set yrange [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set y2range [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set zlabel "" 0.000000,0.000000 "" +set zrange [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set zero 1e-08 +set lmargin -1 +set bmargin -1 +set rmargin -1 +set tmargin -1 +set locale "C" +set xrange [1:1000000] +##set yrange [0:550] diff --git a/bench/btl/data/go_mean b/bench/btl/data/go_mean new file mode 100755 index 000000000..80203afc4 --- /dev/null +++ b/bench/btl/data/go_mean @@ -0,0 +1,9 @@ +mkdir $1 +##cp ../libs/*/*.dat $1 + +source mk_mean_script.sh axpy $1 11 2500 100000 250000 > $1/axpy.html +source mk_mean_script.sh matrix_vector $1 11 50 300 500 > $1/matrix_vector.html +source mk_mean_script.sh matrix_matrix $1 11 100 300 500 > $1/matrix_matrix.html +source mk_mean_script.sh aat $1 11 100 300 1000 > $1/aat.html +source mk_mean_script.sh ata $1 11 100 300 1000 > $1/ata.html + diff --git a/bench/btl/data/matrix_matrix.hh b/bench/btl/data/matrix_matrix.hh new file mode 100644 index 000000000..42e97d5c1 --- /dev/null +++ b/bench/btl/data/matrix_matrix.hh @@ -0,0 +1,108 @@ +#!/usr/bin/gnuplot -persist +# +# +# G N U P L O T +# Linux version 3.7 +# patchlevel 0 +# last modified Thu Jan 14 19:34:53 BST 1999 +# +# Copyright(C) 1986 - 1993, 1998, 1999 +# Thomas Williams, Colin Kelley and many others +# +# Type `help` to access the on-line reference manual +# The gnuplot FAQ is available from +# <http://www.uni-karlsruhe.de/~ig25/gnuplot-faq/> +# +# Send comments and requests for help to <info-gnuplot@dartmouth.edu> +# Send bugs, suggestions and mods to <bug-gnuplot@dartmouth.edu> +# +# set terminal postscript landscape noenhanced monochrome dashed defaultplex "Helvetica" 14 +# set output 'bench_gcc.ps' +set noclip points +set clip one +set noclip two +set bar 1.000000 +set border 31 lt -1 lw 1.000 +set xdata +set ydata +set zdata +set x2data +set y2data +set boxwidth +set dummy x,y +set format x "%g" +set format y "%g" +set format x2 "%g" +set format y2 "%g" +set format z "%g" +set angles radians +set nogrid +set key title "" +set key right top Right noreverse box linetype -2 linewidth 1.000 samplen 4 spacing 1 width 0 +set nolabel +set noarrow +set nolinestyle +set nologscale +set logscale x 10 +set offsets 0, 0, 0, 0 +set pointsize 1 +set encoding default +set nopolar +set noparametric +set view 60, 30, 1, 1 +set samples 100, 100 +set isosamples 10, 10 +set surface +set nocontour +set clabel '%8.3g' +set mapping cartesian +set nohidden3d +set cntrparam order 4 +set cntrparam linear +set cntrparam levels auto 5 +set cntrparam points 5 +set size ratio 0 1,1 +set origin 0,0 +set data style linespoints +set function style lines +set xzeroaxis lt -2 lw 1.000 +set x2zeroaxis lt -2 lw 1.000 +set yzeroaxis lt -2 lw 1.000 +set y2zeroaxis lt -2 lw 1.000 +set tics in +set ticslevel 0.5 +set ticscale 1 0.5 +set mxtics default +set mytics default +set mx2tics default +set my2tics default +set xtics border mirror norotate autofreq +set ytics border mirror norotate autofreq +set ztics border nomirror norotate autofreq +set nox2tics +set noy2tics +set title "matrix matrix product " 0.000000,0.000000 "" +set timestamp "" bottom norotate 0.000000,0.000000 "" +set rrange [ * : * ] noreverse nowriteback # (currently [-0:10] ) +set trange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set urange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set vrange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set xlabel "matrix size" 0.000000,0.000000 "" +set x2label "" 0.000000,0.000000 "" +set timefmt "%d/%m/%y\n%H:%M" +set xrange [ 10 : 1000 ] noreverse nowriteback +set x2range [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set ylabel "MFLOPS" 0.000000,0.000000 "" +set y2label "" 0.000000,0.000000 "" +set yrange [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set y2range [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set zlabel "" 0.000000,0.000000 "" +set zrange [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set zero 1e-08 +set lmargin -1 +set bmargin -1 +set rmargin -1 +set tmargin -1 +set locale "C" +set xrange [1:1000] +##set yrange [0:400] diff --git a/bench/btl/data/matrix_vector.hh b/bench/btl/data/matrix_vector.hh new file mode 100644 index 000000000..00e8c7c33 --- /dev/null +++ b/bench/btl/data/matrix_vector.hh @@ -0,0 +1,108 @@ +#!/usr/bin/gnuplot -persist +# +# +# G N U P L O T +# Linux version 3.7 +# patchlevel 0 +# last modified Thu Jan 14 19:34:53 BST 1999 +# +# Copyright(C) 1986 - 1993, 1998, 1999 +# Thomas Williams, Colin Kelley and many others +# +# Type `help` to access the on-line reference manual +# The gnuplot FAQ is available from +# <http://www.uni-karlsruhe.de/~ig25/gnuplot-faq/> +# +# Send comments and requests for help to <info-gnuplot@dartmouth.edu> +# Send bugs, suggestions and mods to <bug-gnuplot@dartmouth.edu> +# +# set terminal postscript landscape noenhanced monochrome dashed defaultplex "Helvetica" 14 +# set output 'bench_gcc.ps' +set noclip points +set clip one +set noclip two +set bar 1.000000 +set border 31 lt -1 lw 1.000 +set xdata +set ydata +set zdata +set x2data +set y2data +set boxwidth +set dummy x,y +set format x "%g" +set format y "%g" +set format x2 "%g" +set format y2 "%g" +set format z "%g" +set angles radians +set nogrid +set key title "" +set key right top Right noreverse box linetype -2 linewidth 1.000 samplen 4 spacing 1 width 0 +set nolabel +set noarrow +set nolinestyle +set nologscale +set logscale x 10 +set offsets 0, 0, 0, 0 +set pointsize 1 +set encoding default +set nopolar +set noparametric +set view 60, 30, 1, 1 +set samples 100, 100 +set isosamples 10, 10 +set surface +set nocontour +set clabel '%8.3g' +set mapping cartesian +set nohidden3d +set cntrparam order 4 +set cntrparam linear +set cntrparam levels auto 5 +set cntrparam points 5 +set size ratio 0 1,1 +set origin 0,0 +set data style linespoints +set function style lines +set xzeroaxis lt -2 lw 1.000 +set x2zeroaxis lt -2 lw 1.000 +set yzeroaxis lt -2 lw 1.000 +set y2zeroaxis lt -2 lw 1.000 +set tics in +set ticslevel 0.5 +set ticscale 1 0.5 +set mxtics default +set mytics default +set mx2tics default +set my2tics default +set xtics border mirror norotate autofreq +set ytics border mirror norotate autofreq +set ztics border nomirror norotate autofreq +set nox2tics +set noy2tics +set title "matrix vector product " 0.000000,0.000000 "" +set timestamp "" bottom norotate 0.000000,0.000000 "" +set rrange [ * : * ] noreverse nowriteback # (currently [-0:10] ) +set trange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set urange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set vrange [ * : * ] noreverse nowriteback # (currently [-5:5] ) +set xlabel "matrix size" 0.000000,0.000000 "" +set x2label "" 0.000000,0.000000 "" +set timefmt "%d/%m/%y\n%H:%M" +set xrange [ 10 : 1000 ] noreverse nowriteback +set x2range [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set ylabel "MFLOPS" 0.000000,0.000000 "" +set y2label "" 0.000000,0.000000 "" +set yrange [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set y2range [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set zlabel "" 0.000000,0.000000 "" +set zrange [ * : * ] noreverse nowriteback # (currently [-10:10] ) +set zero 1e-08 +set lmargin -1 +set bmargin -1 +set rmargin -1 +set tmargin -1 +set locale "C" +set xrange [1:1000] +##set yrange [0:400] diff --git a/bench/btl/data/mean.cxx b/bench/btl/data/mean.cxx new file mode 100644 index 000000000..96d37dc4a --- /dev/null +++ b/bench/btl/data/mean.cxx @@ -0,0 +1,207 @@ +//===================================================== +// File : mean.cxx +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:15 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include <vector> +#include <string> +#include <iostream> +#include <fstream> +#include "bench_parameter.hh" +#include <set> + +using namespace std; + +void read_xy_file(const string & filename, vector<int> & tab_sizes, vector<double> & tab_mflops); +double mean_calc(const vector<int> & tab_sizes, const vector<double> & tab_mflops, const int size_min, const int size_max); + +class Lib_Mean{ + +public: + Lib_Mean( void ):_lib_name(),_mean_in_cache(),_mean_out_of_cache(){ + MESSAGE("Lib_mean Default Ctor"); + MESSAGE("!!! should not be used"); + exit(0); + } + Lib_Mean(const string & name, const double & mic, const double & moc):_lib_name(name),_mean_in_cache(mic),_mean_out_of_cache(moc){ + MESSAGE("Lib_mean Ctor"); + } + Lib_Mean(const Lib_Mean & lm):_lib_name(lm._lib_name),_mean_in_cache(lm._mean_in_cache),_mean_out_of_cache(lm._mean_out_of_cache){ + MESSAGE("Lib_mean Copy Ctor"); + } + ~Lib_Mean( void ){ + MESSAGE("Lib_mean Dtor"); + } + + double _mean_in_cache; + double _mean_out_of_cache; + string _lib_name; + + bool operator < ( const Lib_Mean &right) const + { + //return ( this->_mean_out_of_cache > right._mean_out_of_cache) ; + return ( this->_mean_in_cache > right._mean_in_cache) ; + } + +}; + + +int main( int argc , char *argv[] ) +{ + + if (argc<6){ + INFOS("!!! Error ... usage : main what mic Mic moc Moc filename1 finename2..."); + exit(0); + } + INFOS(argc); + + int min_in_cache=atoi(argv[2]); + int max_in_cache=atoi(argv[3]); + int min_out_of_cache=atoi(argv[4]); + int max_out_of_cache=atoi(argv[5]); + + + multiset<Lib_Mean> s_lib_mean ; + + for (int i=6;i<argc;i++){ + + string filename=argv[i]; + + INFOS(filename); + + double mic=0; + double moc=0; + + { + + vector<int> tab_sizes; + vector<double> tab_mflops; + + read_xy_file(filename,tab_sizes,tab_mflops); + + mic=mean_calc(tab_sizes,tab_mflops,min_in_cache,max_in_cache); + moc=mean_calc(tab_sizes,tab_mflops,min_out_of_cache,max_out_of_cache); + + Lib_Mean cur_lib_mean(filename,mic,moc); + + s_lib_mean.insert(cur_lib_mean); + + } + + } + + + cout << "<TABLE BORDER CELLPADDING=2>" << endl ; + cout << " <TR>" << endl ; + cout << " <TH ALIGN=CENTER> " << argv[1] << " </TH>" << endl ; + cout << " <TH ALIGN=CENTER> <a href=""#mean_marker""> in cache <BR> mean perf <BR> Mflops </a></TH>" << endl ; + cout << " <TH ALIGN=CENTER> in cache <BR> % best </TH>" << endl ; + cout << " <TH ALIGN=CENTER> <a href=""#mean_marker""> out of cache <BR> mean perf <BR> Mflops </a></TH>" << endl ; + cout << " <TH ALIGN=CENTER> out of cache <BR> % best </TH>" << endl ; + cout << " <TH ALIGN=CENTER> details </TH>" << endl ; + cout << " <TH ALIGN=CENTER> comments </TH>" << endl ; + cout << " </TR>" << endl ; + + set<Lib_Mean>::iterator is ; + + is=s_lib_mean.begin(); + Lib_Mean best(*is); + + + for (is=s_lib_mean.begin(); is!=s_lib_mean.end() ; is++){ + + cout << " <TR>" << endl ; + cout << " <TD> " << is->_lib_name << " </TD>" << endl ; + cout << " <TD> " << is->_mean_in_cache << " </TD>" << endl ; + cout << " <TD> " << 100*(is->_mean_in_cache/best._mean_in_cache) << " </TD>" << endl ; + cout << " <TD> " << is->_mean_out_of_cache << " </TD>" << endl ; + cout << " <TD> " << 100*(is->_mean_out_of_cache/best._mean_out_of_cache) << " </TD>" << endl ; + cout << " <TD> " << + "<a href=\"#"<<is->_lib_name<<"_"<<argv[1]<<"\">snippet</a>/" + "<a href=\"#"<<is->_lib_name<<"_flags\">flags</a> </TD>" << endl ; + cout << " <TD> " << + "<a href=\"#"<<is->_lib_name<<"_comments\">click here</a> </TD>" << endl ; + cout << " </TR>" << endl ; + + } + + cout << "</TABLE>" << endl ; + + ofstream output_file ("../order_lib",ios::out) ; + + for (is=s_lib_mean.begin(); is!=s_lib_mean.end() ; is++){ + output_file << is->_lib_name << endl ; + } + + output_file.close(); + +} + +void read_xy_file(const string & filename, vector<int> & tab_sizes, vector<double> & tab_mflops){ + + ifstream input_file (filename.c_str(),ios::in) ; + + if (!input_file){ + INFOS("!!! Error opening "<<filename); + exit(0); + } + + int nb_point=0; + int size=0; + double mflops=0; + + while (input_file >> size >> mflops ){ + nb_point++; + tab_sizes.push_back(size); + tab_mflops.push_back(mflops); + } + SCRUTE(nb_point); + + input_file.close(); +} + +double mean_calc(const vector<int> & tab_sizes, const vector<double> & tab_mflops, const int size_min, const int size_max){ + + int size=tab_sizes.size(); + int nb_sample=0; + double mean=0.0; + + for (int i=0;i<size;i++){ + + + if ((tab_sizes[i]>=size_min)&&(tab_sizes[i]<=size_max)){ + + nb_sample++; + mean+=tab_mflops[i]; + + } + + + } + + if (nb_sample==0){ + INFOS("no data for mean calculation"); + return 0.0; + } + + return mean/nb_sample; +} + + + + diff --git a/bench/btl/data/mk_gnuplot_script.sh b/bench/btl/data/mk_gnuplot_script.sh new file mode 100644 index 000000000..2ca7b5cb5 --- /dev/null +++ b/bench/btl/data/mk_gnuplot_script.sh @@ -0,0 +1,68 @@ +#! /bin/bash +WHAT=$1 +DIR=$2 +echo $WHAT script generation +cat $WHAT.hh > $WHAT.gnuplot + +DATA_FILE=`find $DIR -name "*.dat" | grep $WHAT` + +echo plot \\ >> $WHAT.gnuplot + +for FILE in $DATA_FILE +do + LAST=$FILE +done + +echo LAST=$LAST + +for FILE in $DATA_FILE +do + if [ $FILE != $LAST ] + then + BASE=${FILE##*/} ; BASE=${FILE##*/} ; AVANT=bench_${WHAT}_ ; REDUC=${BASE##*$AVANT} ; TITLE=${REDUC%.dat} + echo "'"$FILE"'" title "'"$TITLE"'" ",\\" >> $WHAT.gnuplot + fi +done +BASE=${LAST##*/} ; BASE=${FILE##*/} ; AVANT=bench_${WHAT}_ ; REDUC=${BASE##*$AVANT} ; TITLE=${REDUC%.dat} +echo "'"$LAST"'" title "'"$TITLE"'" >> $WHAT.gnuplot + +#echo set term postscript color >> $WHAT.gnuplot +#echo set output "'"$WHAT.ps"'" >> $WHAT.gnuplot +echo set term pbm small color >> $WHAT.gnuplot +echo set output "'"$WHAT.ppm"'" >> $WHAT.gnuplot +echo plot \\ >> $WHAT.gnuplot + +for FILE in $DATA_FILE +do + if [ $FILE != $LAST ] + then + BASE=${FILE##*/} ; BASE=${FILE##*/} ; AVANT=bench_${WHAT}_ ; REDUC=${BASE##*$AVANT} ; TITLE=${REDUC%.dat} + echo "'"$FILE"'" title "'"$TITLE"'" ",\\" >> $WHAT.gnuplot + fi +done +BASE=${LAST##*/} ; BASE=${FILE##*/} ; AVANT=bench_${WHAT}_ ; REDUC=${BASE##*$AVANT} ; TITLE=${REDUC%.dat} +echo "'"$LAST"'" title "'"$TITLE"'" >> $WHAT.gnuplot + +echo set term jpeg large >> $WHAT.gnuplot +echo set output "'"$WHAT.jpg"'" >> $WHAT.gnuplot +echo plot \\ >> $WHAT.gnuplot + +for FILE in $DATA_FILE +do + if [ $FILE != $LAST ] + then + BASE=${FILE##*/} ; BASE=${FILE##*/} ; AVANT=bench_${WHAT}_ ; REDUC=${BASE##*$AVANT} ; TITLE=${REDUC%.dat} + echo "'"$FILE"'" title "'"$TITLE"'" ",\\" >> $WHAT.gnuplot + fi +done +BASE=${LAST##*/} ; BASE=${FILE##*/} ; AVANT=bench_${WHAT}_ ; REDUC=${BASE##*$AVANT} ; TITLE=${REDUC%.dat} +echo "'"$LAST"'" title "'"$TITLE"'" >> $WHAT.gnuplot + + +gnuplot -persist < $WHAT.gnuplot + +rm $WHAT.gnuplot + + + + diff --git a/bench/btl/data/mk_mean_script.sh b/bench/btl/data/mk_mean_script.sh new file mode 100644 index 000000000..bc6821cf1 --- /dev/null +++ b/bench/btl/data/mk_mean_script.sh @@ -0,0 +1,39 @@ +#! /bin/bash +WHAT=$1 +DIR=$2 +MINIC=$3 +MAXIC=$4 +MINOC=$5 +MAXOC=$6 + +WORK_DIR=tmp +mkdir $WORK_DIR + +DATA_FILE=`find $DIR -name "*.dat" | grep _${WHAT}` +echo +for FILE in $DATA_FILE +do + ##echo hello world + ##echo "mk_mean_script1" ${FILE} + BASE=${FILE##*/} ; BASE=${FILE##*/} ; AVANT=bench_${WHAT}_ ; REDUC=${BASE##*$AVANT} ; TITLE=${REDUC%.dat} + + ##echo "mk_mean_script1" ${TITLE} + cp $FILE ${WORK_DIR}/${TITLE} + +done + +cd $WORK_DIR +../main $1 $3 $4 $5 $6 * +../mk_new_gnuplot.sh $1 $2 +rm -f *.gnuplot +cd .. + +rm -R $WORK_DIR + + + + + + + + diff --git a/bench/btl/data/mk_new_gnuplot.sh b/bench/btl/data/mk_new_gnuplot.sh new file mode 100755 index 000000000..ba86b2884 --- /dev/null +++ b/bench/btl/data/mk_new_gnuplot.sh @@ -0,0 +1,45 @@ +#! /bin/bash +WHAT=$1 +DIR=$2 +cat ../${WHAT}.hh > ${WHAT}.gnuplot + +DATA_FILE=`cat ../order_lib` + +echo plot \\ >> $WHAT.gnuplot + +for FILE in $DATA_FILE +do + LAST=$FILE +done + + +for FILE in $DATA_FILE +do + if [ $FILE != $LAST ] + then + echo "'"$FILE"'" ",\\" >> $WHAT.gnuplot + fi +done +echo "'"$LAST"'" >> $WHAT.gnuplot + +echo set term postscript color >> $WHAT.gnuplot +echo set output "'"../${DIR}/$WHAT.ps"'" >> $WHAT.gnuplot +#echo set term pbm color >> $WHAT.gnuplot +#echo set output "'"../${DIR}/$WHAT.ppm"'" >> $WHAT.gnuplot +echo plot \\ >> $WHAT.gnuplot +for FILE in $DATA_FILE +do + if [ $FILE != $LAST ] + then + echo "'"$FILE"'" ",\\" >> $WHAT.gnuplot + fi +done +echo "'"$LAST"'" >> $WHAT.gnuplot + +gnuplot -persist < $WHAT.gnuplot + +rm $WHAT.gnuplot + + + + diff --git a/bench/btl/data/order_lib b/bench/btl/data/order_lib new file mode 100644 index 000000000..5ea998a2e --- /dev/null +++ b/bench/btl/data/order_lib @@ -0,0 +1,8 @@ +eigen2 +C_BLAS +STL +C +gmm +ublas +blitz +F77 diff --git a/bench/btl/data/regularize.cxx b/bench/btl/data/regularize.cxx new file mode 100644 index 000000000..eea2b8b85 --- /dev/null +++ b/bench/btl/data/regularize.cxx @@ -0,0 +1,131 @@ +//===================================================== +// File : regularize.cxx +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:15 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include <vector> +#include <string> +#include <iostream> +#include <fstream> +#include "bench_parameter.hh" +#include <set> + +using namespace std; + +void read_xy_file(const string & filename, vector<int> & tab_sizes, vector<double> & tab_mflops); +void regularize_curve(const string & filename, + const vector<double> & tab_mflops, + const vector<int> & tab_sizes, + int start_cut_size, int stop_cut_size); +///////////////////////////////////////////////////////////////////////////////////////////////// + +int main( int argc , char *argv[] ) +{ + + // input data + + if (argc<4){ + INFOS("!!! Error ... usage : main filename start_cut_size stop_cut_size regularize_filename"); + exit(0); + } + INFOS(argc); + + int start_cut_size=atoi(argv[2]); + int stop_cut_size=atoi(argv[3]); + + string filename=argv[1]; + string regularize_filename=argv[4]; + + INFOS(filename); + INFOS("start_cut_size="<<start_cut_size); + + vector<int> tab_sizes; + vector<double> tab_mflops; + + read_xy_file(filename,tab_sizes,tab_mflops); + + // regularizeing + + regularize_curve(regularize_filename,tab_mflops,tab_sizes,start_cut_size,stop_cut_size); + + +} + +////////////////////////////////////////////////////////////////////////////////////// + +void regularize_curve(const string & filename, + const vector<double> & tab_mflops, + const vector<int> & tab_sizes, + int start_cut_size, int stop_cut_size) +{ + int size=tab_mflops.size(); + ofstream output_file (filename.c_str(),ios::out) ; + + int i=0; + + while(tab_sizes[i]<start_cut_size){ + + output_file << tab_sizes[i] << " " << tab_mflops[i] << endl ; + i++; + + } + + output_file << endl ; + + while(tab_sizes[i]<stop_cut_size){ + + i++; + + } + + while(i<size){ + + output_file << tab_sizes[i] << " " << tab_mflops[i] << endl ; + i++; + + } + + output_file.close(); + +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void read_xy_file(const string & filename, vector<int> & tab_sizes, vector<double> & tab_mflops){ + + ifstream input_file (filename.c_str(),ios::in) ; + + if (!input_file){ + INFOS("!!! Error opening "<<filename); + exit(0); + } + + int nb_point=0; + int size=0; + double mflops=0; + + while (input_file >> size >> mflops ){ + nb_point++; + tab_sizes.push_back(size); + tab_mflops.push_back(mflops); + } + SCRUTE(nb_point); + + input_file.close(); +} + diff --git a/bench/btl/data/smooth.cxx b/bench/btl/data/smooth.cxx new file mode 100644 index 000000000..e5270cc32 --- /dev/null +++ b/bench/btl/data/smooth.cxx @@ -0,0 +1,198 @@ +//===================================================== +// File : smooth.cxx +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:15 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include <vector> +#include <deque> +#include <string> +#include <iostream> +#include <fstream> +#include "bench_parameter.hh" +#include <set> + +using namespace std; + +void read_xy_file(const string & filename, vector<int> & tab_sizes, vector<double> & tab_mflops); +void write_xy_file(const string & filename, vector<int> & tab_sizes, vector<double> & tab_mflops); +void smooth_curve(const vector<double> & tab_mflops, vector<double> & smooth_tab_mflops,int window_half_width); +void centered_smooth_curve(const vector<double> & tab_mflops, vector<double> & smooth_tab_mflops,int window_half_width); + +///////////////////////////////////////////////////////////////////////////////////////////////// + +int main( int argc , char *argv[] ) +{ + + // input data + + if (argc<3){ + INFOS("!!! Error ... usage : main filename window_half_width smooth_filename"); + exit(0); + } + INFOS(argc); + + int window_half_width=atoi(argv[2]); + + string filename=argv[1]; + string smooth_filename=argv[3]; + + INFOS(filename); + INFOS("window_half_width="<<window_half_width); + + vector<int> tab_sizes; + vector<double> tab_mflops; + + read_xy_file(filename,tab_sizes,tab_mflops); + + // smoothing + + vector<double> smooth_tab_mflops; + + //smooth_curve(tab_mflops,smooth_tab_mflops,window_half_width); + centered_smooth_curve(tab_mflops,smooth_tab_mflops,window_half_width); + + // output result + + write_xy_file(smooth_filename,tab_sizes,smooth_tab_mflops); + + +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +template<class VECTOR> +double weighted_mean(const VECTOR & data) +{ + + double mean=0.0; + + for (int i=0 ; i<data.size() ; i++){ + + mean+=data[i]; + + } + + return mean/double(data.size()) ; + +} + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +void smooth_curve(const vector<double> & tab_mflops, vector<double> & smooth_tab_mflops,int window_half_width){ + + int window_width=2*window_half_width+1; + + int size=tab_mflops.size(); + + vector<double> sample(window_width); + + for (int i=0 ; i < size ; i++){ + + for ( int j=0 ; j < window_width ; j++ ){ + + int shifted_index=i+j-window_half_width; + if (shifted_index<0) shifted_index=0; + if (shifted_index>size-1) shifted_index=size-1; + sample[j]=tab_mflops[shifted_index]; + + } + + smooth_tab_mflops.push_back(weighted_mean(sample)); + + } + +} + +void centered_smooth_curve(const vector<double> & tab_mflops, vector<double> & smooth_tab_mflops,int window_half_width){ + + int max_window_width=2*window_half_width+1; + + int size=tab_mflops.size(); + + + for (int i=0 ; i < size ; i++){ + + deque<double> sample; + + + sample.push_back(tab_mflops[i]); + + for ( int j=1 ; j <= window_half_width ; j++ ){ + + int before=i-j; + int after=i+j; + + if ((before>=0)&&(after<size)) // inside of the vector + { + sample.push_front(tab_mflops[before]); + sample.push_back(tab_mflops[after]); + } + } + + smooth_tab_mflops.push_back(weighted_mean(sample)); + + } + +} + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void write_xy_file(const string & filename, vector<int> & tab_sizes, vector<double> & tab_mflops){ + + ofstream output_file (filename.c_str(),ios::out) ; + + for (int i=0 ; i < tab_sizes.size() ; i++) + { + output_file << tab_sizes[i] << " " << tab_mflops[i] << endl ; + } + + output_file.close(); + +} + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void read_xy_file(const string & filename, vector<int> & tab_sizes, vector<double> & tab_mflops){ + + ifstream input_file (filename.c_str(),ios::in) ; + + if (!input_file){ + INFOS("!!! Error opening "<<filename); + exit(0); + } + + int nb_point=0; + int size=0; + double mflops=0; + + while (input_file >> size >> mflops ){ + nb_point++; + tab_sizes.push_back(size); + tab_mflops.push_back(mflops); + } + SCRUTE(nb_point); + + input_file.close(); +} + diff --git a/bench/btl/data/smooth_all.sh b/bench/btl/data/smooth_all.sh new file mode 100755 index 000000000..3e5bfdf47 --- /dev/null +++ b/bench/btl/data/smooth_all.sh @@ -0,0 +1,68 @@ +#! /bin/bash +ORIG_DIR=$1 +SMOOTH_DIR=${ORIG_DIR}_smooth +mkdir ${SMOOTH_DIR} + +AXPY_FILE=`find ${ORIG_DIR} -name "*.dat" | grep axpy` +for FILE in ${AXPY_FILE} +do + echo $FILE + BASE=${FILE##*/} + ./smooth ${ORIG_DIR}/${BASE} 4 ${SMOOTH_DIR}/${BASE}_tmp + ./regularize ${SMOOTH_DIR}/${BASE}_tmp 2500 15000 ${SMOOTH_DIR}/${BASE} + rm -f ${SMOOTH_DIR}/${BASE}_tmp +done + + +MATRIX_VECTOR_FILE=`find ${ORIG_DIR} -name "*.dat" | grep matrix_vector` +for FILE in ${MATRIX_VECTOR_FILE} +do + echo $FILE + BASE=${FILE##*/} + ./smooth ${ORIG_DIR}/${BASE} 4 ${SMOOTH_DIR}/${BASE}_tmp + ./regularize ${SMOOTH_DIR}/${BASE}_tmp 50 180 ${SMOOTH_DIR}/${BASE} + rm -f ${SMOOTH_DIR}/${BASE}_tmp +done + +MATRIX_MATRIX_FILE=`find ${ORIG_DIR} -name "*.dat" | grep matrix_matrix` +for FILE in ${MATRIX_MATRIX_FILE} +do + echo $FILE + BASE=${FILE##*/} + ./smooth ${ORIG_DIR}/${BASE} 4 ${SMOOTH_DIR}/${BASE} +done + +AAT_FILE=`find ${ORIG_DIR} -name "*.dat" | grep _aat` +for FILE in ${AAT_FILE} +do + echo $FILE + BASE=${FILE##*/} + ./smooth ${ORIG_DIR}/${BASE} 4 ${SMOOTH_DIR}/${BASE} +done + + +ATA_FILE=`find ${ORIG_DIR} -name "*.dat" | grep _ata` +for FILE in ${ATA_FILE} +do + echo $FILE + BASE=${FILE##*/} + ./smooth ${ORIG_DIR}/${BASE} 4 ${SMOOTH_DIR}/${BASE} +done + +### no smoothing for tinyvector and matrices libs + +TINY_BLITZ_FILE=`find ${ORIG_DIR} -name "*.dat" | grep tiny_blitz` +for FILE in ${TINY_BLITZ_FILE} +do + echo $FILE + BASE=${FILE##*/} + cp ${ORIG_DIR}/${BASE} ${SMOOTH_DIR}/${BASE} +done + +TVMET_FILE=`find ${ORIG_DIR} -name "*.dat" | grep tvmet` +for FILE in ${TVMET_FILE} +do + echo $FILE + BASE=${FILE##*/} + cp ${ORIG_DIR}/${BASE} ${SMOOTH_DIR}/${BASE} +done diff --git a/bench/btl/generic_bench/bench.hh b/bench/btl/generic_bench/bench.hh new file mode 100644 index 000000000..f46965c2f --- /dev/null +++ b/bench/btl/generic_bench/bench.hh @@ -0,0 +1,90 @@ +//===================================================== +// File : bench.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:16 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef BENCH_HH +#define BENCH_HH +#include "bench_parameter.hh" +#include <iostream> +#include "utilities.h" +#include "size_lin_log.hh" +#include "dump_file_x_y.hh" +#include <vector> +#include <string> +#include "timers/portable_perf_analyzer.hh" +//#include "timers/mixed_perf_analyzer.hh" +//#include "timers/x86_perf_analyzer.hh" +//#include "timers/STL_perf_analyzer.hh" + +using namespace std; + +template <template<class> class Perf_Analyzer, class Action> +void bench( int size_min, int size_max, int nb_point ){ + + // bench name + + string filename="bench_"+Action::name()+".dat"; + + INFOS("starting " <<filename); + + // utilities + + std::vector<double> tab_mflops(nb_point); + std::vector<int> tab_sizes(nb_point); + + // matrices and vector size calculations + + size_lin_log(nb_point,size_min,size_max,tab_sizes); + + // loop on matrix size + + Perf_Analyzer<Action> perf_action; + + for (int i=nb_point-1;i>=0;i--) + { + //INFOS("size=" <<tab_sizes[i]<<" ("<<nb_point-i<<"/"<<nb_point<<")"); + std::cout << " " << "size = " << tab_sizes[i] << " " << std::flush; + tab_mflops[i] = perf_action.eval_mflops(tab_sizes[i]); + std::cout << tab_mflops[i] << " MFlops (" << nb_point-i << "/" << nb_point << ")" << std::endl; + } +// std::cout << "\n"; + + // dump the result in a file : + + dump_file_x_y(tab_sizes,tab_mflops,filename); + +} + +// default Perf Analyzer + +template <class Action> +void bench( int size_min, int size_max, int nb_point ){ + + // if the rdtsc is not available : + bench<Portable_Perf_Analyzer,Action>(size_min,size_max,nb_point); + // if the rdtsc is available : +// bench<Mixed_Perf_Analyzer,Action>(size_min,size_max,nb_point); + + + // Only for small problem size. Otherwize it will be too long + //bench<X86_Perf_Analyzer,Action>(size_min,size_max,nb_point); + //bench<STL_Perf_Analyzer,Action>(size_min,size_max,nb_point); + +} + +#endif diff --git a/bench/btl/generic_bench/bench_parameter.hh b/bench/btl/generic_bench/bench_parameter.hh new file mode 100644 index 000000000..e2db997fd --- /dev/null +++ b/bench/btl/generic_bench/bench_parameter.hh @@ -0,0 +1,53 @@ +//===================================================== +// File : bench_parameter.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:16 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef BENCH_PARAMETER_HH +#define BENCH_PARAMETER_HH + +// minimal time for each measurement +#define REAL_TYPE float +// minimal time for each measurement +#define MIN_TIME 1.0 +// nb of point on bench curves +#define NB_POINT 100 +// min vector size for axpy bench +#define MIN_AXPY 2 +// max vector size for axpy bench +#define MAX_AXPY 1000000 +// min matrix size for matrix vector product bench +#define MIN_MV 2 +// max matrix size for matrix vector product bench +#define MAX_MV 1024 +// min matrix size for matrix matrix product bench +#define MIN_MM 2 +// max matrix size for matrix matrix product bench +#define MAX_MM 1024 +// min matrix size for LU bench +#define MIN_LU 10 +// max matrix size for LU bench +#define MAX_LU 1000 +// max size for tiny vector and matrix +#define TINY_MV_MAX_SIZE 16 +// default nb_sample for x86 timer +#define DEFAULT_NB_SAMPLE 1000 + +// how many times we run a single bench (keep the best perf) +#define NB_TRIES 3 + +#endif diff --git a/bench/btl/generic_bench/init/init_function.hh b/bench/btl/generic_bench/init/init_function.hh new file mode 100644 index 000000000..c7b348957 --- /dev/null +++ b/bench/btl/generic_bench/init/init_function.hh @@ -0,0 +1,55 @@ +//===================================================== +// File : init_function.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:18 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef INIT_FUNCTION_HH +#define INIT_FUNCTION_HH + +double simple_function(int index) +{ + return index; +} + +double simple_function(int index_i, int index_j) +{ + return index_i+index_j; +} + +double pseudo_random(int index) +{ + // INFOS("random="<<(std::rand()/double(RAND_MAX))); + return std::rand()/double(RAND_MAX); +} + +double pseudo_random(int index_i, int index_j) +{ + return std::rand()/double(RAND_MAX); +} + + +double null_function(int index) +{ + return 0.0; +} + +double null_function(int index_i, int index_j) +{ + return 0.0; +} + +#endif diff --git a/bench/btl/generic_bench/init/init_matrix.hh b/bench/btl/generic_bench/init/init_matrix.hh new file mode 100644 index 000000000..27f8b42aa --- /dev/null +++ b/bench/btl/generic_bench/init/init_matrix.hh @@ -0,0 +1,53 @@ +//===================================================== +// File : init_matrix.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef INIT_MATRIX_HH +#define INIT_MATRIX_HH + +// The Vector class must satisfy the following part of STL vector concept : +// resize() method +// [] operator for setting element +// value_type defined +template<double init_function(int,int), class Vector> +void init_row(Vector & X, int size, int row){ + + X.resize(size); + + for (int j=0;j<X.size();j++){ + X[j]=typename Vector::value_type(init_function(row,j)); + } +} + + +// Matrix is a Vector of Vector +// The Matrix class must satisfy the following part of STL vector concept : +// resize() method +// [] operator for setting rows +template<double init_function(int,int),class Vector> +void init_matrix(Vector & A, int size){ + + A.resize(size); + for (int row=0; row<A.size() ; row++){ + init_row<init_function>(A[row],size,row); + } + + +} + +#endif diff --git a/bench/btl/generic_bench/init/init_vector.hh b/bench/btl/generic_bench/init/init_vector.hh new file mode 100644 index 000000000..faf14f953 --- /dev/null +++ b/bench/btl/generic_bench/init/init_vector.hh @@ -0,0 +1,37 @@ +//===================================================== +// File : init_vector.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:18 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef INIT_VECTOR_HH +#define INIT_VECTOR_HH + +// The Vector class must satisfy the following part of STL vector concept : +// resize() method +// [] operator for setting element +// value_type defined +template<double init_function(int), class Vector> +void init_vector(Vector & X, int size){ + + X.resize(size); + + for (int i=0;i<X.size();i++){ + X[i]=typename Vector::value_type(init_function(i)); + } +} + +#endif diff --git a/bench/btl/generic_bench/static/bench_static.hh b/bench/btl/generic_bench/static/bench_static.hh new file mode 100644 index 000000000..5ae23c1b8 --- /dev/null +++ b/bench/btl/generic_bench/static/bench_static.hh @@ -0,0 +1,75 @@ +//===================================================== +// File : bench_static.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:16 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef BENCH_STATIC_HH +#define BENCH_STATIC_HH +#include "bench_parameter.hh" +#include <iostream> +#include "utilities.h" +#include "dump_file_x_y.hh" +#include "static/static_size_generator.hh" +#include "timers/portable_perf_analyzer.hh" +#include "timers/mixed_perf_analyzer.hh" +#include "timers/x86_perf_analyzer.hh" + +using namespace std; + + +template <template<class> class Perf_Analyzer, template<class> class Action, template<class,int> class Interface> +void bench_static(void) +{ + string filename = "bench_" + Action<Interface<REAL_TYPE,10> >::name() + ".dat"; + + INFOS("starting " << filename); + + const int max_size = TINY_MV_MAX_SIZE; + + std::vector<double> tab_mflops; + std::vector<double> tab_sizes; + + static_size_generator<max_size,Perf_Analyzer,Action,Interface>::go(tab_sizes,tab_mflops); + + dump_file_x_y(tab_sizes,tab_mflops,filename); +} + +// default Perf Analyzer +template <template<class> class Action, template<class,int> class Interface> +void bench_static(void) +{ + bench_static<Portable_Perf_Analyzer,Action,Interface>(); + //bench_static<Mixed_Perf_Analyzer,Action,Interface>(); + //bench_static<X86_Perf_Analyzer,Action,Interface>(); +} + +#endif + + + + + + + + + + + + + + + diff --git a/bench/btl/generic_bench/static/intel_bench_fixed_size.hh b/bench/btl/generic_bench/static/intel_bench_fixed_size.hh new file mode 100644 index 000000000..b4edcbc46 --- /dev/null +++ b/bench/btl/generic_bench/static/intel_bench_fixed_size.hh @@ -0,0 +1,66 @@ +//===================================================== +// File : intel_bench_fixed_size.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar déc 3 18:59:37 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef _BENCH_FIXED_SIZE_HH_ +#define _BENCH_FIXED_SIZE_HH_ + +#include "utilities.h" +#include "function_time.hh" + +template <class Action> +double bench_fixed_size(int size, unsigned long long & nb_calc,unsigned long long & nb_init) +{ + + Action action(size); + + double time_baseline=time_init(nb_init,action); + + while (time_baseline < MIN_TIME) { + + //INFOS("nb_init="<<nb_init); + //INFOS("time_baseline="<<time_baseline); + nb_init*=2; + time_baseline=time_init(nb_init,action); + } + + time_baseline=time_baseline/(double(nb_init)); + + double time_action=time_calculate(nb_calc,action); + + while (time_action < MIN_TIME) { + + nb_calc*=2; + time_action=time_calculate(nb_calc,action); + } + + INFOS("nb_init="<<nb_init); + INFOS("nb_calc="<<nb_calc); + + + time_action=time_action/(double(nb_calc)); + + action.check_result(); + + time_action=time_action-time_baseline; + + return action.nb_op_base()/(time_action*1000000.0); + +} + +#endif diff --git a/bench/btl/generic_bench/static/static_size_generator.hh b/bench/btl/generic_bench/static/static_size_generator.hh new file mode 100644 index 000000000..50f063bc0 --- /dev/null +++ b/bench/btl/generic_bench/static/static_size_generator.hh @@ -0,0 +1,56 @@ +//===================================================== +// File : static_size_generator.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar déc 3 18:59:36 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef _STATIC_SIZE_GENERATOR_HH +#define _STATIC_SIZE_GENERATOR_HH +#include <vector> + +using namespace std; + +//recursive generation of statically defined matrix and vector sizes + +template <int SIZE,template<class> class Perf_Analyzer, template<class> class Action, template<class,int> class Interface> +struct static_size_generator{ + static void go(vector<double> & tab_sizes, vector<double> & tab_mflops) + { + tab_sizes.push_back(SIZE); + + Perf_Analyzer<Action<Interface<REAL_TYPE,SIZE> > > perf_action; + tab_mflops.push_back(perf_action.eval_mflops(SIZE)); + static_size_generator<SIZE-1,Perf_Analyzer,Action,Interface>::go(tab_sizes,tab_mflops); + }; +}; + +//recursion end + +template <template<class> class Perf_Analyzer, template<class> class Action, template<class,int> class Interface> +struct static_size_generator<1,Perf_Analyzer,Action,Interface>{ + static void go(vector<double> & tab_sizes, vector<double> & tab_mflops) + { + tab_sizes.push_back(1); + Perf_Analyzer<Action<Interface<REAL_TYPE,1> > > perf_action; + tab_mflops.push_back(perf_action.eval_mflops(1)); + }; +}; + +#endif + + + + diff --git a/bench/btl/generic_bench/timers/STL_perf_analyzer.hh b/bench/btl/generic_bench/timers/STL_perf_analyzer.hh new file mode 100644 index 000000000..c9f894b1f --- /dev/null +++ b/bench/btl/generic_bench/timers/STL_perf_analyzer.hh @@ -0,0 +1,82 @@ +//===================================================== +// File : STL_perf_analyzer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar déc 3 18:59:35 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef _STL_PERF_ANALYSER_HH +#define _STL_PERF_ANALYSER_HH + +#include "STL_timer.hh" +#include "bench_parameter.hh" + +template<class ACTION> +class STL_Perf_Analyzer{ +public: + STL_Perf_Analyzer(unsigned long long nb_sample=DEFAULT_NB_SAMPLE):_nb_sample(nb_sample),_chronos() + { + MESSAGE("STL_Perf_Analyzer Ctor"); + }; + STL_Perf_Analyzer( const STL_Perf_Analyzer & ){ + INFOS("Copy Ctor not implemented"); + exit(0); + }; + ~STL_Perf_Analyzer( void ){ + MESSAGE("STL_Perf_Analyzer Dtor"); + }; + + + inline double eval_mflops(int size) + { + + ACTION action(size); + + _chronos.start_baseline(_nb_sample); + + do { + + action.initialize(); + } while (_chronos.check()); + + double baseline_time=_chronos.get_time(); + + _chronos.start(_nb_sample); + do { + action.initialize(); + action.calculate(); + } while (_chronos.check()); + + double calculate_time=_chronos.get_time(); + + double corrected_time=calculate_time-baseline_time; + + // cout << size <<" "<<baseline_time<<" "<<calculate_time<<" "<<corrected_time<<" "<<action.nb_op_base() << endl; + + return action.nb_op_base()/(corrected_time*1000000.0); + //return action.nb_op_base()/(calculate_time*1000000.0); + + } +private: + + STL_Timer _chronos; + unsigned long long _nb_sample; + + +}; + + + +#endif diff --git a/bench/btl/generic_bench/timers/STL_timer.hh b/bench/btl/generic_bench/timers/STL_timer.hh new file mode 100644 index 000000000..19c54e9c1 --- /dev/null +++ b/bench/btl/generic_bench/timers/STL_timer.hh @@ -0,0 +1,78 @@ +//===================================================== +// File : STL_Timer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar déc 3 18:59:35 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// STL Timer Class. Adapted (L.P.) from the timer class by Musser et Al +// described int the Book : STL Tutorial and reference guide. +// Define a timer class for analyzing algorithm performance. +#include <iostream> +#include <iomanip> +#include <vector> +#include <map> +#include <algorithm> +using namespace std; + +class STL_Timer { +public: + STL_Timer(){ baseline = false; }; // Default constructor + // Start a series of r trials: + void start(unsigned int r){ + reps = r; + count = 0; + iterations.clear(); + iterations.reserve(reps); + initial = time(0); + }; + // Start a series of r trials to determine baseline time: + void start_baseline(unsigned int r) + { + baseline = true; + start(r); + } + // Returns true if the trials have been completed, else false + bool check() + { + ++count; + final = time(0); + if (initial < final) { + iterations.push_back(count); + initial = final; + count = 0; + } + return (iterations.size() < reps); + }; + // Returns the results for external use + double get_time( void ) + { + sort(iterations.begin(), iterations.end()); + return 1.0/iterations[reps/2]; + }; +private: + unsigned int reps; // Number of trials + // For storing loop iterations of a trial + vector<long> iterations; + // For saving initial and final times of a trial + time_t initial, final; + // For counting loop iterations of a trial + unsigned long count; + // true if this is a baseline computation, false otherwise + bool baseline; + // For recording the baseline time + double baseline_time; +}; + diff --git a/bench/btl/generic_bench/timers/mixed_perf_analyzer.hh b/bench/btl/generic_bench/timers/mixed_perf_analyzer.hh new file mode 100644 index 000000000..e190236e0 --- /dev/null +++ b/bench/btl/generic_bench/timers/mixed_perf_analyzer.hh @@ -0,0 +1,73 @@ +//===================================================== +// File : mixed_perf_analyzer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar déc 3 18:59:36 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef _MIXED_PERF_ANALYSER_HH +#define _MIXED_PERF_ANALYSER_HH + +#include "x86_perf_analyzer.hh" +#include "portable_perf_analyzer.hh" + +// choose portable perf analyzer for long calculations and x86 analyser for short ones + + +template<class Action> +class Mixed_Perf_Analyzer{ + +public: + Mixed_Perf_Analyzer( void ):_x86pa(),_ppa(),_use_ppa(true) + { + MESSAGE("Mixed_Perf_Analyzer Ctor"); + }; + Mixed_Perf_Analyzer( const Mixed_Perf_Analyzer & ){ + INFOS("Copy Ctor not implemented"); + exit(0); + }; + ~Mixed_Perf_Analyzer( void ){ + MESSAGE("Mixed_Perf_Analyzer Dtor"); + }; + + + inline double eval_mflops(int size) + { + + double result=0.0; + if (_use_ppa){ + result=_ppa.eval_mflops(size); + if (_ppa.get_nb_calc()>DEFAULT_NB_SAMPLE){_use_ppa=false;} + } + else{ + result=_x86pa.eval_mflops(size); + } + + return result; + } + +private: + + Portable_Perf_Analyzer<Action> _ppa; + X86_Perf_Analyzer<Action> _x86pa; + bool _use_ppa; + +}; + +#endif + + + + diff --git a/bench/btl/generic_bench/timers/portable_perf_analyzer.hh b/bench/btl/generic_bench/timers/portable_perf_analyzer.hh new file mode 100644 index 000000000..709f0de5d --- /dev/null +++ b/bench/btl/generic_bench/timers/portable_perf_analyzer.hh @@ -0,0 +1,98 @@ +//===================================================== +// File : portable_perf_analyzer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar d�c 3 18:59:35 CET 2002 +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef _PORTABLE_PERF_ANALYZER_HH +#define _PORTABLE_PERF_ANALYZER_HH + +#include "utilities.h" +#include "timers/portable_timer.hh" + +template <class Action> +class Portable_Perf_Analyzer{ +public: + Portable_Perf_Analyzer( void ):_nb_calc(1),_chronos(){ + MESSAGE("Portable_Perf_Analyzer Ctor"); + }; + Portable_Perf_Analyzer( const Portable_Perf_Analyzer & ){ + INFOS("Copy Ctor not implemented"); + exit(0); + }; + ~Portable_Perf_Analyzer( void ){ + MESSAGE("Portable_Perf_Analyzer Dtor"); + }; + + + + inline double eval_mflops(int size) + { + Action action(size); + + + double time_action = time_calculate(action); + while (time_action < MIN_TIME) + { + _nb_calc *= 2; + action.initialize(); + time_action = time_calculate(action); + } + + // optimize + for (int i=1; i<NB_TRIES; ++i) + { + action.initialize(); + time_action = std::min(time_action, time_calculate(action)); + } + + time_action = time_action / (double(_nb_calc)); + + // check + action.initialize(); + action.calculate(); + action.check_result(); + + return action.nb_op_base()/(time_action*1000000.0); + } + + double time_calculate(Action & action) + { + // time measurement + _chronos.start(); + for (int ii=0;ii<_nb_calc;ii++) + { + action.calculate(); + } + _chronos.stop(); + return _chronos.user_time(); + } + + unsigned long long get_nb_calc( void ) + { + return _nb_calc; + } + + +private: + unsigned long long _nb_calc; + Portable_Timer _chronos; + +}; + +#endif //_PORTABLE_PERF_ANALYZER_HH + diff --git a/bench/btl/generic_bench/timers/portable_perf_analyzer_old.hh b/bench/btl/generic_bench/timers/portable_perf_analyzer_old.hh new file mode 100644 index 000000000..fce378168 --- /dev/null +++ b/bench/btl/generic_bench/timers/portable_perf_analyzer_old.hh @@ -0,0 +1,134 @@ +//===================================================== +// File : portable_perf_analyzer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar d�c 3 18:59:35 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef _PORTABLE_PERF_ANALYZER_HH +#define _PORTABLE_PERF_ANALYZER_HH + +#include "utilities.h" +#include "timers/portable_timer.hh" + +template <class Action> +class Portable_Perf_Analyzer{ +public: + Portable_Perf_Analyzer( void ):_nb_calc(1),_nb_init(1),_chronos(){ + MESSAGE("Portable_Perf_Analyzer Ctor"); + }; + Portable_Perf_Analyzer( const Portable_Perf_Analyzer & ){ + INFOS("Copy Ctor not implemented"); + exit(0); + }; + ~Portable_Perf_Analyzer( void ){ + MESSAGE("Portable_Perf_Analyzer Dtor"); + }; + + + + inline double eval_mflops(int size) + { + + Action action(size); + +// double time_baseline = time_init(action); +// while (time_baseline < MIN_TIME_INIT) +// { +// _nb_init *= 2; +// time_baseline = time_init(action); +// } +// +// // optimize +// for (int i=1; i<NB_TRIES; ++i) +// time_baseline = std::min(time_baseline, time_init(action)); +// +// time_baseline = time_baseline/(double(_nb_init)); + + double time_action = time_calculate(action); + while (time_action < MIN_TIME) + { + _nb_calc *= 2; + time_action = time_calculate(action); + } + + // optimize + for (int i=1; i<NB_TRIES; ++i) + time_action = std::min(time_action, time_calculate(action)); + +// INFOS("size="<<size); +// INFOS("_nb_init="<<_nb_init); +// INFOS("_nb_calc="<<_nb_calc); + + time_action = time_action / (double(_nb_calc)); + + action.check_result(); + + + double time_baseline = time_init(action); + for (int i=1; i<NB_TRIES; ++i) + time_baseline = std::min(time_baseline, time_init(action)); + time_baseline = time_baseline/(double(_nb_init)); + + + +// INFOS("time_baseline="<<time_baseline); +// INFOS("time_action="<<time_action); + + time_action = time_action - time_baseline; + +// INFOS("time_corrected="<<time_action); + + return action.nb_op_base()/(time_action*1000000.0); + } + + inline double time_init(Action & action) + { + // time measurement + _chronos.start(); + for (int ii=0; ii<_nb_init; ii++) + action.initialize(); + _chronos.stop(); + return _chronos.user_time(); + } + + + inline double time_calculate(Action & action) + { + // time measurement + _chronos.start(); + for (int ii=0;ii<_nb_calc;ii++) + { + action.initialize(); + action.calculate(); + } + _chronos.stop(); + return _chronos.user_time(); + } + + unsigned long long get_nb_calc( void ) + { + return _nb_calc; + } + + +private: + unsigned long long _nb_calc; + unsigned long long _nb_init; + Portable_Timer _chronos; + +}; + +#endif //_PORTABLE_PERF_ANALYZER_HH diff --git a/bench/btl/generic_bench/timers/portable_timer.hh b/bench/btl/generic_bench/timers/portable_timer.hh new file mode 100755 index 000000000..3b7c5266b --- /dev/null +++ b/bench/btl/generic_bench/timers/portable_timer.hh @@ -0,0 +1,103 @@ +//===================================================== +// File : portable_timer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> from boost lib +// Copyright (C) EDF R&D, lun sep 30 14:23:17 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// simple_time extracted from the boost library +// +#ifndef _PORTABLE_TIMER_HH +#define _PORTABLE_TIMER_HH + +#include <time.h> +#include <sys/time.h> +#include <sys/resource.h> +#include <unistd.h> +#include <sys/times.h> + +#define USEC_IN_SEC 1000000 + + +// timer -------------------------------------------------------------------// + +// A timer object measures CPU time. + +class Portable_Timer +{ + public: + + Portable_Timer( void ):_utime_sec_start(-1), + _utime_usec_start(-1), + _utime_sec_stop(-1), + _utime_usec_stop(-1) + { + } + + + void start() + { + + int status=getrusage(RUSAGE_SELF, &resourcesUsage) ; + + _start_time = std::clock(); + + _utime_sec_start = resourcesUsage.ru_utime.tv_sec ; + _utime_usec_start = resourcesUsage.ru_utime.tv_usec ; + + } + + void stop() + { + + int status=getrusage(RUSAGE_SELF, &resourcesUsage) ; + + _stop_time = std::clock(); + + _utime_sec_stop = resourcesUsage.ru_utime.tv_sec ; + _utime_usec_stop = resourcesUsage.ru_utime.tv_usec ; + + } + + double elapsed() + { + return double(_stop_time - _start_time) / CLOCKS_PER_SEC; + } + + double user_time() + { + long tot_utime_sec=_utime_sec_stop-_utime_sec_start; + long tot_utime_usec=_utime_usec_stop-_utime_usec_start; + return double(tot_utime_sec)+ double(tot_utime_usec)/double(USEC_IN_SEC) ; + } + + +private: + + struct rusage resourcesUsage ; + + long _utime_sec_start ; + long _utime_usec_start ; + + long _utime_sec_stop ; + long _utime_usec_stop ; + + std::clock_t _start_time; + std::clock_t _stop_time; + +}; // Portable_Timer + + +#endif // PORTABLE_TIMER_HPP diff --git a/bench/btl/generic_bench/timers/x86_perf_analyzer.hh b/bench/btl/generic_bench/timers/x86_perf_analyzer.hh new file mode 100644 index 000000000..37ea21dcc --- /dev/null +++ b/bench/btl/generic_bench/timers/x86_perf_analyzer.hh @@ -0,0 +1,108 @@ +//===================================================== +// File : x86_perf_analyzer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar d�c 3 18:59:35 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef _X86_PERF_ANALYSER_HH +#define _X86_PERF_ANALYSER_HH + +#include "x86_timer.hh" +#include "bench_parameter.hh" + +template<class ACTION> +class X86_Perf_Analyzer{ +public: + X86_Perf_Analyzer( unsigned long long nb_sample=DEFAULT_NB_SAMPLE):_nb_sample(nb_sample),_chronos() + { + MESSAGE("X86_Perf_Analyzer Ctor"); + _chronos.find_frequency(); + }; + X86_Perf_Analyzer( const X86_Perf_Analyzer & ){ + INFOS("Copy Ctor not implemented"); + exit(0); + }; + ~X86_Perf_Analyzer( void ){ + MESSAGE("X86_Perf_Analyzer Dtor"); + }; + + + inline double eval_mflops(int size) + { + + ACTION action(size); + + int nb_loop=5; + double calculate_time=0.0; + double baseline_time=0.0; + + for (int j=0 ; j < nb_loop ; j++){ + + _chronos.clear(); + + for(int i=0 ; i < _nb_sample ; i++) + { + _chronos.start(); + action.initialize(); + action.calculate(); + _chronos.stop(); + _chronos.add_get_click(); + } + + calculate_time += double(_chronos.get_shortest_clicks())/_chronos.frequency(); + + if (j==0) action.check_result(); + + _chronos.clear(); + + for(int i=0 ; i < _nb_sample ; i++) + { + _chronos.start(); + action.initialize(); + _chronos.stop(); + _chronos.add_get_click(); + + } + + baseline_time+=double(_chronos.get_shortest_clicks())/_chronos.frequency(); + + } + + double corrected_time = (calculate_time-baseline_time)/double(nb_loop); + + +// INFOS("_nb_sample="<<_nb_sample); +// INFOS("baseline_time="<<baseline_time); +// INFOS("calculate_time="<<calculate_time); +// INFOS("corrected_time="<<corrected_time); + +// cout << size <<" "<<baseline_time<<" "<<calculate_time<<" "<<corrected_time<<" "<<action.nb_op_base() << endl; + + return action.nb_op_base()/(corrected_time*1000000.0); + //return action.nb_op_base()/(calculate_time*1000000.0); + } + +private: + + X86_Timer _chronos; + unsigned long long _nb_sample; + + +}; + + + +#endif diff --git a/bench/btl/generic_bench/timers/x86_timer.hh b/bench/btl/generic_bench/timers/x86_timer.hh new file mode 100644 index 000000000..cfb5ee833 --- /dev/null +++ b/bench/btl/generic_bench/timers/x86_timer.hh @@ -0,0 +1,246 @@ +//===================================================== +// File : x86_timer.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar d�c 3 18:59:35 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef _X86_TIMER_HH +#define _X86_TIMER_HH + +#include <sys/time.h> +#include <sys/resource.h> +#include <unistd.h> +#include <sys/times.h> +//#include "system_time.h" +#define u32 unsigned int +#include <asm/msr.h> +#include "utilities.h" +#include <map> +#include <fstream> +#include <string> +#include <iostream> + +// frequence de la becanne en Hz +//#define FREQUENCY 648000000 +//#define FREQUENCY 1400000000 +#define FREQUENCY 1695000000 + +using namespace std; + + +class X86_Timer { + +public : + + X86_Timer( void ):_frequency(FREQUENCY),_nb_sample(0) + { + MESSAGE("X86_Timer Default Ctor"); + } + + inline void start( void ){ + + rdtsc(_click_start.n32[0],_click_start.n32[1]); + + } + + + inline void stop( void ){ + + rdtsc(_click_stop.n32[0],_click_stop.n32[1]); + + } + + + inline double frequency( void ){ + return _frequency; + } + + double get_elapsed_time_in_second( void ){ + + return (_click_stop.n64-_click_start.n64)/double(FREQUENCY); + + + } + + unsigned long long get_click( void ){ + + return (_click_stop.n64-_click_start.n64); + + } + + inline void find_frequency( void ){ + + time_t initial, final; + int dummy=2; + + initial = time(0); + start(); + do { + dummy+=2; + } + while(time(0)==initial); + // On est au debut d'un cycle d'une seconde !!! + initial = time(0); + start(); + do { + dummy+=2; + } + while(time(0)==initial); + final=time(0); + stop(); + // INFOS("fine grained time : "<< get_elapsed_time_in_second()); + // INFOS("coarse grained time : "<< final-initial); + _frequency=_frequency*get_elapsed_time_in_second()/double(final-initial); + /// INFOS("CPU frequency : "<< _frequency); + + } + + void add_get_click( void ){ + + _nb_sample++; + _counted_clicks[get_click()]++; + fill_history_clicks(); + + } + + void dump_statistics(string filemane){ + + ofstream outfile (filemane.c_str(),ios::out) ; + + std::map<unsigned long long , unsigned long long>::iterator itr; + for(itr=_counted_clicks.begin() ; itr!=_counted_clicks.end() ; itr++) + { + outfile << (*itr).first << " " << (*itr).second << endl ; + } + + outfile.close(); + + } + + void dump_history(string filemane){ + + ofstream outfile (filemane.c_str(),ios::out) ; + + + + for(int i=0 ; i<_history_mean_clicks.size() ; i++) + { + outfile << i << " " + << _history_mean_clicks[i] << " " + << _history_shortest_clicks[i] << " " + << _history_most_occured_clicks[i] << endl ; + } + + outfile.close(); + + } + + + + double get_mean_clicks( void ){ + + std::map<unsigned long long,unsigned long long>::iterator itr; + + unsigned long long mean_clicks=0; + + for(itr=_counted_clicks.begin() ; itr!=_counted_clicks.end() ; itr++) + { + + mean_clicks+=(*itr).second*(*itr).first; + } + + return mean_clicks/double(_nb_sample); + + } + + double get_shortest_clicks( void ){ + + return double((*_counted_clicks.begin()).first); + + } + + void fill_history_clicks( void ){ + + _history_mean_clicks.push_back(get_mean_clicks()); + _history_shortest_clicks.push_back(get_shortest_clicks()); + _history_most_occured_clicks.push_back(get_most_occured_clicks()); + + } + + + double get_most_occured_clicks( void ){ + + unsigned long long moc=0; + unsigned long long max_occurence=0; + + std::map<unsigned long long,unsigned long long>::iterator itr; + + for(itr=_counted_clicks.begin() ; itr!=_counted_clicks.end() ; itr++) + { + + if (max_occurence<=(*itr).second){ + max_occurence=(*itr).second; + moc=(*itr).first; + } + } + + return double(moc); + + } + + void clear( void ) + { + _counted_clicks.clear(); + + _history_mean_clicks.clear(); + _history_shortest_clicks.clear(); + _history_most_occured_clicks.clear(); + + _nb_sample=0; + } + + + +private : + + union + { + unsigned long int n32[2] ; + unsigned long long n64 ; + } _click_start; + + union + { + unsigned long int n32[2] ; + unsigned long long n64 ; + } _click_stop; + + double _frequency ; + + map<unsigned long long,unsigned long long> _counted_clicks; + + vector<double> _history_mean_clicks; + vector<double> _history_shortest_clicks; + vector<double> _history_most_occured_clicks; + + unsigned long long _nb_sample; + + + +}; + + +#endif diff --git a/bench/btl/generic_bench/utils/dump_file_x_y.hh b/bench/btl/generic_bench/utils/dump_file_x_y.hh new file mode 100644 index 000000000..6b99dcb10 --- /dev/null +++ b/bench/btl/generic_bench/utils/dump_file_x_y.hh @@ -0,0 +1,47 @@ +//===================================================== +// File : dump_file_x_y.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:20 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef DUMP_FILE_X_Y_HH +#define DUMP_FILE_X_Y_HH +#include <fstream> +#include <string> + +// The Vector class must satisfy the following part of STL vector concept : +// resize() method +// [] operator for seting element +// the vector element must have the << operator define + +using namespace std; + +template<class Vector_A, class Vector_B> +void dump_file_x_y(const Vector_A & X, const Vector_B & Y, const std::string & filename){ + + ofstream outfile (filename.c_str(),ios::out) ; + int size=X.size(); + + for (int i=0;i<size;i++){ + + outfile << X[i] << " " << Y[i] << endl ; + + } + + outfile.close(); +} + +#endif diff --git a/bench/btl/generic_bench/utils/size_lin_log.hh b/bench/btl/generic_bench/utils/size_lin_log.hh new file mode 100644 index 000000000..bca3932ae --- /dev/null +++ b/bench/btl/generic_bench/utils/size_lin_log.hh @@ -0,0 +1,70 @@ +//===================================================== +// File : size_lin_log.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, mar déc 3 18:59:37 CET 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef SIZE_LIN_LOG +#define SIZE_LIN_LOG + +#include "size_log.hh" + +template<class Vector> +void size_lin_log(const int nb_point, const int size_min, const int size_max, Vector & X) +{ + int ten=10; + int nine=9; + + X.resize(nb_point); + + if (nb_point>ten){ + + for (int i=0;i<nine;i++){ + + X[i]=i+1; + + } + + Vector log_size; + size_log(nb_point-nine,ten,size_max,log_size); + + for (int i=0;i<nb_point-nine;i++){ + + X[i+nine]=log_size[i]; + + } + } + else{ + + for (int i=0;i<nb_point;i++){ + + X[i]=i+1; + + } + } + + // for (int i=0;i<nb_point;i++){ + +// INFOS("computed sizes : X["<<i<<"]="<<X[i]); + +// } + +} + +#endif + + + diff --git a/bench/btl/generic_bench/utils/size_log.hh b/bench/btl/generic_bench/utils/size_log.hh new file mode 100644 index 000000000..13a3da7a8 --- /dev/null +++ b/bench/btl/generic_bench/utils/size_log.hh @@ -0,0 +1,54 @@ +//===================================================== +// File : size_log.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:17 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef SIZE_LOG +#define SIZE_LOG + +#include "math.h" +// The Vector class must satisfy the following part of STL vector concept : +// resize() method +// [] operator for seting element +// the vector element are int compatible. +template<class Vector> +void size_log(const int nb_point, const int size_min, const int size_max, Vector & X) +{ + X.resize(nb_point); + + float ls_min=log(float(size_min)); + float ls_max=log(float(size_max)); + + float ls=0.0; + + float delta_ls=(ls_max-ls_min)/(float(nb_point-1)); + + int size=0; + + for (int i=0;i<nb_point;i++){ + + ls = ls_min + float(i)*delta_ls ; + + size=int(exp(ls)); + + X[i]=size; + } + +} + + +#endif diff --git a/bench/btl/generic_bench/utils/utilities.h b/bench/btl/generic_bench/utils/utilities.h new file mode 100644 index 000000000..3c2acfb02 --- /dev/null +++ b/bench/btl/generic_bench/utils/utilities.h @@ -0,0 +1,90 @@ +//============================================================================= +// File : utilities.h +// Created : mar jun 19 13:18:14 CEST 2001 +// Author : Antoine YESSAYAN, Paul RASCLE, EDF +// Project : SALOME +// Copyright : EDF 2001 +// $Header$ +//============================================================================= + +/* --- Definition macros file to print informations if _DEBUG_ is defined --- */ + +# ifndef UTILITIES_H +# define UTILITIES_H + +# include <stdlib.h> +//# include <iostream> ok for gcc3.01 +# include <iostream> + +/* --- INFOS is always defined (without _DEBUG_): to be used for warnings, with release version --- */ + +# define HEREWEARE cout<<flush ; cerr << __FILE__ << " [" << __LINE__ << "] : " << flush ; +# define INFOS(chain) {HEREWEARE ; cerr << chain << endl ;} +# define PYSCRIPT(chain) {cout<<flush ; cerr << "---PYSCRIPT--- " << chain << endl ;} + +/* --- To print date and time of compilation of current source on stdout --- */ + +# if defined ( __GNUC__ ) +# define COMPILER "g++" ; +# elif defined ( __sun ) +# define COMPILER "CC" ; +# elif defined ( __KCC ) +# define COMPILER "KCC" ; +# elif defined ( __PGI ) +# define COMPILER "pgCC" ; +# else +# define COMPILER "undefined" ; +# endif + +# ifdef INFOS_COMPILATION +# error INFOS_COMPILATION already defined +# endif +# define INFOS_COMPILATION {\ + cerr << flush;\ + cout << __FILE__ ;\ + cout << " [" << __LINE__ << "] : " ;\ + cout << "COMPILED with " << COMPILER ;\ + cout << ", " << __DATE__ ; \ + cout << " at " << __TIME__ << endl ;\ + cout << "\n\n" ;\ + cout << flush ;\ + } + +# ifdef _DEBUG_ + +/* --- the following MACROS are useful at debug time --- */ + +# define HERE cout<<flush ; cerr << "- Trace " << __FILE__ << " [" << __LINE__ << "] : " << flush ; +# define SCRUTE(var) HERE ; cerr << #var << "=" << var << endl ; +# define MESSAGE(chain) {HERE ; cerr << chain << endl ;} +# define INTERRUPTION(code) HERE ; cerr << "INTERRUPTION return code= " << code << endl ; exit(code) ; + +# ifndef ASSERT +# define ASSERT(condition) if (!(condition)){ HERE ; cerr << "CONDITION " << #condition << " NOT VERIFIED"<< endl ; INTERRUPTION(1) ;} +# endif /* ASSERT */ + +#define REPERE cout<<flush ; cerr << " --------------" << endl << flush ; +#define BEGIN_OF(chain) {REPERE ; HERE ; cerr << "Begin of: " << chain << endl ; REPERE ; } +#define END_OF(chain) {REPERE ; HERE ; cerr << "Normal end of: " << chain << endl ; REPERE ; } + + + +# else /* ifdef _DEBUG_*/ + +# define HERE +# define SCRUTE(var) +# define MESSAGE(chain) +# define INTERRUPTION(code) + +# ifndef ASSERT +# define ASSERT(condition) +# endif /* ASSERT */ + +#define REPERE +#define BEGIN_OF(chain) +#define END_OF(chain) + + +# endif /* ifdef _DEBUG_*/ + +# endif /* ifndef UTILITIES_H */ diff --git a/bench/btl/libs/ATLAS/ATLAS_LU_solve_interface.hh b/bench/btl/libs/ATLAS/ATLAS_LU_solve_interface.hh new file mode 100644 index 000000000..83732b4a2 --- /dev/null +++ b/bench/btl/libs/ATLAS/ATLAS_LU_solve_interface.hh @@ -0,0 +1,118 @@ +//===================================================== +// File : ATLAS_LU_solve_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:22 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef ATLAS_LU_solve_interface_HH +#define ATLAS_LU_solve_interface_HH +#include "ATLAS_interface.hh" +extern "C" +{ +#include <atlas_level1.h> +#include <atlas_level2.h> +#include <atlas_level3.h> +#include "cblas.h" +#include <atlas_lapack.h> + +} + +template<class real> +class ATLAS_LU_solve_interface : public ATLAS_interface<real> +{ +public : + + typedef typename ATLAS_interface<real>::gene_matrix gene_matrix; + typedef typename ATLAS_interface<real>::gene_vector gene_vector; + + typedef int * Pivot_Vector; + + inline static void new_Pivot_Vector(Pivot_Vector & pivot, int N) + { + + pivot = new int[N]; + + } + + inline static void free_Pivot_Vector(Pivot_Vector & pivot) + { + + delete pivot; + + } + + + inline static void LU_factor(gene_matrix & LU, Pivot_Vector & pivot, int N) + { + + int error=ATL_dgetrf(CblasColMajor,N,N,LU,N,pivot); + + } + + inline static void LU_solve(const gene_matrix & LU, const Pivot_Vector pivot, const gene_vector &B, gene_vector X, int N) + { + + copy_vector(B,X,N); + ATL_dgetrs(CblasColMajor,CblasNoTrans,N,1,LU,N,pivot,X,N); + + } + +}; + +template<> +class ATLAS_LU_solve_interface<float> : public ATLAS_interface<float> +{ +public : + + typedef int * Pivot_Vector; + + inline static void new_Pivot_Vector(Pivot_Vector & pivot, int N) + { + + pivot = new int[N]; + + } + + inline static void free_Pivot_Vector(Pivot_Vector & pivot) + { + + delete pivot; + + } + + + inline static void LU_factor(gene_matrix & LU, Pivot_Vector & pivot, int N) + { + + int error=ATL_sgetrf(CblasColMajor,N,N,LU,N,pivot); + + } + + inline static void LU_solve(const gene_matrix & LU, const Pivot_Vector pivot, const gene_vector &B, gene_vector X, int N) + { + + copy_vector(B,X,N); + ATL_sgetrs(CblasColMajor,CblasNoTrans,N,1,LU,N,pivot,X,N); + + } + +}; + + +#endif + + + diff --git a/bench/btl/libs/ATLAS/ATLAS_interface.hh b/bench/btl/libs/ATLAS/ATLAS_interface.hh new file mode 100644 index 000000000..a0e93854b --- /dev/null +++ b/bench/btl/libs/ATLAS/ATLAS_interface.hh @@ -0,0 +1,120 @@ +//===================================================== +// File : ATLAS_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:21 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef ATLAS_PRODUIT_MATRICE_VECTEUR_HH +#define ATLAS_PRODUIT_MATRICE_VECTEUR_HH +#include "f77_interface_base.hh" +#include <string> +extern "C" +{ +#include <atlas_level1.h> +#include <atlas_level2.h> +#include <atlas_level3.h> +#include "cblas.h" + +} + +template<class real> +class ATLAS_interface : public f77_interface_base<real> +{ +public : + + typedef typename f77_interface_base<real>::gene_matrix gene_matrix; + typedef typename f77_interface_base<real>::gene_vector gene_vector; + + static inline std::string name( void ) + { + return "ATLAS"; + } + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) + { + + ATL_dgemv(CblasNoTrans,N,N,1.0,A,N,B,1,0.0,X,1); + + } + + static inline void matrix_matrix_product(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N) + { + ATL_dgemm(CblasNoTrans,CblasNoTrans,N,N,N,1.0,A,N,B,N,0.0,X,N); + } + + static inline void ata_product(gene_matrix & A, gene_matrix & X, int N) + { + ATL_dgemm(CblasTrans,CblasNoTrans,N,N,N,1.0,A,N,A,N,0.0,X,N); + } + + static inline void aat_product(gene_matrix & A, gene_matrix & X, int N) + { + ATL_dgemm(CblasNoTrans,CblasTrans,N,N,N,1.0,A,N,A,N,0.0,X,N); + } + + + + static inline void axpy(real coef, const gene_vector & X, gene_vector & Y, int N) + { + ATL_daxpy(N,coef,X,1,Y,1); + } +}; + +template<> +class ATLAS_interface<float> : public f77_interface_base<float> +{ +public : + + static inline std::string name( void ) + { + return "ATLAS"; + } + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) + { + + ATL_sgemv(CblasNoTrans,N,N,1.0,A,N,B,1,0.0,X,1); + + } + + static inline void matrix_matrix_product(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N) + { + ATL_sgemm(CblasNoTrans,CblasNoTrans,N,N,N,1.0,A,N,B,N,0.0,X,N); + + } + + static inline void ata_product(gene_matrix & A, gene_matrix & X, int N) + { + ATL_sgemm(CblasTrans,CblasNoTrans,N,N,N,1.0,A,N,A,N,0.0,X,N); + } + + static inline void aat_product(gene_matrix & A, gene_matrix & X, int N) + { + ATL_sgemm(CblasNoTrans,CblasTrans,N,N,N,1.0,A,N,A,N,0.0,X,N); + } + + + static inline void axpy(float coef, const gene_vector & X, gene_vector & Y, int N) + { + ATL_saxpy(N,coef,X,1,Y,1); + } +}; + + +#endif + + + diff --git a/bench/btl/libs/ATLAS/CMakeLists.txt b/bench/btl/libs/ATLAS/CMakeLists.txt new file mode 100644 index 000000000..e047b4e08 --- /dev/null +++ b/bench/btl/libs/ATLAS/CMakeLists.txt @@ -0,0 +1,4 @@ + +include_directories(${BLITZ_INCLUDES}) +add_executable(btl_blitz main.cpp) +target_link_libraries(btl_blitz ${BLITZ_LIBRARIES}) diff --git a/bench/btl/libs/ATLAS/main.cpp b/bench/btl/libs/ATLAS/main.cpp new file mode 100644 index 000000000..2383a7367 --- /dev/null +++ b/bench/btl/libs/ATLAS/main.cpp @@ -0,0 +1,49 @@ +//===================================================== +// File : main.cpp +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:21 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include "ATLAS_interface.hh" +#include "ATLAS_LU_solve_interface.hh" +#include "bench.hh" +#include "action_matrix_vector_product.hh" +#include "action_matrix_matrix_product.hh" +#include "action_axpy.hh" +#include "action_lu_solve.hh" +#include "action_ata_product.hh" +#include "action_aat_product.hh" + + +int main() +{ + bench<Action_axpy<ATLAS_interface<REAL_TYPE> > >(MIN_AXPY,MAX_AXPY,NB_POINT); + + bench<Action_matrix_vector_product<ATLAS_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + + bench<Action_matrix_matrix_product<ATLAS_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + bench<Action_ata_product<ATLAS_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + bench<Action_aat_product<ATLAS_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + // bench<Action_lu_solve<ATLAS_LU_solve_interface<REAL_TYPE> > >(MIN_LU,MAX_LU,NB_POINT); + + return 0; +} + + diff --git a/bench/btl/libs/ATLAS/titi.txt b/bench/btl/libs/ATLAS/titi.txt new file mode 100644 index 000000000..470501f6f --- /dev/null +++ b/bench/btl/libs/ATLAS/titi.txt @@ -0,0 +1,33 @@ +Bonjour à tous, + +Une dizaine de candidats Neptune se sont déjà déclarés pour la formation C++ +(sur la base de 2 jours/semaine pendant 1 mois). + +Il faut faire une proposition de date pour la formation. Les vacances scolaires zone C (Paris) +se terminent le 22 avril (au matin) nous pourrions commencer ce jour. + +A priori il me semble que deux jours consécutifs soient préférables. Je propose les mardi et mercredi +de chaque semaine. Sachant qu'il y a 2 jeudi (1er et 8 mai) consécutifs qui sont fériés. + +Dans cette hypothèse les dates de formation seraient : + +Mardi 22 avril (Vincent/Marc) +Mercredi 23 avril (Marc) + +Mardi 29 avril (Marc/Antoine) +Mercredi 30 avril (Antoine) + +Mardi 6 mai (Antoine) +Mercredi 7 mai (Antoine) + +Mardi 13 mai (Laurent) +Mercredi 14 mai (Laurent) + +J'ai mis entre parenthèse les intervenants principaux (on doit choisir le deuxième formateur pour chaque session). + +Qu'en pensez-vous ? + +Je dois toujours présenter un programme, pouvez-vous me donner vos programmes respectifs...? + + +Laurent diff --git a/bench/btl/libs/C/CMakeLists.txt b/bench/btl/libs/C/CMakeLists.txt new file mode 100644 index 000000000..d3d2312d8 --- /dev/null +++ b/bench/btl/libs/C/CMakeLists.txt @@ -0,0 +1,2 @@ +include_directories(${PROJECT_SOURCE_DIR}/libs/f77) +btl_add_bench(btl_C main.cpp) diff --git a/bench/btl/libs/C/C_interface.hh b/bench/btl/libs/C/C_interface.hh new file mode 100755 index 000000000..b688f18fa --- /dev/null +++ b/bench/btl/libs/C/C_interface.hh @@ -0,0 +1,96 @@ +//===================================================== +// File : C_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:23 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef C_INTERFACE_HH +#define C_INTERFACE_HH + +#include "f77_interface.hh" + +template<class real> +class C_interface : public f77_interface_base<real> { + +public : + + typedef typename f77_interface_base<real>::gene_matrix gene_matrix; + typedef typename f77_interface_base<real>::gene_vector gene_vector; + + static inline std::string name() { return "C"; } + + static inline void matrix_vector_product(const gene_matrix & A, const gene_vector & B, gene_vector & X, int N) + { + for (int i=0;i<N;i++) + { + real somme = 0.0; + for (int j=0;j<N;j++) + somme += A[j*N+i] * B[j]; + X[i] = somme; + } + } + + static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N) + { + real somme; + for (int i=0;i<N;i++){ + for (int j=0;j<N;j++){ + somme=0.0; + for (int k=0;k<N;k++){ + somme += A[i+k*N] * B[k+j*N]; + } + X[i+j*N] = somme; + } + } + } + + static inline void ata_product(const gene_matrix & A, gene_matrix & X, int N) + { + + real somme; + for (int i=0;i<N;i++){ + for (int j=0;j<N;j++){ + somme=0.0; + for (int k=0;k<N;k++){ + somme+=A[k+i*N]*A[k+j*N]; + } + X[i+j*N]=somme; + } + } + } + + static inline void aat_product(const gene_matrix & A, gene_matrix & X, int N){ + real somme; + for (int i=0;i<N;i++){ + for (int j=0;j<N;j++){ + somme=0.0; + for (int k=0;k<N;k++){ + somme+=A[i+k*N]*A[j+k*N]; + } + X[i+j*N] = somme; + } + } + } + + static inline void axpy(real coef, const gene_vector & X, gene_vector & Y, int N){ + for (int i=0;i<N;i++) + Y[i]+=coef*X[i]; + } + + +}; + +#endif diff --git a/bench/btl/libs/C/main.cpp b/bench/btl/libs/C/main.cpp new file mode 100644 index 000000000..b15b7d9d5 --- /dev/null +++ b/bench/btl/libs/C/main.cpp @@ -0,0 +1,44 @@ +//===================================================== +// File : main.cpp +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:23 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include "bench.hh" +#include "C_interface.hh" +#include "action_matrix_vector_product.hh" +#include "action_matrix_matrix_product.hh" +#include "action_axpy.hh" +#include "action_ata_product.hh" +#include "action_aat_product.hh" +//#include "action_lu_solve.hh" +#include "timers/mixed_perf_analyzer.hh" + +int main() +{ + + bench<Action_matrix_vector_product<C_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + bench<Action_matrix_matrix_product<C_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_aat_product<C_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_ata_product<C_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_axpy<C_interface<REAL_TYPE> > >(MIN_AXPY,MAX_AXPY,NB_POINT); + + + return 0; +} + + diff --git a/bench/btl/libs/C_BLAS/CMakeLists.txt b/bench/btl/libs/C_BLAS/CMakeLists.txt new file mode 100644 index 000000000..9654bf8ad --- /dev/null +++ b/bench/btl/libs/C_BLAS/CMakeLists.txt @@ -0,0 +1,4 @@ + +include_directories(${CBLAS_INCLUDES} ${PROJECT_SOURCE_DIR}/libs/f77) +btl_add_bench(btl_cblas main.cpp) +target_link_libraries(btl_cblas ${CBLAS_LIBRARIES}) diff --git a/bench/btl/libs/C_BLAS/C_BLAS_interface.hh b/bench/btl/libs/C_BLAS/C_BLAS_interface.hh new file mode 100644 index 000000000..e637c0e5e --- /dev/null +++ b/bench/btl/libs/C_BLAS/C_BLAS_interface.hh @@ -0,0 +1,131 @@ +//===================================================== +// File : C_BLAS_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:28 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef C_BLAS_PRODUIT_MATRICE_VECTEUR_HH +#define C_BLAS_PRODUIT_MATRICE_VECTEUR_HH + +#include "f77_interface.hh" + +extern "C" +{ +#include "cblas.h" +} + +template<class real> +class C_BLAS_interface : public f77_interface_base<real> +{ +public : + + typedef typename f77_interface_base<real>::gene_matrix gene_matrix; + typedef typename f77_interface_base<real>::gene_vector gene_vector; + + static inline std::string name( void ) + { + return "C_BLAS"; + } + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) + { + cblas_dgemv(CblasColMajor,CblasNoTrans,N,N,1.0,A,N,B,1,0.0,X,1); + } + + static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) + { + cblas_dgemv(CblasColMajor,CblasTrans,N,N,1.0,A,N,B,1,0.0,X,1); + } + + static inline void matrix_matrix_product(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N) + { + cblas_dgemm(CblasColMajor,CblasNoTrans,CblasNoTrans,N,N,N,1.0,A,N,B,N,0.0,X,N); + } + + static inline void transposed_matrix_matrix_product(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N) + { + cblas_dgemm(CblasColMajor,CblasTrans,CblasTrans,N,N,N,1.0,A,N,B,N,0.0,X,N); + } + + static inline void ata_product(gene_matrix & A, gene_matrix & X, int N) + { + cblas_dgemm(CblasColMajor,CblasTrans,CblasNoTrans,N,N,N,1.0,A,N,A,N,0.0,X,N); + } + + static inline void aat_product(gene_matrix & A, gene_matrix & X, int N) + { + cblas_dgemm(CblasColMajor,CblasNoTrans,CblasTrans,N,N,N,1.0,A,N,A,N,0.0,X,N); + } + + static inline void axpy(real coef, const gene_vector & X, gene_vector & Y, int N) + { + cblas_daxpy(N,coef,X,1,Y,1); + } + +}; + +template<> +class C_BLAS_interface<float> : public f77_interface_base<float> +{ +public : + + static inline std::string name( void ) + { + return "C_BLAS"; + } + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) + { + cblas_sgemv(CblasColMajor,CblasNoTrans,N,N,1.0,A,N,B,1,0.0,X,1); + } + + static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) + { + cblas_sgemv(CblasColMajor,CblasTrans,N,N,1.0,A,N,B,1,0.0,X,1); + } + + static inline void matrix_matrix_product(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N) + { + cblas_sgemm(CblasColMajor,CblasNoTrans,CblasNoTrans,N,N,N,1.0,A,N,B,N,0.0,X,N); + } + + static inline void transposed_matrix_matrix_product(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N) + { + cblas_sgemm(CblasColMajor,CblasNoTrans,CblasNoTrans,N,N,N,1.0,A,N,B,N,0.0,X,N); + } + + static inline void ata_product(gene_matrix & A, gene_matrix & X, int N) + { + cblas_sgemm(CblasColMajor,CblasTrans,CblasNoTrans,N,N,N,1.0,A,N,A,N,0.0,X,N); + } + + static inline void aat_product(gene_matrix & A, gene_matrix & X, int N) + { + cblas_sgemm(CblasColMajor,CblasNoTrans,CblasTrans,N,N,N,1.0,A,N,A,N,0.0,X,N); + } + + static inline void axpy(float coef, const gene_vector & X, gene_vector & Y, int N) + { + cblas_saxpy(N,coef,X,1,Y,1); + } + +}; + + +#endif + + + diff --git a/bench/btl/libs/C_BLAS/main.cpp b/bench/btl/libs/C_BLAS/main.cpp new file mode 100644 index 000000000..d88effa29 --- /dev/null +++ b/bench/btl/libs/C_BLAS/main.cpp @@ -0,0 +1,49 @@ +//===================================================== +// File : main.cpp +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:28 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include "C_BLAS_interface.hh" +#include "bench.hh" +#include "action_matrix_vector_product.hh" +#include "action_matrix_matrix_product.hh" +#include "action_axpy.hh" +#include "action_lu_solve.hh" +#include "action_ata_product.hh" +#include "action_aat_product.hh" + + +int main() +{ + + bench<Action_axpy<C_BLAS_interface<REAL_TYPE> > >(MIN_AXPY,MAX_AXPY,NB_POINT); + + bench<Action_matrix_vector_product<C_BLAS_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + + bench<Action_matrix_matrix_product<C_BLAS_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + bench<Action_ata_product<C_BLAS_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + bench<Action_aat_product<C_BLAS_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + //bench<Action_lu_solve<C_BLAS_LU_solve_interface<REAL_TYPE> > >(MIN_LU,MAX_LU,NB_POINT); + + return 0; +} + + diff --git a/bench/btl/libs/INTEL_BLAS/INTEL_BLAS_LU_solve_interface.hh b/bench/btl/libs/INTEL_BLAS/INTEL_BLAS_LU_solve_interface.hh new file mode 100644 index 000000000..616ab4720 --- /dev/null +++ b/bench/btl/libs/INTEL_BLAS/INTEL_BLAS_LU_solve_interface.hh @@ -0,0 +1,127 @@ +//===================================================== +// File : INTEL_BLAS_LU_solve_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:29 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef INTEL_BLAS_LU_solve_interface_HH +#define INTEL_BLAS_LU_solve_interface_HH +#include "INTEL_BLAS_interface.hh" +extern "C" +{ +// void dgetrf_(int *M, int *N, double *A, int *LDA, int *IPIV, int *INFO); +// void dgetrs_(char *TRANS, int *N, int *NRHS, double *A, int *LDA, int *IPIV, double *B, int *LDB, int *INFO); +// void sgetrf_(int *M, int *N, float *A, int *LDA, int *IPIV, int *INFO); +// void sgetrs_(char *TRANS, int *N, int *NRHS, float *A, int *LDA, int *IPIV, double *B, int *LDB, int *INFO); +#include "mkl_lapack.h" + +} + +template<class real> +class INTEL_BLAS_LU_solve_interface : public INTEL_BLAS_interface<real> +{ +public : + + typedef typename INTEL_BLAS_interface<real>::gene_matrix gene_matrix; + typedef typename INTEL_BLAS_interface<real>::gene_vector gene_vector; + + typedef int * Pivot_Vector; + + inline static void new_Pivot_Vector(Pivot_Vector & pivot, int N) + { + + pivot = new int[N]; + + } + + inline static void free_Pivot_Vector(Pivot_Vector & pivot) + { + + delete pivot; + + } + + + inline static void LU_factor(gene_matrix & LU, Pivot_Vector & pivot, int N) + { + + int info; + DGETRF(&N,&N,LU,&N,pivot,&info); + + } + + inline static void LU_solve(const gene_matrix & LU, const Pivot_Vector pivot, const gene_vector &B, gene_vector X, int N) + { + int info; + int one=1; + + char * transpose="N"; + + copy_vector(B,X,N); + DGETRS(transpose,&N,&one,LU,&N,pivot,X,&N,&info); + + } + +}; + +template<> +class INTEL_BLAS_LU_solve_interface<float> : public INTEL_BLAS_interface<float> +{ +public : + + typedef int * Pivot_Vector; + + inline static void new_Pivot_Vector(Pivot_Vector & pivot, int N) + { + + pivot = new int[N]; + + } + + inline static void free_Pivot_Vector(Pivot_Vector & pivot) + { + + delete pivot; + + } + + + inline static void LU_factor(gene_matrix & LU, Pivot_Vector & pivot, int N) + { + + int info; + SGETRF(&N,&N,LU,&N,pivot,&info); + + } + + inline static void LU_solve(const gene_matrix & LU, const Pivot_Vector pivot, const gene_vector &B, gene_vector X, int N) + { + + char * transpose="N"; + int info; + int one=1; + copy_vector(B,X,N); + SGETRS(transpose,&N,&one,LU,&N,pivot,X,&N,&info); + + } + +}; + + +#endif + + + diff --git a/bench/btl/libs/INTEL_BLAS/INTEL_BLAS_interface.hh b/bench/btl/libs/INTEL_BLAS/INTEL_BLAS_interface.hh new file mode 100644 index 000000000..778aaf8b1 --- /dev/null +++ b/bench/btl/libs/INTEL_BLAS/INTEL_BLAS_interface.hh @@ -0,0 +1,95 @@ +//===================================================== +// File : INTEL_BLAS_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:29 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef INTEL_BLAS_PRODUIT_MATRICE_VECTEUR_HH +#define INTEL_BLAS_PRODUIT_MATRICE_VECTEUR_HH +#include "f77_interface.hh" +extern "C" +{ +#include "mkl_cblas.h" +} + +template<class real> +class INTEL_BLAS_interface : public f77_interface_base<real> +{ +public : + + typedef typename f77_interface_base<real>::gene_matrix gene_matrix; + typedef typename f77_interface_base<real>::gene_vector gene_vector; + + static inline std::string name( void ) { return "INTEL_BLAS"; } + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) { + cblas_dgemv(CblasColMajor,CblasNoTrans,N,N,1.0,A,N,B,1,0.0,X,1); + } + + static inline void matrix_matrix_product(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N) { + cblas_dgemm(CblasColMajor,CblasNoTrans,CblasNoTrans,N,N,N,1.0,A,N,B,N,0.0,X,N); + } + + static inline void ata_product(gene_matrix & A, gene_matrix & X, int N) { + cblas_dgemm(CblasColMajor,CblasTrans,CblasNoTrans,N,N,N,1.0,A,N,A,N,0.0,X,N); + } + + static inline void aat_product(gene_matrix & A, gene_matrix & X, int N) { + cblas_dgemm(CblasColMajor,CblasNoTrans,CblasTrans,N,N,N,1.0,A,N,A,N,0.0,X,N); + } + + static inline void axpy(real coef, const gene_vector & X, gene_vector & Y, int N) { + cblas_daxpy(N,coef,X,1,Y,1); + } + +}; + +template<> +class INTEL_BLAS_interface<float> : public f77_interface_base<float> +{ +public : + + static inline std::string name() { return "INTEL_BLAS"; } + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) { + // cblas_sgemv(CblasNoTrans,N,N,1.0,A,N,B,1,0.0,X,1); + cblas_sgemv(CblasColMajor,CblasNoTrans,N,N,1.0,A,N,B,1,0.0,X,1); + + } + + static inline void matrix_matrix_product(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N) { + cblas_sgemm(CblasColMajor,CblasNoTrans,CblasNoTrans,N,N,N,1.0,A,N,B,N,0.0,X,N); + } + + static inline void ata_product(gene_matrix & A, gene_matrix & X, int N) { + cblas_sgemm(CblasColMajor,CblasTrans,CblasNoTrans,N,N,N,1.0,A,N,A,N,0.0,X,N); + } + + static inline void aat_product(gene_matrix & A, gene_matrix & X, int N) { + cblas_sgemm(CblasColMajor,CblasNoTrans,CblasTrans,N,N,N,1.0,A,N,A,N,0.0,X,N); + } + + static inline void axpy(float coef, const gene_vector & X, gene_vector & Y, int N) { + cblas_saxpy(N,coef,X,1,Y,1); + } + +}; + + +#endif + + + diff --git a/bench/btl/libs/INTEL_BLAS/config.sh b/bench/btl/libs/INTEL_BLAS/config.sh new file mode 100755 index 000000000..0ba48fe90 --- /dev/null +++ b/bench/btl/libs/INTEL_BLAS/config.sh @@ -0,0 +1,2 @@ +#! /bin/bash +export LD_LIBRARY_PATH=/opt/intel/mkl/lib/32:${LD_LIBRARY_PATH} diff --git a/bench/btl/libs/INTEL_BLAS/main.cpp b/bench/btl/libs/INTEL_BLAS/main.cpp new file mode 100644 index 000000000..b91d93470 --- /dev/null +++ b/bench/btl/libs/INTEL_BLAS/main.cpp @@ -0,0 +1,49 @@ +//===================================================== +// File : main.cpp +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:29 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include "INTEL_BLAS_interface.hh" +#include "INTEL_BLAS_LU_solve_interface.hh" +#include "bench.hh" +#include "action_matrix_vector_product.hh" +#include "action_matrix_matrix_product.hh" +#include "action_axpy.hh" +#include "action_lu_solve.hh" +#include "action_ata_product.hh" +#include "action_aat_product.hh" + +int main() +{ + + bench<Action_axpy<INTEL_BLAS_interface<REAL_TYPE> > >(MIN_AXPY,MAX_AXPY,NB_POINT); + + bench<Action_matrix_vector_product<INTEL_BLAS_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + + bench<Action_matrix_matrix_product<INTEL_BLAS_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + bench<Action_ata_product<INTEL_BLAS_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + bench<Action_aat_product<INTEL_BLAS_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + +// bench<Action_lu_solve<INTEL_BLAS_LU_solve_interface<REAL_TYPE> > >(MIN_LU,MAX_LU,NB_POINT); + + return 0; +} + + diff --git a/bench/btl/libs/STL/CMakeLists.txt b/bench/btl/libs/STL/CMakeLists.txt new file mode 100644 index 000000000..2897298d1 --- /dev/null +++ b/bench/btl/libs/STL/CMakeLists.txt @@ -0,0 +1,2 @@ + +btl_add_bench(btl_STL main.cpp) diff --git a/bench/btl/libs/STL/STL_interface.hh b/bench/btl/libs/STL/STL_interface.hh new file mode 100644 index 000000000..5b1a384af --- /dev/null +++ b/bench/btl/libs/STL/STL_interface.hh @@ -0,0 +1,190 @@ +//===================================================== +// File : STL_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:24 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef STL_INTERFACE_HH +#define STL_INTERFACE_HH +#include <string> +#include <vector> +#include "utilities.h" + +using namespace std; + +template<class real> +class STL_interface{ + +public : + + typedef real real_type ; + + typedef std::vector<real> stl_vector; + typedef std::vector<stl_vector > stl_matrix; + + typedef stl_matrix gene_matrix; + + typedef stl_vector gene_vector; + + static inline std::string name( void ) + { + return "STL"; + } + + static void free_matrix(gene_matrix & A, int N){} + + static void free_vector(gene_vector & B){} + + static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){ + A = A_stl; + } + + static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){ + B = B_stl; + } + + static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){ + B_stl = B ; + } + + + static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){ + A_stl = A ; + } + + static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){ + for (int i=0;i<N;i++){ + cible[i]=source[i]; + } + } + + + static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){ + for (int i=0;i<N;i++) + for (int j=0;j<N;j++) + cible[i][j]=source[i][j]; + } + + static inline void ata_product(const gene_matrix & A, gene_matrix & X, int N) + { + real somme; + for (int j=0;j<N;j++){ + for (int i=0;i<N;i++){ + somme=0.0; + for (int k=0;k<N;k++) + somme += A[i][k]*A[j][k]; + X[j][i]=somme; + } + } + } + + static inline void aat_product(const gene_matrix & A, gene_matrix & X, int N) + { + real somme; + for (int j=0;j<N;j++){ + for (int i=0;i<N;i++){ + somme=0.0; + for (int k=0;k<N;k++){ + somme+=A[k][i]*A[k][j]; + } + X[j][i]=somme; + } + } + } + + + static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N) + { + real somme; + for (int j=0;j<N;j++){ + for (int i=0;i<N;i++){ + somme=0.0; + for (int k=0;k<N;k++) + somme+=A[k][i]*B[j][k]; + X[j][i]=somme; + } + } + } + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) + { + real somme; + for (int i=0;i<N;i++){ + somme=0.0; + for (int j=0;j<N;j++) + somme+=A[j][i]*B[j]; + X[i]=somme; + } + } + + static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) + { + real somme; + for (int i=0;i<N;i++){ + somme = 0.0; + for (int j=0;j<N;j++) + somme += A[i][j]*B[j]; + X[i] = somme; + } + } + + static inline void axpy(real coef, const gene_vector & X, gene_vector & Y, int N){ + for (int i=0;i<N;i++) + Y[i]+=coef*X[i]; + } + + static inline real norm_diff(const stl_vector & A, const stl_vector & B) + { + int N=A.size(); + real somme=0.0; + real somme2=0.0; + + for (int i=0;i<N;i++){ + real diff=A[i]-B[i]; + somme+=diff*diff; + somme2+=A[i]*A[i]; + } + return somme/somme2; + } + + static inline real norm_diff(const stl_matrix & A, const stl_matrix & B) + { + int N=A[0].size(); + real somme=0.0; + real somme2=0.0; + + for (int i=0;i<N;i++){ + for (int j=0;j<N;j++){ + real diff=A[i][j] - B[i][j]; + somme += diff*diff; + somme2 += A[i][j]*A[i][j]; + } + } + + return somme/somme2; + } + + static inline void display_vector(const stl_vector & A) + { + int N=A.size(); + for (int i=0;i<N;i++){ + INFOS("A["<<i<<"]="<<A[i]<<endl); + } + } + +}; + +#endif diff --git a/bench/btl/libs/STL/main.cpp b/bench/btl/libs/STL/main.cpp new file mode 100644 index 000000000..dc2044320 --- /dev/null +++ b/bench/btl/libs/STL/main.cpp @@ -0,0 +1,43 @@ +//===================================================== +// File : main.cpp +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:23 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include "STL_interface.hh" +#include "bench.hh" +#include "action_matrix_vector_product.hh" +#include "action_matrix_matrix_product.hh" +#include "action_axpy.hh" +#include "action_lu_solve.hh" +#include "action_ata_product.hh" +#include "action_aat_product.hh" +#include "action_atv_product.hh" + +int main() +{ + bench<Action_axpy<STL_interface<REAL_TYPE> > >(MIN_AXPY,MAX_AXPY,NB_POINT); + bench<Action_matrix_vector_product<STL_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + bench<Action_atv_product<STL_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + bench<Action_matrix_matrix_product<STL_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_ata_product<STL_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_aat_product<STL_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + return 0; +} + + diff --git a/bench/btl/libs/STL_algo/CMakeLists.txt b/bench/btl/libs/STL_algo/CMakeLists.txt new file mode 100644 index 000000000..e4387aba8 --- /dev/null +++ b/bench/btl/libs/STL_algo/CMakeLists.txt @@ -0,0 +1,2 @@ + +btl_add_bench(btl_STL_algo main.cpp) diff --git a/bench/btl/libs/STL_algo/STL_algo_interface.hh b/bench/btl/libs/STL_algo/STL_algo_interface.hh new file mode 100644 index 000000000..8854479a6 --- /dev/null +++ b/bench/btl/libs/STL_algo/STL_algo_interface.hh @@ -0,0 +1,138 @@ +//===================================================== +// File : STL_algo_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:24 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef STL_ALGO_INTERFACE_HH +#define STL_ALGO_INTERFACE_HH +#include <string> +#include <vector> +#include <numeric> +#include <algorithm> +#include "utilities.h" + + +template<class real> +class STL_algo_interface{ + +public : + + typedef real real_type ; + + typedef std::vector<real> stl_vector; + typedef std::vector<stl_vector > stl_matrix; + + typedef stl_matrix gene_matrix; + + typedef stl_vector gene_vector; + + static inline std::string name( void ) + { + return "STL_algo"; + } + + static void free_matrix(gene_matrix & A, int N){} + + static void free_vector(gene_vector & B){} + + static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){ + A=A_stl ; + } + + static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){ + B=B_stl ; + } + + static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){ + B_stl=B ; + } + + static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){ + A_stl=A ; + } + + static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){ + for (int i=0;i<N;i++) + cible[i]=source[i]; + } + + static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N) + { + for (int i=0;i<N;i++){ + for (int j=0;j<N;j++){ + cible[i][j]=source[i][j]; + } + } + } + + class somme { + public: + + somme(real coef):_coef(coef){}; + + real operator()(const real & val1, const real & val2) + { + return _coef * val1 + val2; + } + + private: + + real _coef; + + }; + + + class vector_generator { + public: + + vector_generator(const gene_matrix & a_matrix, const gene_vector & a_vector): + _matrice(a_matrix), + _vecteur(a_vector), + _index(0) + {}; + real operator()( void ) + { + + const gene_vector & ai=_matrice[_index]; + int N=ai.size(); + + _index++; + + return std::inner_product(&ai[0],&ai[N],&_vecteur[0],0.0); + } + + private: + + int _index; + const gene_matrix & _matrice; + const gene_vector & _vecteur; + + }; + + static inline void atv_product(const gene_matrix & A, const gene_vector & B, gene_vector & X, int N) + { + std::generate(&X[0],&X[N],vector_generator(A,B)); + } + + static inline void axpy(real coef, const gene_vector & X, gene_vector & Y, int N) + { + std::transform(&X[0],&X[N],&Y[0],&Y[0],somme(coef)); + } + +}; + +#endif diff --git a/bench/btl/libs/STL_algo/main.cpp b/bench/btl/libs/STL_algo/main.cpp new file mode 100644 index 000000000..8c8b60781 --- /dev/null +++ b/bench/btl/libs/STL_algo/main.cpp @@ -0,0 +1,37 @@ +//===================================================== +// File : main.cpp +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:23 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include "STL_algo_interface.hh" +#include "bench.hh" +#include "action_atv_product.hh" +#include "action_axpy.hh" + +int main() +{ + + + bench<Action_atv_product<STL_algo_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + + bench<Action_axpy<STL_algo_interface<REAL_TYPE> > >(MIN_AXPY,MAX_AXPY,NB_POINT); + + return 0; +} + + diff --git a/bench/btl/libs/blitz/CMakeLists.txt b/bench/btl/libs/blitz/CMakeLists.txt new file mode 100644 index 000000000..1cb71c36d --- /dev/null +++ b/bench/btl/libs/blitz/CMakeLists.txt @@ -0,0 +1,4 @@ + +include_directories(${BLITZ_INCLUDES}) +btl_add_bench(btl_blitz main.cpp) +target_link_libraries(btl_blitz ${BLITZ_LIBRARIES}) diff --git a/bench/btl/libs/blitz/blitz_LU_solve_interface.hh b/bench/btl/libs/blitz/blitz_LU_solve_interface.hh new file mode 100644 index 000000000..dcb9f567f --- /dev/null +++ b/bench/btl/libs/blitz/blitz_LU_solve_interface.hh @@ -0,0 +1,192 @@ +//===================================================== +// File : blitz_LU_solve_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:31 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef BLITZ_LU_SOLVE_INTERFACE_HH +#define BLITZ_LU_SOLVE_INTERFACE_HH + +#include "blitz/array.h" +#include <vector> + +BZ_USING_NAMESPACE(blitz) + +template<class real> +class blitz_LU_solve_interface : public blitz_interface<real> +{ + +public : + + typedef typename blitz_interface<real>::gene_matrix gene_matrix; + typedef typename blitz_interface<real>::gene_vector gene_vector; + + typedef blitz::Array<int,1> Pivot_Vector; + + inline static void new_Pivot_Vector(Pivot_Vector & pivot,int N) + { + + pivot.resize(N); + + } + + inline static void free_Pivot_Vector(Pivot_Vector & pivot) + { + + return; + + } + + + static inline real matrix_vector_product_sliced(const gene_matrix & A, gene_vector B, int row, int col_start, int col_end) + { + + real somme=0.; + + for (int j=col_start ; j<col_end+1 ; j++){ + + somme+=A(row,j)*B(j); + + } + + return somme; + + } + + + + + static inline real matrix_matrix_product_sliced(gene_matrix & A, int row, int col_start, int col_end, gene_matrix & B, int row_shift, int col ) + { + + real somme=0.; + + for (int j=col_start ; j<col_end+1 ; j++){ + + somme+=A(row,j)*B(j+row_shift,col); + + } + + return somme; + + } + + inline static void LU_factor(gene_matrix & LU, Pivot_Vector & pivot, int N) + { + + ASSERT( LU.rows()==LU.cols() ) ; + int index_max = 0 ; + real big = 0. ; + real theSum = 0. ; + real dum = 0. ; + // Get the implicit scaling information : + gene_vector ImplicitScaling( N ) ; + for( int i=0; i<N; i++ ) { + big = 0. ; + for( int j=0; j<N; j++ ) { + if( abs( LU( i, j ) )>=big ) big = abs( LU( i, j ) ) ; + } + if( big==0. ) { + INFOS( "blitz_LU_factor::Singular matrix" ) ; + exit( 0 ) ; + } + ImplicitScaling( i ) = 1./big ; + } + // Loop over columns of Crout's method : + for( int j=0; j<N; j++ ) { + for( int i=0; i<j; i++ ) { + theSum = LU( i, j ) ; + theSum -= matrix_matrix_product_sliced(LU, i, 0, i-1, LU, 0, j) ; + // theSum -= sum( LU( i, Range( fromStart, i-1 ) )*LU( Range( fromStart, i-1 ), j ) ) ; + LU( i, j ) = theSum ; + } + + // Search for the largest pivot element : + big = 0. ; + for( int i=j; i<N; i++ ) { + theSum = LU( i, j ) ; + theSum -= matrix_matrix_product_sliced(LU, i, 0, j-1, LU, 0, j) ; + // theSum -= sum( LU( i, Range( fromStart, j-1 ) )*LU( Range( fromStart, j-1 ), j ) ) ; + LU( i, j ) = theSum ; + if( (ImplicitScaling( i )*abs( theSum ))>=big ) { + dum = ImplicitScaling( i )*abs( theSum ) ; + big = dum ; + index_max = i ; + } + } + // Interchanging rows and the scale factor : + if( j!=index_max ) { + for( int k=0; k<N; k++ ) { + dum = LU( index_max, k ) ; + LU( index_max, k ) = LU( j, k ) ; + LU( j, k ) = dum ; + } + ImplicitScaling( index_max ) = ImplicitScaling( j ) ; + } + pivot( j ) = index_max ; + if ( LU( j, j )==0. ) LU( j, j ) = 1.e-20 ; + // Divide by the pivot element : + if( j<N ) { + dum = 1./LU( j, j ) ; + for( int i=j+1; i<N; i++ ) LU( i, j ) *= dum ; + } + } + + } + + inline static void LU_solve(const gene_matrix & LU, const Pivot_Vector pivot, gene_vector &B, gene_vector X, int N) + { + + // Pour conserver le meme header, on travaille sur X, copie du second-membre B + X = B.copy() ; + ASSERT( LU.rows()==LU.cols() ) ; + firstIndex indI ; + // Forward substitution : + int ii = 0 ; + real theSum = 0. ; + for( int i=0; i<N; i++ ) { + int ip = pivot( i ) ; + theSum = X( ip ) ; + // theSum = B( ip ) ; + X( ip ) = X( i ) ; + // B( ip ) = B( i ) ; + if( ii ) { + theSum -= matrix_vector_product_sliced(LU, X, i, ii-1, i-1) ; + // theSum -= sum( LU( i, Range( ii-1, i-1 ) )*X( Range( ii-1, i-1 ) ) ) ; + // theSum -= sum( LU( i, Range( ii-1, i-1 ) )*B( Range( ii-1, i-1 ) ) ) ; + } else if( theSum ) { + ii = i+1 ; + } + X( i ) = theSum ; + // B( i ) = theSum ; + } + // Backsubstitution : + for( int i=N-1; i>=0; i-- ) { + theSum = X( i ) ; + // theSum = B( i ) ; + theSum -= matrix_vector_product_sliced(LU, X, i, i+1, N) ; + // theSum -= sum( LU( i, Range( i+1, toEnd ) )*X( Range( i+1, toEnd ) ) ) ; + // theSum -= sum( LU( i, Range( i+1, toEnd ) )*B( Range( i+1, toEnd ) ) ) ; + // Store a component of the solution vector : + X( i ) = theSum/LU( i, i ) ; + // B( i ) = theSum/LU( i, i ) ; + } + + } + +}; + +#endif diff --git a/bench/btl/libs/blitz/blitz_interface.hh b/bench/btl/libs/blitz/blitz_interface.hh new file mode 100644 index 000000000..0ba73fc0d --- /dev/null +++ b/bench/btl/libs/blitz/blitz_interface.hh @@ -0,0 +1,147 @@ +//===================================================== +// File : blitz_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:30 CEST 2002 +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef BLITZ_INTERFACE_HH +#define BLITZ_INTERFACE_HH + +#include <blitz/blitz.h> +#include <blitz/array.h> +#include <blitz/vector-et.h> +#include <blitz/vecwhere.h> +#include <blitz/matrix.h> +#include <vector> + +BZ_USING_NAMESPACE(blitz) + +template<class real> +class blitz_interface{ + +public : + + typedef real real_type ; + + typedef std::vector<real> stl_vector; + typedef std::vector<stl_vector > stl_matrix; + + typedef blitz::Array<real, 2> gene_matrix; + typedef blitz::Array<real, 1> gene_vector; +// typedef blitz::Matrix<real, blitz::ColumnMajor> gene_matrix; +// typedef blitz::Vector<real> gene_vector; + + static inline std::string name() { return "blitz"; } + + static void free_matrix(gene_matrix & A, int N){} + + static void free_vector(gene_vector & B){} + + static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){ + A.resize(A_stl[0].size(),A_stl.size()); + for (int j=0; j<A_stl.size() ; j++){ + for (int i=0; i<A_stl[j].size() ; i++){ + A(i,j)=A_stl[j][i]; + } + } + } + + static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){ + B.resize(B_stl.size()); + for (int i=0; i<B_stl.size() ; i++){ + B(i)=B_stl[i]; + } + } + + static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){ + for (int i=0; i<B_stl.size() ; i++){ + B_stl[i]=B(i); + } + } + + static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){ + int N=A_stl.size(); + for (int j=0;j<N;j++){ + A_stl[j].resize(N); + for (int i=0;i<N;i++) + A_stl[j][i] = A(i,j); + } + } + + static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N) + { + firstIndex i; + secondIndex j; + thirdIndex k; + X = sum(A(i,k) * B(k,j), k); + } + + static inline void ata_product(const gene_matrix & A, gene_matrix & X, int N) + { + firstIndex i; + secondIndex j; + thirdIndex k; + X = sum(A(k,i) * A(k,j), k); + } + + static inline void aat_product(const gene_matrix & A, gene_matrix & X, int N) + { + firstIndex i; + secondIndex j; + thirdIndex k; + X = sum(A(i,k) * A(j,k), k); + } + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) + { + firstIndex i; + secondIndex j; + X = sum(A(i,j)*B(j),j); + } + + static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) + { + firstIndex i; + secondIndex j; + X = sum(A(j,i) * B(j),j); + } + + static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N) + { + firstIndex i; + Y = Y(i) + coef * X(i); + //Y += coef * X; + } + + static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){ + cible = source; + //cible.template operator=<gene_matrix>(source); +// for (int i=0;i<N;i++){ +// for (int j=0;j<N;j++){ +// cible(i,j)=source(i,j); +// } +// } + } + + static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){ + //cible.template operator=<gene_vector>(source); + cible = source; + } + +}; + +#endif diff --git a/bench/btl/libs/blitz/main.cpp b/bench/btl/libs/blitz/main.cpp new file mode 100644 index 000000000..65fbb6b11 --- /dev/null +++ b/bench/btl/libs/blitz/main.cpp @@ -0,0 +1,49 @@ +//===================================================== +// File : main.cpp +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:30 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include "blitz_interface.hh" +#include "blitz_LU_solve_interface.hh" +#include "bench.hh" +#include "action_matrix_vector_product.hh" +#include "action_matrix_matrix_product.hh" +#include "action_axpy.hh" +#include "action_lu_solve.hh" +#include "action_ata_product.hh" +#include "action_aat_product.hh" +#include "action_atv_product.hh" + +int main() +{ + + bench<Action_matrix_vector_product<blitz_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + bench<Action_atv_product<blitz_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + + bench<Action_matrix_matrix_product<blitz_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_ata_product<blitz_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_aat_product<blitz_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + bench<Action_axpy<blitz_interface<REAL_TYPE> > >(MIN_AXPY,MAX_AXPY,NB_POINT); + + //bench<Action_lu_solve<blitz_LU_solve_interface<REAL_TYPE> > >(MIN_LU,MAX_LU,NB_POINT); + + return 0; +} + + diff --git a/bench/btl/libs/eigen2/CMakeLists.txt b/bench/btl/libs/eigen2/CMakeLists.txt new file mode 100644 index 000000000..6ac0ab24a --- /dev/null +++ b/bench/btl/libs/eigen2/CMakeLists.txt @@ -0,0 +1,8 @@ + +include_directories(${EIGEN2_INCLUDE_DIR}) +btl_add_bench(btl_eigen2 main.cpp) + +IF(NOT BTL_NOVEC) + btl_add_bench(btl_eigen2_novec main.cpp) + set_target_properties(btl_eigen2_novec PROPERTIES COMPILE_FLAGS "-DEIGEN_DONT_VECTORIZE") +ENDIF(NOT BTL_NOVEC) diff --git a/bench/btl/libs/eigen2/eigen2_LU_solve_interface.hh b/bench/btl/libs/eigen2/eigen2_LU_solve_interface.hh new file mode 100644 index 000000000..dcb9f567f --- /dev/null +++ b/bench/btl/libs/eigen2/eigen2_LU_solve_interface.hh @@ -0,0 +1,192 @@ +//===================================================== +// File : blitz_LU_solve_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:31 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef BLITZ_LU_SOLVE_INTERFACE_HH +#define BLITZ_LU_SOLVE_INTERFACE_HH + +#include "blitz/array.h" +#include <vector> + +BZ_USING_NAMESPACE(blitz) + +template<class real> +class blitz_LU_solve_interface : public blitz_interface<real> +{ + +public : + + typedef typename blitz_interface<real>::gene_matrix gene_matrix; + typedef typename blitz_interface<real>::gene_vector gene_vector; + + typedef blitz::Array<int,1> Pivot_Vector; + + inline static void new_Pivot_Vector(Pivot_Vector & pivot,int N) + { + + pivot.resize(N); + + } + + inline static void free_Pivot_Vector(Pivot_Vector & pivot) + { + + return; + + } + + + static inline real matrix_vector_product_sliced(const gene_matrix & A, gene_vector B, int row, int col_start, int col_end) + { + + real somme=0.; + + for (int j=col_start ; j<col_end+1 ; j++){ + + somme+=A(row,j)*B(j); + + } + + return somme; + + } + + + + + static inline real matrix_matrix_product_sliced(gene_matrix & A, int row, int col_start, int col_end, gene_matrix & B, int row_shift, int col ) + { + + real somme=0.; + + for (int j=col_start ; j<col_end+1 ; j++){ + + somme+=A(row,j)*B(j+row_shift,col); + + } + + return somme; + + } + + inline static void LU_factor(gene_matrix & LU, Pivot_Vector & pivot, int N) + { + + ASSERT( LU.rows()==LU.cols() ) ; + int index_max = 0 ; + real big = 0. ; + real theSum = 0. ; + real dum = 0. ; + // Get the implicit scaling information : + gene_vector ImplicitScaling( N ) ; + for( int i=0; i<N; i++ ) { + big = 0. ; + for( int j=0; j<N; j++ ) { + if( abs( LU( i, j ) )>=big ) big = abs( LU( i, j ) ) ; + } + if( big==0. ) { + INFOS( "blitz_LU_factor::Singular matrix" ) ; + exit( 0 ) ; + } + ImplicitScaling( i ) = 1./big ; + } + // Loop over columns of Crout's method : + for( int j=0; j<N; j++ ) { + for( int i=0; i<j; i++ ) { + theSum = LU( i, j ) ; + theSum -= matrix_matrix_product_sliced(LU, i, 0, i-1, LU, 0, j) ; + // theSum -= sum( LU( i, Range( fromStart, i-1 ) )*LU( Range( fromStart, i-1 ), j ) ) ; + LU( i, j ) = theSum ; + } + + // Search for the largest pivot element : + big = 0. ; + for( int i=j; i<N; i++ ) { + theSum = LU( i, j ) ; + theSum -= matrix_matrix_product_sliced(LU, i, 0, j-1, LU, 0, j) ; + // theSum -= sum( LU( i, Range( fromStart, j-1 ) )*LU( Range( fromStart, j-1 ), j ) ) ; + LU( i, j ) = theSum ; + if( (ImplicitScaling( i )*abs( theSum ))>=big ) { + dum = ImplicitScaling( i )*abs( theSum ) ; + big = dum ; + index_max = i ; + } + } + // Interchanging rows and the scale factor : + if( j!=index_max ) { + for( int k=0; k<N; k++ ) { + dum = LU( index_max, k ) ; + LU( index_max, k ) = LU( j, k ) ; + LU( j, k ) = dum ; + } + ImplicitScaling( index_max ) = ImplicitScaling( j ) ; + } + pivot( j ) = index_max ; + if ( LU( j, j )==0. ) LU( j, j ) = 1.e-20 ; + // Divide by the pivot element : + if( j<N ) { + dum = 1./LU( j, j ) ; + for( int i=j+1; i<N; i++ ) LU( i, j ) *= dum ; + } + } + + } + + inline static void LU_solve(const gene_matrix & LU, const Pivot_Vector pivot, gene_vector &B, gene_vector X, int N) + { + + // Pour conserver le meme header, on travaille sur X, copie du second-membre B + X = B.copy() ; + ASSERT( LU.rows()==LU.cols() ) ; + firstIndex indI ; + // Forward substitution : + int ii = 0 ; + real theSum = 0. ; + for( int i=0; i<N; i++ ) { + int ip = pivot( i ) ; + theSum = X( ip ) ; + // theSum = B( ip ) ; + X( ip ) = X( i ) ; + // B( ip ) = B( i ) ; + if( ii ) { + theSum -= matrix_vector_product_sliced(LU, X, i, ii-1, i-1) ; + // theSum -= sum( LU( i, Range( ii-1, i-1 ) )*X( Range( ii-1, i-1 ) ) ) ; + // theSum -= sum( LU( i, Range( ii-1, i-1 ) )*B( Range( ii-1, i-1 ) ) ) ; + } else if( theSum ) { + ii = i+1 ; + } + X( i ) = theSum ; + // B( i ) = theSum ; + } + // Backsubstitution : + for( int i=N-1; i>=0; i-- ) { + theSum = X( i ) ; + // theSum = B( i ) ; + theSum -= matrix_vector_product_sliced(LU, X, i, i+1, N) ; + // theSum -= sum( LU( i, Range( i+1, toEnd ) )*X( Range( i+1, toEnd ) ) ) ; + // theSum -= sum( LU( i, Range( i+1, toEnd ) )*B( Range( i+1, toEnd ) ) ) ; + // Store a component of the solution vector : + X( i ) = theSum/LU( i, i ) ; + // B( i ) = theSum/LU( i, i ) ; + } + + } + +}; + +#endif diff --git a/bench/btl/libs/eigen2/eigen2_interface.hh b/bench/btl/libs/eigen2/eigen2_interface.hh new file mode 100644 index 000000000..5d8ad9466 --- /dev/null +++ b/bench/btl/libs/eigen2/eigen2_interface.hh @@ -0,0 +1,128 @@ +//===================================================== +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef EIGEN2_INTERFACE_HH +#define EIGEN2_INTERFACE_HH + +#include <Eigen/Core> +#include <vector> + +using namespace Eigen; + +template<class real, int SIZE=Dynamic> +class eigen2_interface +{ + +public : + + typedef real real_type ; + + typedef std::vector<real> stl_vector; + typedef std::vector<stl_vector> stl_matrix; + + typedef Eigen::Matrix<real,SIZE,SIZE> gene_matrix; + typedef Eigen::Matrix<real,SIZE,1> gene_vector; + + static inline std::string name( void ) + { + #if defined(EIGEN_VECTORIZE_SSE) + if (SIZE==Dynamic) return "eigen2_SSE"; else return "tiny_eigen2_SSE"; + #elif defined(EIGEN_VECTORIZE_ALTIVEC) + if (SIZE==Dynamic) return "eigen2_AltiVec"; else return "tiny_eigen2_AltiVec"; + #else + if (SIZE==Dynamic) return "eigen2"; else return "tiny_eigen2"; + #endif + } + + static void free_matrix(gene_matrix & A, int N) {} + + static void free_vector(gene_vector & B) {} + + static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){ + A.resize(A_stl[0].size(), A_stl.size()); + + for (int j=0; j<A_stl.size() ; j++){ + for (int i=0; i<A_stl[j].size() ; i++){ + A.coeffRef(i,j) = A_stl[j][i]; + } + } + } + + static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){ + B.resize(B_stl.size(),1); + + for (int i=0; i<B_stl.size() ; i++){ + B.coeffRef(i) = B_stl[i]; + } + } + + static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){ + for (int i=0; i<B_stl.size() ; i++){ + B_stl[i] = B.coeff(i); + } + } + + static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){ + int N=A_stl.size(); + + for (int j=0;j<N;j++){ + A_stl[j].resize(N); + for (int i=0;i<N;i++){ + A_stl[j][i] = A.coeff(i,j); + } + } + } + + static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){ + X = (A*B).lazy(); + } + + static inline void transposed_matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){ + X = (A.transpose()*B.transpose()).lazy(); + } + + static inline void ata_product(const gene_matrix & A, gene_matrix & X, int N){ + X = (A.transpose()*A).lazy(); + } + + static inline void aat_product(const gene_matrix & A, gene_matrix & X, int N){ + X = (A*A.transpose()).lazy(); + } + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){ + X = (A*B).lazy(); + } + + static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){ + X = (A*B).lazy(); + } + + static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){ + Y += coef * X; + } + + static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){ + cible = source; + } + + static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){ + cible = source; + } + +}; + +#endif diff --git a/bench/btl/libs/eigen2/main.cpp b/bench/btl/libs/eigen2/main.cpp new file mode 100644 index 000000000..d73a80768 --- /dev/null +++ b/bench/btl/libs/eigen2/main.cpp @@ -0,0 +1,49 @@ +//===================================================== +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include "eigen2_interface.hh" +#include "bench.hh" +#include "static/bench_static.hh" +#include "action_matrix_vector_product.hh" +#include "action_matrix_matrix_product.hh" +#include "action_axpy.hh" +#include "action_lu_solve.hh" +#include "action_ata_product.hh" +#include "action_aat_product.hh" +#include "action_atv_product.hh" + +int main() +{ + + bench<Action_matrix_vector_product<eigen2_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + bench<Action_atv_product<eigen2_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + bench<Action_axpy<eigen2_interface<REAL_TYPE> > >(MIN_AXPY,MAX_AXPY,NB_POINT); + bench<Action_matrix_matrix_product<eigen2_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_ata_product<eigen2_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_aat_product<eigen2_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + //bench<Action_lu_solve<blitz_LU_solve_interface<REAL_TYPE> > >(MIN_LU,MAX_LU,NB_POINT); + + bench_static<Action_axpy,eigen2_interface>(); + bench_static<Action_matrix_matrix_product,eigen2_interface>(); + bench_static<Action_matrix_vector_product,eigen2_interface>(); + + return 0; +} + + diff --git a/bench/btl/libs/f77/CMakeLists.txt b/bench/btl/libs/f77/CMakeLists.txt new file mode 100644 index 000000000..03d0c6167 --- /dev/null +++ b/bench/btl/libs/f77/CMakeLists.txt @@ -0,0 +1,3 @@ + +enable_language(Fortran) +btl_add_bench(btl_f77 main.cpp dmxv.f smxv.f dmxm.f smxm.f daxpy.f saxpy.f data.f sata.f daat.f saat.f) diff --git a/bench/btl/libs/f77/daat.f b/bench/btl/libs/f77/daat.f new file mode 100644 index 000000000..a50329a66 --- /dev/null +++ b/bench/btl/libs/f77/daat.f @@ -0,0 +1,14 @@ + SUBROUTINE DAAT(A,X,N) +** +** X = AT * A + REAL*8 A(N,N),X(N,N),R + DO 20 I=1,N + DO 20 J=1,N + R=0. + DO 10 K=1,N + R=R+A(I,K)*A(J,K) + 10 CONTINUE + X(I,J)=R + 20 CONTINUE + RETURN + END diff --git a/bench/btl/libs/f77/data.f b/bench/btl/libs/f77/data.f new file mode 100644 index 000000000..709211ca5 --- /dev/null +++ b/bench/btl/libs/f77/data.f @@ -0,0 +1,14 @@ + SUBROUTINE DATA(A,X,N) +** +** X = AT * A + REAL*8 A(N,N),X(N,N),R + DO 20 I=1,N + DO 20 J=1,N + R=0. + DO 10 K=1,N + R=R+A(K,I)*A(K,J) + 10 CONTINUE + X(I,J)=R + 20 CONTINUE + RETURN + END diff --git a/bench/btl/libs/f77/daxpy.f b/bench/btl/libs/f77/daxpy.f new file mode 100644 index 000000000..94bb846de --- /dev/null +++ b/bench/btl/libs/f77/daxpy.f @@ -0,0 +1,18 @@ + SUBROUTINE DAXPY(N,A,X,Y) +** *************************************** +** CALCULE Y = Y + A*X +** *************************************** +*>N NOMBRE D'OPERATIONS A FAIRE +*>A CONSTANTE MULTIPLICATIVE +*>X TABLEAU +*=Y TABLEAU DES RESULTATS +*A R. SANCHEZ ( EARLY WINTER 1987 ) +*V M.F. ROBEAU + REAL*8 X(1),Y(1) + REAL*8 A + DO 10 I=1,N + Y(I)=Y(I)+A*X(I) + 10 CONTINUE + RETURN + END + diff --git a/bench/btl/libs/f77/dmxm.f b/bench/btl/libs/f77/dmxm.f new file mode 100644 index 000000000..eb7ef9006 --- /dev/null +++ b/bench/btl/libs/f77/dmxm.f @@ -0,0 +1,32 @@ + SUBROUTINE DMXM(A,N,B,M,C,L) +** +** C = A * B +** A ET B MATRICES A(N,M) B(M,L) ==> C(N,L) +** +*>A PREMIERE MATRICE +*>N PREMIERE DIMENSION DE A ET DE C +*>B DEUXIEME MATRICE +*>M DEUXIEME DIMENSION DE A ET PERMIERE DE B +*<C MATRICE PRODUIT DE A ET DE B +*>L DEUXIEME DIMENSION DE B ET DE C +*A R. SANCHEZ ( EARLY WINTER 1987 ) +*V M.F. ROBEAU +*M AM BAUDRON - AVRIL 94 +*: ERREUR DANS L'APPEL A L'UTILITAIRE SGEMM +*: APPEL A L'UTILITAIRE SGEMM DE LA LIBRAIRIE BLAS SUR HP +*M AM BAUDRON - NOVEMBRE 1991 +*: ERREUR ( SOMME SUR LES TERMES PAS FAITE ) +*: APPEL A L'UTILITAIRE SGEMM DE LA LIBRAIRIE BLAS SUR RISC +*M AM BAUDRON - MAI 1993 +*: CHANGEMENT DES %IF LOCAL SUN MIPS SUITE A INTRODUCTION VERSION IBM + REAL*8 A(N,M),B(M,L),C(N,L),R + DO 20 I=1,N + DO 20 J=1,L + R=0. + DO 10 K=1,M + R=R+A(I,K)*B(K,J) + 10 CONTINUE + C(I,J)=R + 20 CONTINUE + RETURN + END diff --git a/bench/btl/libs/f77/dmxm.f.mfr b/bench/btl/libs/f77/dmxm.f.mfr new file mode 100644 index 000000000..82ccac9a5 --- /dev/null +++ b/bench/btl/libs/f77/dmxm.f.mfr @@ -0,0 +1,36 @@ + + SUBROUTINE DMXM(A,N,B,M,C,L) +** +** C = A * B +** A ET B MATRICES A(N,M) B(M,L) ==> C(N,L) +** +*>A PREMIERE MATRICE +*>N PREMIERE DIMENSION DE A ET DE C +*>B DEUXIEME MATRICE +*>M DEUXIEME DIMENSION DE A ET PERMIERE DE B +*<C MATRICE PRODUIT DE A ET DE B +*>L DEUXIEME DIMENSION DE B ET DE C +*A R. SANCHEZ ( EARLY WINTER 1987 ) +*V M.F. ROBEAU +*M AM BAUDRON - AVRIL 94 +*: ERREUR DANS L'APPEL A L'UTILITAIRE SGEMM +*: APPEL A L'UTILITAIRE SGEMM DE LA LIBRAIRIE BLAS SUR HP +*M AM BAUDRON - NOVEMBRE 1991 +*: ERREUR ( SOMME SUR LES TERMES PAS FAITE ) +*: APPEL A L'UTILITAIRE SGEMM DE LA LIBRAIRIE BLAS SUR RISC +*M AM BAUDRON - MAI 1993 +*: CHANGEMENT DES %IF LOCAL SUN MIPS SUITE A INTRODUCTION VERSION IBM + REAL*8 A(N,M),B(M,L),C(N,L),R + DO 5 J=1,L + DO 5 I=1,N + C(I,J)=0. + 5 CONTINUE + DO 10 K=1,M + DO 20 J=1,L + R=B(K,J) + DO 20 I=1,N + C(I,J)=C(I,J)+A(I,K)*R + 20 CONTINUE + 10 CONTINUE + RETURN + END diff --git a/bench/btl/libs/f77/dmxv.f b/bench/btl/libs/f77/dmxv.f new file mode 100644 index 000000000..bd7e4d550 --- /dev/null +++ b/bench/btl/libs/f77/dmxv.f @@ -0,0 +1,39 @@ + SUBROUTINE DMXV(A,N,X,M,R) +C +** +** VERSION DOUBLE PRECISION DE MXV +** R = A * X +** A MATRICE A(N,M) +** R ET X VECTEURS +** +*>A PREMIERE MATRICE +*>N PREMIERE DIMENSION DE A +*>X VECTEUR +*>M DEUXIEME DIMENSION DE A +*<R VECTEUR PRODUIT DE A ET DE X +** +*A M. COSTE +*V M.F. ROBEAU +*M +* + REAL*8 X(1),R(1),A(N,M) + REAL*8 S +C DO 20 I=1,N +C S=0. +C DO 10 J=1,M +C S=S+A(I,J)*X(J) +C 10 CONTINUE +C R(I)=S +C 20 CONTINUE + DO 5 I=1,N + R(I)=0 + 5 CONTINUE + DO 10 J=1,M + S=X(J) + DO 20 I=1,N + R(I)=R(I)+A(I,J)*S + 20 CONTINUE + 10 CONTINUE + RETURN + END + diff --git a/bench/btl/libs/f77/f77_interface.hh b/bench/btl/libs/f77/f77_interface.hh new file mode 100644 index 000000000..0208b42c2 --- /dev/null +++ b/bench/btl/libs/f77/f77_interface.hh @@ -0,0 +1,145 @@ +//===================================================== +// File : f77_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:24 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef F77_INTERFACE_HH +#define F77_INTERFACE_HH +#include "f77_interface_base.hh" +#include <string> + +extern "C" +{ + void dmxv_(double * A, int * N, double * X, int * M, double *R); + void smxv_(float * A, int * N, float * X, int * M, float *R); + + void dmxm_(double * A, int * N, double * B, int * M, double *C, int * K); + void smxm_(float * A, int * N, float * B, int * M, float *C, int * K); + + void data_(double * A, double *X, int * N); + void sata_(float * A, float *X, int * N); + + void daat_(double * A, double *X, int * N); + void saat_(float * A, float *X, int * N); + + void saxpy_(int * N, float * coef, float * X, float *Y); + void daxpy_(int * N, double * coef, double * X, double *Y); +} + +template<class real> +class f77_interface : public f77_interface_base<real> +{ +public : + + typedef typename f77_interface_base<real>::gene_matrix gene_matrix; + typedef typename f77_interface_base<real>::gene_vector gene_vector; + + static inline std::string name( void ) + { + return "f77"; + } + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) + { + + dmxv_(A,&N,B,&N,X); + + } + + static inline void matrix_matrix_product(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N) + { + + dmxm_(A,&N,B,&N,X,&N); + + } + + static inline void ata_product(gene_matrix & A, gene_matrix & X, int N) + { + + data_(A,X,&N); + + } + + static inline void aat_product(gene_matrix & A, gene_matrix & X, int N) + { + + daat_(A,X,&N); + + } + + static inline void axpy(real coef, const gene_vector & X, gene_vector & Y, int N) + { + int one=1; + daxpy_(&N,&coef,X,Y); + } + + +}; + + +template<> +class f77_interface<float> : public f77_interface_base<float> +{ +public : + + static inline std::string name( void ) + { + return "F77"; + } + + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) + { + + smxv_(A,&N,B,&N,X); + + } + + static inline void matrix_matrix_product(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N) + { + + smxm_(A,&N,B,&N,X,&N); + + } + + static inline void ata_product(gene_matrix & A, gene_matrix & X, int N) + { + + sata_(A,X,&N); + + } + + static inline void aat_product(gene_matrix & A, gene_matrix & X, int N) + { + + saat_(A,X,&N); + + } + + + static inline void axpy(float coef, const gene_vector & X, gene_vector & Y, int N) + { + saxpy_(&N,&coef,X,Y); + } + +}; + + +#endif + + + diff --git a/bench/btl/libs/f77/f77_interface_base.hh b/bench/btl/libs/f77/f77_interface_base.hh new file mode 100644 index 000000000..ab8a18295 --- /dev/null +++ b/bench/btl/libs/f77/f77_interface_base.hh @@ -0,0 +1,91 @@ +//===================================================== +// File : f77_interface_base.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:25 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef F77_INTERFACE_BASE_HH +#define F77_INTERFACE_BASE_HH + +#include "utilities.h" +#include <vector> +template<class real> +class f77_interface_base{ + +public: + + typedef real real_type ; + typedef std::vector<real> stl_vector; + typedef std::vector<stl_vector > stl_matrix; + + typedef real * gene_matrix; + typedef real * gene_vector; + + static void free_matrix(gene_matrix & A, int N){ + delete A; + } + + static void free_vector(gene_vector & B){ + delete B; + } + + static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){ + int N = A_stl.size(); + A = new real[N*N]; + for (int j=0;j<N;j++) + for (int i=0;i<N;i++) + A[i+N*j] = A_stl[j][i]; + } + + static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){ + int N = B_stl.size(); + B = new real[N]; + for (int i=0;i<N;i++) + B[i] = B_stl[i]; + } + + static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){ + int N = B_stl.size(); + for (int i=0;i<N;i++) + B_stl[i] = B[i]; + } + + static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){ + int N = A_stl.size(); + for (int j=0;j<N;j++){ + A_stl[j].resize(N); + for (int i=0;i<N;i++) + A_stl[j][i] = A[i+N*j]; + } + } + + static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){ + for (int i=0;i<N;i++) + cible[i]=source[i]; + } + + static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){ + for (int j=0;j<N;j++){ + for (int i=0;i<N;i++){ + cible[i+N*j] = source[i+N*j]; + } + } + } + +}; + + +#endif diff --git a/bench/btl/libs/f77/main.cpp b/bench/btl/libs/f77/main.cpp new file mode 100644 index 000000000..17934fb25 --- /dev/null +++ b/bench/btl/libs/f77/main.cpp @@ -0,0 +1,46 @@ +//===================================================== +// File : main.cpp +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:25 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include "f77_interface.hh" +#include "bench.hh" +#include "action_matrix_vector_product.hh" +#include "action_matrix_matrix_product.hh" +#include "action_axpy.hh" +#include "action_lu_solve.hh" +#include "action_ata_product.hh" +#include "action_aat_product.hh" + + +int main() +{ + bench<Action_axpy<f77_interface<REAL_TYPE> > >(MIN_AXPY,MAX_AXPY,NB_POINT); + + bench<Action_matrix_vector_product<f77_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + + bench<Action_matrix_matrix_product<f77_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + bench<Action_ata_product<f77_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + bench<Action_aat_product<f77_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + return 0; +} + + diff --git a/bench/btl/libs/f77/saat.f b/bench/btl/libs/f77/saat.f new file mode 100644 index 000000000..5d1855d2c --- /dev/null +++ b/bench/btl/libs/f77/saat.f @@ -0,0 +1,14 @@ + SUBROUTINE SAAT(A,X,N) +** +** X = AT * A + REAL*4 A(N,N),X(N,N) + DO 20 I=1,N + DO 20 J=1,N + R=0. + DO 10 K=1,N + R=R+A(I,K)*A(J,K) + 10 CONTINUE + X(I,J)=R + 20 CONTINUE + RETURN + END diff --git a/bench/btl/libs/f77/sata.f b/bench/btl/libs/f77/sata.f new file mode 100644 index 000000000..3ab83d958 --- /dev/null +++ b/bench/btl/libs/f77/sata.f @@ -0,0 +1,14 @@ + SUBROUTINE SATA(A,X,N) +** +** X = AT * A + REAL*4 A(N,N),X(N,N) + DO 20 I=1,N + DO 20 J=1,N + R=0. + DO 10 K=1,N + R=R+A(K,I)*A(K,J) + 10 CONTINUE + X(I,J)=R + 20 CONTINUE + RETURN + END diff --git a/bench/btl/libs/f77/saxpy.f b/bench/btl/libs/f77/saxpy.f new file mode 100644 index 000000000..5eda4c2d2 --- /dev/null +++ b/bench/btl/libs/f77/saxpy.f @@ -0,0 +1,16 @@ + SUBROUTINE SAXPY(N,A,X,Y) +** *************************************** +** CALCULE Y = Y + A*X +** *************************************** +*>N NOMBRE D'OPERATIONS A FAIRE +*>A CONSTANTE MULTIPLICATIVE +*>X TABLEAU +*=Y TABLEAU DES RESULTATS +*A R. SANCHEZ ( EARLY WINTER 1987 ) +*V M.F. ROBEAU + DIMENSION X(1),Y(1) + DO 10 I=1,N + Y(I)=Y(I)+A*X(I) + 10 CONTINUE + RETURN + END diff --git a/bench/btl/libs/f77/smxm.f b/bench/btl/libs/f77/smxm.f new file mode 100644 index 000000000..a1e63adca --- /dev/null +++ b/bench/btl/libs/f77/smxm.f @@ -0,0 +1,32 @@ + SUBROUTINE SMXM(A,N,B,M,C,L) +** +** C = A * B +** A ET B MATRICES A(N,M) B(M,L) ==> C(N,L) +** +*>A PREMIERE MATRICE +*>N PREMIERE DIMENSION DE A ET DE C +*>B DEUXIEME MATRICE +*>M DEUXIEME DIMENSION DE A ET PERMIERE DE B +*<C MATRICE PRODUIT DE A ET DE B +*>L DEUXIEME DIMENSION DE B ET DE C +*A R. SANCHEZ ( EARLY WINTER 1987 ) +*V M.F. ROBEAU +*M AM BAUDRON - AVRIL 94 +*: ERREUR DANS L'APPEL A L'UTILITAIRE SGEMM +*: APPEL A L'UTILITAIRE SGEMM DE LA LIBRAIRIE BLAS SUR HP +*M AM BAUDRON - NOVEMBRE 1991 +*: ERREUR ( SOMME SUR LES TERMES PAS FAITE ) +*: APPEL A L'UTILITAIRE SGEMM DE LA LIBRAIRIE BLAS SUR RISC +*M AM BAUDRON - MAI 1993 +*: CHANGEMENT DES %IF LOCAL SUN MIPS SUITE A INTRODUCTION VERSION IBM + DIMENSION A(N,M),B(M,L),C(N,L) + DO 20 I=1,N + DO 20 J=1,L + R=0. + DO 10 K=1,M + R=R+A(I,K)*B(K,J) + 10 CONTINUE + C(I,J)=R + 20 CONTINUE + RETURN + END diff --git a/bench/btl/libs/f77/smxv.f b/bench/btl/libs/f77/smxv.f new file mode 100644 index 000000000..d2f7ed24e --- /dev/null +++ b/bench/btl/libs/f77/smxv.f @@ -0,0 +1,38 @@ + SUBROUTINE SMXV(A,N,X,M,R) +C +** +** VERSION DOUBLE PRECISION DE MXV +** R = A * X +** A MATRICE A(N,M) +** R ET X VECTEURS +** +*>A PREMIERE MATRICE +*>N PREMIERE DIMENSION DE A +*>X VECTEUR +*>M DEUXIEME DIMENSION DE A +*<R VECTEUR PRODUIT DE A ET DE X +** +*A M. COSTE +*V M.F. ROBEAU +*M +* + REAL*4 X(1),R(1),A(N,M) + REAL*4 S +C DO 20 I=1,N +C S=0. +C DO 10 J=1,M +C S=S+A(I,J)*X(J) +C 10 CONTINUE +C R(I)=S +C 20 CONTINUE + DO 5 I=1,N + R(I)=0 + 5 CONTINUE + DO 10 J=1,M + S=X(J) + DO 20 I=1,N + R(I)=R(I)+A(I,J)*S + 20 CONTINUE + 10 CONTINUE + RETURN + END diff --git a/bench/btl/libs/f77/test_interface.hh b/bench/btl/libs/f77/test_interface.hh new file mode 100644 index 000000000..230c8dbc8 --- /dev/null +++ b/bench/btl/libs/f77/test_interface.hh @@ -0,0 +1,36 @@ +//===================================================== +// File : test_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:25 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef TEST_INTERFACE_HH +#define TEST_INTERFACE_HH + +template< class Interface > +void test_interface( void ){ + + Interface::interface_name(); + + typename Interface::gene_matrix A; + + + + + +} + +#endif diff --git a/bench/btl/libs/gmm/CMakeLists.txt b/bench/btl/libs/gmm/CMakeLists.txt new file mode 100644 index 000000000..98759e8b6 --- /dev/null +++ b/bench/btl/libs/gmm/CMakeLists.txt @@ -0,0 +1,3 @@ + +include_directories(${GMM_INCLUDES}) +btl_add_bench(btl_gmm main.cpp) diff --git a/bench/btl/libs/gmm/gmm_LU_solve_interface.hh b/bench/btl/libs/gmm/gmm_LU_solve_interface.hh new file mode 100644 index 000000000..dcb9f567f --- /dev/null +++ b/bench/btl/libs/gmm/gmm_LU_solve_interface.hh @@ -0,0 +1,192 @@ +//===================================================== +// File : blitz_LU_solve_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:31 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef BLITZ_LU_SOLVE_INTERFACE_HH +#define BLITZ_LU_SOLVE_INTERFACE_HH + +#include "blitz/array.h" +#include <vector> + +BZ_USING_NAMESPACE(blitz) + +template<class real> +class blitz_LU_solve_interface : public blitz_interface<real> +{ + +public : + + typedef typename blitz_interface<real>::gene_matrix gene_matrix; + typedef typename blitz_interface<real>::gene_vector gene_vector; + + typedef blitz::Array<int,1> Pivot_Vector; + + inline static void new_Pivot_Vector(Pivot_Vector & pivot,int N) + { + + pivot.resize(N); + + } + + inline static void free_Pivot_Vector(Pivot_Vector & pivot) + { + + return; + + } + + + static inline real matrix_vector_product_sliced(const gene_matrix & A, gene_vector B, int row, int col_start, int col_end) + { + + real somme=0.; + + for (int j=col_start ; j<col_end+1 ; j++){ + + somme+=A(row,j)*B(j); + + } + + return somme; + + } + + + + + static inline real matrix_matrix_product_sliced(gene_matrix & A, int row, int col_start, int col_end, gene_matrix & B, int row_shift, int col ) + { + + real somme=0.; + + for (int j=col_start ; j<col_end+1 ; j++){ + + somme+=A(row,j)*B(j+row_shift,col); + + } + + return somme; + + } + + inline static void LU_factor(gene_matrix & LU, Pivot_Vector & pivot, int N) + { + + ASSERT( LU.rows()==LU.cols() ) ; + int index_max = 0 ; + real big = 0. ; + real theSum = 0. ; + real dum = 0. ; + // Get the implicit scaling information : + gene_vector ImplicitScaling( N ) ; + for( int i=0; i<N; i++ ) { + big = 0. ; + for( int j=0; j<N; j++ ) { + if( abs( LU( i, j ) )>=big ) big = abs( LU( i, j ) ) ; + } + if( big==0. ) { + INFOS( "blitz_LU_factor::Singular matrix" ) ; + exit( 0 ) ; + } + ImplicitScaling( i ) = 1./big ; + } + // Loop over columns of Crout's method : + for( int j=0; j<N; j++ ) { + for( int i=0; i<j; i++ ) { + theSum = LU( i, j ) ; + theSum -= matrix_matrix_product_sliced(LU, i, 0, i-1, LU, 0, j) ; + // theSum -= sum( LU( i, Range( fromStart, i-1 ) )*LU( Range( fromStart, i-1 ), j ) ) ; + LU( i, j ) = theSum ; + } + + // Search for the largest pivot element : + big = 0. ; + for( int i=j; i<N; i++ ) { + theSum = LU( i, j ) ; + theSum -= matrix_matrix_product_sliced(LU, i, 0, j-1, LU, 0, j) ; + // theSum -= sum( LU( i, Range( fromStart, j-1 ) )*LU( Range( fromStart, j-1 ), j ) ) ; + LU( i, j ) = theSum ; + if( (ImplicitScaling( i )*abs( theSum ))>=big ) { + dum = ImplicitScaling( i )*abs( theSum ) ; + big = dum ; + index_max = i ; + } + } + // Interchanging rows and the scale factor : + if( j!=index_max ) { + for( int k=0; k<N; k++ ) { + dum = LU( index_max, k ) ; + LU( index_max, k ) = LU( j, k ) ; + LU( j, k ) = dum ; + } + ImplicitScaling( index_max ) = ImplicitScaling( j ) ; + } + pivot( j ) = index_max ; + if ( LU( j, j )==0. ) LU( j, j ) = 1.e-20 ; + // Divide by the pivot element : + if( j<N ) { + dum = 1./LU( j, j ) ; + for( int i=j+1; i<N; i++ ) LU( i, j ) *= dum ; + } + } + + } + + inline static void LU_solve(const gene_matrix & LU, const Pivot_Vector pivot, gene_vector &B, gene_vector X, int N) + { + + // Pour conserver le meme header, on travaille sur X, copie du second-membre B + X = B.copy() ; + ASSERT( LU.rows()==LU.cols() ) ; + firstIndex indI ; + // Forward substitution : + int ii = 0 ; + real theSum = 0. ; + for( int i=0; i<N; i++ ) { + int ip = pivot( i ) ; + theSum = X( ip ) ; + // theSum = B( ip ) ; + X( ip ) = X( i ) ; + // B( ip ) = B( i ) ; + if( ii ) { + theSum -= matrix_vector_product_sliced(LU, X, i, ii-1, i-1) ; + // theSum -= sum( LU( i, Range( ii-1, i-1 ) )*X( Range( ii-1, i-1 ) ) ) ; + // theSum -= sum( LU( i, Range( ii-1, i-1 ) )*B( Range( ii-1, i-1 ) ) ) ; + } else if( theSum ) { + ii = i+1 ; + } + X( i ) = theSum ; + // B( i ) = theSum ; + } + // Backsubstitution : + for( int i=N-1; i>=0; i-- ) { + theSum = X( i ) ; + // theSum = B( i ) ; + theSum -= matrix_vector_product_sliced(LU, X, i, i+1, N) ; + // theSum -= sum( LU( i, Range( i+1, toEnd ) )*X( Range( i+1, toEnd ) ) ) ; + // theSum -= sum( LU( i, Range( i+1, toEnd ) )*B( Range( i+1, toEnd ) ) ) ; + // Store a component of the solution vector : + X( i ) = theSum/LU( i, i ) ; + // B( i ) = theSum/LU( i, i ) ; + } + + } + +}; + +#endif diff --git a/bench/btl/libs/gmm/gmm_interface.hh b/bench/btl/libs/gmm/gmm_interface.hh new file mode 100644 index 000000000..6a81fe969 --- /dev/null +++ b/bench/btl/libs/gmm/gmm_interface.hh @@ -0,0 +1,119 @@ +//===================================================== +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef GMM_INTERFACE_HH +#define GMM_INTERFACE_HH + +#include <gmm/gmm.h> +#include <vector> + +using namespace gmm; + +template<class real> +class gmm_interface { + +public : + + typedef real real_type ; + + typedef std::vector<real> stl_vector; + typedef std::vector<stl_vector > stl_matrix; + + typedef gmm::dense_matrix<real> gene_matrix; + typedef stl_vector gene_vector; + + static inline std::string name( void ) + { + return "gmm"; + } + + static void free_matrix(gene_matrix & A, int N){ + return ; + } + + static void free_vector(gene_vector & B){ + return ; + } + + static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){ + A.resize(A_stl[0].size(),A_stl.size()); + + for (int j=0; j<A_stl.size() ; j++){ + for (int i=0; i<A_stl[j].size() ; i++){ + A(i,j) = A_stl[j][i]; + } + } + } + + static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){ + B = B_stl; + } + + static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){ + B_stl = B; + } + + static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){ + int N=A_stl.size(); + + for (int j=0;j<N;j++){ + A_stl[j].resize(N); + for (int i=0;i<N;i++){ + A_stl[j][i] = A(i,j); + } + } + } + + static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){ + gmm::mult(A,B, X); + } + + static inline void transposed_matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){ + gmm::mult(gmm::transposed(A),gmm::transposed(B), X); + } + + static inline void ata_product(const gene_matrix & A, gene_matrix & X, int N){ + gmm::mult(gmm::transposed(A),A, X); + } + + static inline void aat_product(const gene_matrix & A, gene_matrix & X, int N){ + gmm::mult(A,gmm::transposed(A), X); + } + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){ + gmm::mult(A,B,X); + } + + static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){ + gmm::mult(gmm::transposed(A),B,X); + } + + static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){ + gmm::add(gmm::scaled(X,coef), Y); + } + + static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){ + gmm::copy(source,cible); + } + + static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){ + gmm::copy(source,cible); + } + +}; + +#endif diff --git a/bench/btl/libs/gmm/main.cpp b/bench/btl/libs/gmm/main.cpp new file mode 100644 index 000000000..27afeedbb --- /dev/null +++ b/bench/btl/libs/gmm/main.cpp @@ -0,0 +1,44 @@ +//===================================================== +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include "gmm_interface.hh" +#include "bench.hh" +#include "action_matrix_vector_product.hh" +#include "action_matrix_matrix_product.hh" +#include "action_axpy.hh" +#include "action_lu_solve.hh" +#include "action_ata_product.hh" +#include "action_aat_product.hh" +#include "action_atv_product.hh" + +int main() +{ + + bench<Action_axpy<gmm_interface<REAL_TYPE> > >(MIN_AXPY,MAX_AXPY,NB_POINT); + bench<Action_matrix_vector_product<gmm_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + bench<Action_atv_product<gmm_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + bench<Action_matrix_matrix_product<gmm_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_ata_product<gmm_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_aat_product<gmm_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + //bench<Action_lu_solve<blitz_LU_solve_interface<REAL_TYPE> > >(MIN_LU,MAX_LU,NB_POINT); + + return 0; +} + + diff --git a/bench/btl/libs/mtl4/.kdbgrc.main b/bench/btl/libs/mtl4/.kdbgrc.main new file mode 100644 index 000000000..fed082f7f --- /dev/null +++ b/bench/btl/libs/mtl4/.kdbgrc.main @@ -0,0 +1,12 @@ +[General] +DebuggerCmdStr= +DriverName=GDB +FileVersion=1 +OptionsSelected= +ProgramArgs= +TTYLevel=7 +WorkingDirectory= + +[Memory] +ColumnWidths=80,0 +NumExprs=0 diff --git a/bench/btl/libs/mtl4/main.cpp b/bench/btl/libs/mtl4/main.cpp new file mode 100644 index 000000000..219570d28 --- /dev/null +++ b/bench/btl/libs/mtl4/main.cpp @@ -0,0 +1,42 @@ +//===================================================== +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include "mtl4_interface.hh" +#include "bench.hh" +#include "action_matrix_vector_product.hh" +#include "action_matrix_matrix_product.hh" +#include "action_axpy.hh" +#include "action_lu_solve.hh" +#include "action_ata_product.hh" +#include "action_aat_product.hh" +#include "action_atv_product.hh" + +int main() +{ + + bench<Action_axpy<mtl4_interface<REAL_TYPE> > >(MIN_AXPY,MAX_AXPY,NB_POINT); + bench<Action_matrix_vector_product<mtl4_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + bench<Action_atv_product<mtl4_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + bench<Action_matrix_matrix_product<mtl4_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_ata_product<mtl4_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_aat_product<mtl4_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + return 0; +} + + diff --git a/bench/btl/libs/mtl4/mtl4_LU_solve_interface.hh b/bench/btl/libs/mtl4/mtl4_LU_solve_interface.hh new file mode 100644 index 000000000..dcb9f567f --- /dev/null +++ b/bench/btl/libs/mtl4/mtl4_LU_solve_interface.hh @@ -0,0 +1,192 @@ +//===================================================== +// File : blitz_LU_solve_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:31 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef BLITZ_LU_SOLVE_INTERFACE_HH +#define BLITZ_LU_SOLVE_INTERFACE_HH + +#include "blitz/array.h" +#include <vector> + +BZ_USING_NAMESPACE(blitz) + +template<class real> +class blitz_LU_solve_interface : public blitz_interface<real> +{ + +public : + + typedef typename blitz_interface<real>::gene_matrix gene_matrix; + typedef typename blitz_interface<real>::gene_vector gene_vector; + + typedef blitz::Array<int,1> Pivot_Vector; + + inline static void new_Pivot_Vector(Pivot_Vector & pivot,int N) + { + + pivot.resize(N); + + } + + inline static void free_Pivot_Vector(Pivot_Vector & pivot) + { + + return; + + } + + + static inline real matrix_vector_product_sliced(const gene_matrix & A, gene_vector B, int row, int col_start, int col_end) + { + + real somme=0.; + + for (int j=col_start ; j<col_end+1 ; j++){ + + somme+=A(row,j)*B(j); + + } + + return somme; + + } + + + + + static inline real matrix_matrix_product_sliced(gene_matrix & A, int row, int col_start, int col_end, gene_matrix & B, int row_shift, int col ) + { + + real somme=0.; + + for (int j=col_start ; j<col_end+1 ; j++){ + + somme+=A(row,j)*B(j+row_shift,col); + + } + + return somme; + + } + + inline static void LU_factor(gene_matrix & LU, Pivot_Vector & pivot, int N) + { + + ASSERT( LU.rows()==LU.cols() ) ; + int index_max = 0 ; + real big = 0. ; + real theSum = 0. ; + real dum = 0. ; + // Get the implicit scaling information : + gene_vector ImplicitScaling( N ) ; + for( int i=0; i<N; i++ ) { + big = 0. ; + for( int j=0; j<N; j++ ) { + if( abs( LU( i, j ) )>=big ) big = abs( LU( i, j ) ) ; + } + if( big==0. ) { + INFOS( "blitz_LU_factor::Singular matrix" ) ; + exit( 0 ) ; + } + ImplicitScaling( i ) = 1./big ; + } + // Loop over columns of Crout's method : + for( int j=0; j<N; j++ ) { + for( int i=0; i<j; i++ ) { + theSum = LU( i, j ) ; + theSum -= matrix_matrix_product_sliced(LU, i, 0, i-1, LU, 0, j) ; + // theSum -= sum( LU( i, Range( fromStart, i-1 ) )*LU( Range( fromStart, i-1 ), j ) ) ; + LU( i, j ) = theSum ; + } + + // Search for the largest pivot element : + big = 0. ; + for( int i=j; i<N; i++ ) { + theSum = LU( i, j ) ; + theSum -= matrix_matrix_product_sliced(LU, i, 0, j-1, LU, 0, j) ; + // theSum -= sum( LU( i, Range( fromStart, j-1 ) )*LU( Range( fromStart, j-1 ), j ) ) ; + LU( i, j ) = theSum ; + if( (ImplicitScaling( i )*abs( theSum ))>=big ) { + dum = ImplicitScaling( i )*abs( theSum ) ; + big = dum ; + index_max = i ; + } + } + // Interchanging rows and the scale factor : + if( j!=index_max ) { + for( int k=0; k<N; k++ ) { + dum = LU( index_max, k ) ; + LU( index_max, k ) = LU( j, k ) ; + LU( j, k ) = dum ; + } + ImplicitScaling( index_max ) = ImplicitScaling( j ) ; + } + pivot( j ) = index_max ; + if ( LU( j, j )==0. ) LU( j, j ) = 1.e-20 ; + // Divide by the pivot element : + if( j<N ) { + dum = 1./LU( j, j ) ; + for( int i=j+1; i<N; i++ ) LU( i, j ) *= dum ; + } + } + + } + + inline static void LU_solve(const gene_matrix & LU, const Pivot_Vector pivot, gene_vector &B, gene_vector X, int N) + { + + // Pour conserver le meme header, on travaille sur X, copie du second-membre B + X = B.copy() ; + ASSERT( LU.rows()==LU.cols() ) ; + firstIndex indI ; + // Forward substitution : + int ii = 0 ; + real theSum = 0. ; + for( int i=0; i<N; i++ ) { + int ip = pivot( i ) ; + theSum = X( ip ) ; + // theSum = B( ip ) ; + X( ip ) = X( i ) ; + // B( ip ) = B( i ) ; + if( ii ) { + theSum -= matrix_vector_product_sliced(LU, X, i, ii-1, i-1) ; + // theSum -= sum( LU( i, Range( ii-1, i-1 ) )*X( Range( ii-1, i-1 ) ) ) ; + // theSum -= sum( LU( i, Range( ii-1, i-1 ) )*B( Range( ii-1, i-1 ) ) ) ; + } else if( theSum ) { + ii = i+1 ; + } + X( i ) = theSum ; + // B( i ) = theSum ; + } + // Backsubstitution : + for( int i=N-1; i>=0; i-- ) { + theSum = X( i ) ; + // theSum = B( i ) ; + theSum -= matrix_vector_product_sliced(LU, X, i, i+1, N) ; + // theSum -= sum( LU( i, Range( i+1, toEnd ) )*X( Range( i+1, toEnd ) ) ) ; + // theSum -= sum( LU( i, Range( i+1, toEnd ) )*B( Range( i+1, toEnd ) ) ) ; + // Store a component of the solution vector : + X( i ) = theSum/LU( i, i ) ; + // B( i ) = theSum/LU( i, i ) ; + } + + } + +}; + +#endif diff --git a/bench/btl/libs/mtl4/mtl4_interface.hh b/bench/btl/libs/mtl4/mtl4_interface.hh new file mode 100644 index 000000000..73ff565fc --- /dev/null +++ b/bench/btl/libs/mtl4/mtl4_interface.hh @@ -0,0 +1,120 @@ +//===================================================== +// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef MTL4_INTERFACE_HH +#define MTL4_INTERFACE_HH + +#include <boost/numeric/mtl/mtl.hpp> +#include <vector> + +using namespace mtl; + +template<class real> +class mtl4_interface { + +public : + + typedef real real_type ; + + typedef std::vector<real> stl_vector; + typedef std::vector<stl_vector > stl_matrix; + + typedef mtl::dense2D<real, mtl::matrix::parameters<mtl::tag::col_major> > gene_matrix; + typedef mtl::dense_vector<real> gene_vector; + + static inline std::string name() { return "mtl4"; } + + static void free_matrix(gene_matrix & A, int N){ + return ; + } + + static void free_vector(gene_vector & B){ + return ; + } + + static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){ + A.change_dim(A_stl[0].size(), A_stl.size()); + + for (int j=0; j<A_stl.size() ; j++){ + for (int i=0; i<A_stl[j].size() ; i++){ + A(i,j) = A_stl[j][i]; + } + } + } + + static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){ + B.change_dim(B_stl.size()); + for (int i=0; i<B_stl.size() ; i++){ + B[i] = B_stl[i]; + } + } + + static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){ + for (int i=0; i<B_stl.size() ; i++){ + B_stl[i] = B[i]; + } + } + + static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){ + int N=A_stl.size(); + for (int j=0;j<N;j++){ + A_stl[j].resize(N); + for (int i=0;i<N;i++){ + A_stl[j][i] = A(i,j); + } + } + } + + static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){ + X = (A*B); + } + + static inline void transposed_matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){ + X = (trans(A)*trans(B)); + } + + static inline void ata_product(const gene_matrix & A, gene_matrix & X, int N){ + X = (trans(A)*A); + } + + static inline void aat_product(const gene_matrix & A, gene_matrix & X, int N){ + X = (A*trans(A)); + } + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){ + X = (A*B); + } + + static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){ + X = (trans(A)*B); + } + + static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){ + Y += coef * X; + } + + static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){ + cible = source; + } + + static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){ + cible = source; + } + +}; + +#endif diff --git a/bench/btl/libs/tiny_blitz/CMakeLists.txt b/bench/btl/libs/tiny_blitz/CMakeLists.txt new file mode 100644 index 000000000..e3e2625a7 --- /dev/null +++ b/bench/btl/libs/tiny_blitz/CMakeLists.txt @@ -0,0 +1,4 @@ + +include_directories(${BLITZ_INCLUDES}) +btl_add_bench(btl_tiny_blitz main.cpp) +target_link_libraries(btl_tiny_blitz ${BLITZ_LIBRARIES}) diff --git a/bench/btl/libs/tiny_blitz/main.cpp b/bench/btl/libs/tiny_blitz/main.cpp new file mode 100644 index 000000000..6675d3d1a --- /dev/null +++ b/bench/btl/libs/tiny_blitz/main.cpp @@ -0,0 +1,37 @@ +//===================================================== +// File : main.cpp +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:30 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include "tiny_blitz_interface.hh" +#include "static/bench_static.hh" +#include "action_matrix_vector_product.hh" +#include "action_matrix_matrix_product.hh" +#include "action_axpy.hh" +#include "timers/x86_perf_analyzer.hh" + +int main() +{ + bench_static<Action_axpy,tiny_blitz_interface>(); + bench_static<Action_matrix_matrix_product,tiny_blitz_interface>(); + bench_static<Action_matrix_vector_product,tiny_blitz_interface>(); + + return 0; +} + + diff --git a/bench/btl/libs/tiny_blitz/tiny_blitz_interface.hh b/bench/btl/libs/tiny_blitz/tiny_blitz_interface.hh new file mode 100644 index 000000000..6b26db72d --- /dev/null +++ b/bench/btl/libs/tiny_blitz/tiny_blitz_interface.hh @@ -0,0 +1,106 @@ +//===================================================== +// File : tiny_blitz_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:30 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef TINY_BLITZ_INTERFACE_HH +#define TINY_BLITZ_INTERFACE_HH + +#include "blitz/array.h" +#include "blitz/tiny.h" +#include "blitz/tinymat.h" +#include "blitz/tinyvec.h" +#include <blitz/tinyvec-et.h> + +#include <vector> + +BZ_USING_NAMESPACE(blitz) + +template<class real, int SIZE> +class tiny_blitz_interface +{ + +public : + + typedef real real_type ; + + typedef std::vector<real> stl_vector; + typedef std::vector<stl_vector > stl_matrix; + + typedef TinyVector<real,SIZE> gene_vector; + typedef TinyMatrix<real,SIZE,SIZE> gene_matrix; + + static inline std::string name() { return "tiny_blitz"; } + + static void free_matrix(gene_matrix & A, int N){} + + static void free_vector(gene_vector & B){} + + static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){ + for (int j=0; j<A_stl.size() ; j++) + for (int i=0; i<A_stl[j].size() ; i++) + A(i,j)=A_stl[j][i]; + } + + static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){ + for (int i=0; i<B_stl.size() ; i++) + B(i) = B_stl[i]; + } + + static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){ + for (int i=0; i<B_stl.size() ; i++) + B_stl[i] = B(i); + } + + static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){ + int N = A_stl.size(); + for (int j=0;j<N;j++) + { + A_stl[j].resize(N); + for (int i=0;i<N;i++) + A_stl[j][i] = A(i,j); + } + } + + static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){ + for (int j=0;j<N;j++) + for (int i=0;i<N;i++) + cible(i,j) = source(i,j); + } + + static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){ + for (int i=0;i<N;i++){ + cible(i) = source(i); + } + } + + static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){ + X = product(A,B); + } + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){ + X = product(A,B); + } + + static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){ + Y += coef * X; + } + +}; + + +#endif diff --git a/bench/btl/libs/tvmet/CMakeLists.txt b/bench/btl/libs/tvmet/CMakeLists.txt new file mode 100644 index 000000000..e047b4e08 --- /dev/null +++ b/bench/btl/libs/tvmet/CMakeLists.txt @@ -0,0 +1,4 @@ + +include_directories(${BLITZ_INCLUDES}) +add_executable(btl_blitz main.cpp) +target_link_libraries(btl_blitz ${BLITZ_LIBRARIES}) diff --git a/bench/btl/libs/tvmet/main.cpp b/bench/btl/libs/tvmet/main.cpp new file mode 100644 index 000000000..448c1a980 --- /dev/null +++ b/bench/btl/libs/tvmet/main.cpp @@ -0,0 +1,36 @@ +//===================================================== +// File : main.cpp +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:30 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include "tvmet_interface.hh" +#include "static/bench_static.hh" +#include "action_matrix_vector_product.hh" +#include "action_matrix_matrix_product.hh" +#include "action_axpy.hh" + +int main() +{ + bench_static<Action_axpy,tvmet_interface>(); + bench_static<Action_matrix_matrix_product,tvmet_interface>(); + bench_static<Action_matrix_vector_product,tvmet_interface>(); + + return 0; +} + + diff --git a/bench/btl/libs/tvmet/tvmet_interface.hh b/bench/btl/libs/tvmet/tvmet_interface.hh new file mode 100644 index 000000000..dfbfa20aa --- /dev/null +++ b/bench/btl/libs/tvmet/tvmet_interface.hh @@ -0,0 +1,141 @@ +//===================================================== +// File : tvmet_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:30 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef TVMET_INTERFACE_HH +#define TVMET_INTERFACE_HH + +#include <tvmet/Vector.h> +#include <tvmet/Matrix.h> + +#include <vector> + +using namespace tvmet; + +template<class real, int SIZE> +class tvmet_interface{ + +public : + + typedef real real_type ; + + typedef std::vector<real> stl_vector; + typedef std::vector<stl_vector > stl_matrix; + + typedef Vector<real,SIZE> gene_vector; + typedef Matrix<real,SIZE,SIZE> gene_matrix; + + static inline std::string name( void ) + { + return "tvmet"; + } + + + static void free_matrix(gene_matrix & A, int N){ + + return ; + } + + static void free_vector(gene_vector & B){ + + return ; + + } + + static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){ + + for (int i=0; i<A_stl.size() ; i++){ + for (int j=0; j<A_stl[i].size() ; j++){ + A(i,j)=A_stl[i][j]; + } + + } + } + + static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){ + + for (int i=0; i<B_stl.size() ; i++){ + B[i]=B_stl[i]; + } + } + + static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){ + + for (int i=0; i<B_stl.size() ; i++){ + B_stl[i]=B[i]; + } + } + + static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){ + + int N=A_stl.size(); + + for (int i=0;i<N;i++){ + A_stl[i].resize(N); + for (int j=0;j<N;j++){ + A_stl[i][j]=A(i,j); + } + } + + } + + + static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N) + { + + for (int i=0;i<N;i++){ + for (int j=0;j<N;j++){ + cible(i,j)=source(i,j); + } + } + + } + + static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N) + { + + for (int i=0;i<N;i++){ + cible[i]=source[i]; + } + + } + + + + static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N) + { + X=product(A,B); + } + + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N) + { + X=product(A,B); + + } + + static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N) + { + Y+=coef*X; + } + + +}; + + +#endif diff --git a/bench/btl/libs/ublas/CMakeLists.txt b/bench/btl/libs/ublas/CMakeLists.txt new file mode 100644 index 000000000..25931c46e --- /dev/null +++ b/bench/btl/libs/ublas/CMakeLists.txt @@ -0,0 +1,3 @@ + +include_directories(${Boost_INCLUDES}) +btl_add_bench(btl_ublas main.cpp) diff --git a/bench/btl/libs/ublas/main.cpp b/bench/btl/libs/ublas/main.cpp new file mode 100644 index 000000000..768010406 --- /dev/null +++ b/bench/btl/libs/ublas/main.cpp @@ -0,0 +1,44 @@ +//===================================================== +// File : main.cpp +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:27 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#include "utilities.h" +#include "ublas_interface.hh" +#include "bench.hh" +#include "action_matrix_vector_product.hh" +#include "action_matrix_matrix_product.hh" +#include "action_axpy.hh" +#include "action_ata_product.hh" +#include "action_aat_product.hh" +#include "action_atv_product.hh" + +int main() +{ + bench<Action_axpy<ublas_interface<REAL_TYPE> > >(MIN_AXPY,MAX_AXPY,NB_POINT); + + bench<Action_matrix_vector_product<ublas_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + bench<Action_atv_product<ublas_interface<REAL_TYPE> > >(MIN_MV,MAX_MV,NB_POINT); + + bench<Action_matrix_matrix_product<ublas_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_ata_product<ublas_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + bench<Action_aat_product<ublas_interface<REAL_TYPE> > >(MIN_MM,MAX_MM,NB_POINT); + + return 0; +} + + diff --git a/bench/btl/libs/ublas/ublas_interface.hh b/bench/btl/libs/ublas/ublas_interface.hh new file mode 100644 index 000000000..c8acb32db --- /dev/null +++ b/bench/btl/libs/ublas/ublas_interface.hh @@ -0,0 +1,131 @@ +//===================================================== +// File : ublas_interface.hh +// Author : L. Plagne <laurent.plagne@edf.fr)> +// Copyright (C) EDF R&D, lun sep 30 14:23:27 CEST 2002 +//===================================================== +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// 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 +// GNU General Public License for more details. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef UBLAS_INTERFACE_HH +#define UBLAS_INTERFACE_HH + +#include <boost/numeric/ublas/vector.hpp> +#include <boost/numeric/ublas/matrix.hpp> +#include <boost/numeric/ublas/io.hpp> + + +template <class real> +class ublas_interface{ + +public : + + typedef real real_type ; + + typedef std::vector<real> stl_vector; + typedef std::vector<stl_vector> stl_matrix; + + typedef typename boost::numeric::ublas::matrix<real,boost::numeric::ublas::column_major> gene_matrix; + typedef typename boost::numeric::ublas::vector<real> gene_vector; + + static inline std::string name( void ) { return "ublas"; } + + static void free_matrix(gene_matrix & A, int N) {} + + static void free_vector(gene_vector & B) {} + + static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){ + A.resize(A_stl.size(),A_stl[0].size()); + for (int i=0; i<A_stl.size() ; i++) + for (int j=0; j<A_stl[i].size() ; j++) + A(i,j)=A_stl[i][j]; + } + + static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){ + B.resize(B_stl.size()); + for (int i=0; i<B_stl.size() ; i++) + B(i)=B_stl[i]; + } + + static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){ + for (int i=0; i<B_stl.size() ; i++) + B_stl[i]=B(i); + } + + static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){ + int N=A_stl.size(); + for (int i=0;i<N;i++) + { + A_stl[i].resize(N); + for (int j=0;j<N;j++) + A_stl[i][j]=A(i,j); + } + } + + static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){ + for (int i=0;i<N;i++){ + cible(i) = source(i); + } + } + + static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){ + for (int i=0;i<N;i++){ + for (int j=0;j<N;j++){ + cible(i,j) = source(i,j); + } + } + } + + static inline void matrix_vector_product_slow(gene_matrix & A, gene_vector & B, gene_vector & X, int N){ + X = prod(A,B); + } + + static inline void matrix_matrix_product_slow(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N){ + X = prod(A,B); + } + + static inline void axpy_slow(const real coef, const gene_vector & X, gene_vector & Y, int N){ + Y+=coef*X; + } + + // alias free assignements + + static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){ + X.assign(prod(A,B)); + } + + static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){ + X.assign(prod(trans(A),B)); + } + + static inline void matrix_matrix_product(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N){ + X.assign(prod(A,B)); + } + + static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){ + Y.plus_assign(coef*X); + } + + static inline void ata_product(gene_matrix & A, gene_matrix & X, int N){ + // X = prod(trans(A),A); + X.assign(prod(trans(A),A)); + } + + static inline void aat_product(gene_matrix & A, gene_matrix & X, int N){ + // X = prod(A,trans(A)); + X.assign(prod(A,trans(A))); + } + +}; + +#endif |