00001 ////////////////////////////////////////////////////////////////////////////////////////////////// 00002 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. 00003 // Produced at the Lawrence Livermore National Laboratory 00004 // LLNL-CODE-433662 00005 // All rights reserved. 00006 // 00007 // This file is part of Muster. For details, see http://github.com/tgamblin/muster. 00008 // Please also read the LICENSE file for further information. 00009 // 00010 // Redistribution and use in source and binary forms, with or without modification, are 00011 // permitted provided that the following conditions are met: 00012 // 00013 // * Redistributions of source code must retain the above copyright notice, this list of 00014 // conditions and the disclaimer below. 00015 // * Redistributions in binary form must reproduce the above copyright notice, this list of 00016 // conditions and the disclaimer (as noted below) in the documentation and/or other materials 00017 // provided with the distribution. 00018 // * Neither the name of the LLNS/LLNL nor the names of its contributors may be used to endorse 00019 // or promote products derived from this software without specific prior written permission. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS 00022 // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00023 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 00024 // LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE 00025 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00027 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00028 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00029 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 ////////////////////////////////////////////////////////////////////////////////////////////////// 00031 00032 /// 00033 /// @file par_kmedoids.cpp 00034 /// @author Todd Gamblin tgamblin@llnl.gov 00035 /// 00036 #include "par_kmedoids.h" 00037 00038 #include <cstdlib> 00039 #include <stdint.h> 00040 #include <sys/time.h> 00041 using namespace std; 00042 00043 #include "random.h" 00044 00045 namespace cluster { 00046 00047 par_kmedoids::par_kmedoids(MPI_Comm comm) 00048 : par_partition(comm), 00049 total_dissimilarity(numeric_limits<double>::infinity()), 00050 best_bic_score(0), 00051 init_size(40), 00052 max_reps(5), 00053 epsilon(1e-15) 00054 { } 00055 00056 00057 void par_kmedoids::set_epsilon(double e) { 00058 epsilon = e; 00059 } 00060 00061 00062 double par_kmedoids::average_dissimilarity() { 00063 int size; 00064 CMPI_Comm_size(comm, &size); 00065 return total_dissimilarity / size; 00066 } 00067 00068 double par_kmedoids::bic_score() { 00069 return best_bic_score; 00070 } 00071 00072 void par_kmedoids::seed_random_uniform(MPI_Comm comm) { 00073 int rank; 00074 CMPI_Comm_rank(comm, &rank); 00075 00076 // same seed on all processes. 00077 uint32_t seed = get_time_seed(); 00078 CMPI_Bcast(&seed, 1, MPI_INT, 0, comm); 00079 random.seed(seed); 00080 } 00081 00082 } // namespace cluster