Commit 44c6aefc by Danny Perez

Initial commit

parents
//
// Dispatcher.cpp
// ParSplice
//
// Created by Danny Perez on 11/11/15.
// Copyright (c) 2015 dp. All rights reserved.
//
#include "Dispatcher.h"
//
// Dispatcher.h
// ParSplice
//
// Created by Danny Perez on 11/11/15.
// Copyright (c) 2015 dp. All rights reserved.
//
#ifndef __ParSplice__Dispatcher__
#define __ParSplice__Dispatcher__
#include <stdio.h>
#include <mpi.h>
#include "ParSpliceCommon.h"
class Dispatcher{
public:
Dispatcher(MPI_Comm commp_,MPI_Comm commc_, int nTask_, int parent){
commp=commp_;
commc=commc_;
nTask=nTask_;
root=parent;
pthread_mutex_init(&lock, NULL);
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
//spin the two threads
int ret=pthread_create(&serverTh,&attr,&Dispatcher::serverThHandle,this);
ret=pthread_create(&dispatcherTh,&attr,&Dispatcher::dispatcherThHandle,this);
};
static void *serverThHandle(void *context){
Dispatcher *p=static_cast< Dispatcher* >(context);
p->server();
return NULL;
};
static void *dispatcherThHandle(void *context){
Dispatcher *p=static_cast< Dispatcher* >(context);
p->dispatcher();
return NULL;
};
void server(){
std::vector<parsplice::Label> uintCommBuff(nTask);
while(true){
MPI_Bcast(&(uintCommBuff[0]), nTask, MPI::UNSIGNED , root, commp);
BOOST_LOG_SEV(lg,info) <<"#Received tasks from "<<root;
pthread_mutex_lock(&lock);
tasks.clear();
for(int i=0;i<nTask;i++){
tasks.push_back(uintCommBuff[i]);
}
{
logging::record rec = lg.open_record();
if (rec)
{
logging::record_ostream strm(rec);
strm<<"========== TASKS ==========\n";
for(int i=0;i<nTask;i++){
strm<<tasks[i]<<" ";
}
strm.flush();
lg.push_record(boost::move(rec));
}
}
pthread_mutex_unlock(&lock);
}
};
void dispatcher(){
BOOST_LOG_SEV(lg,info) <<"#Dispatcher dispatcher ";
std::vector<parsplice::Label> uintCommBuff(1);
MPI_Request req;
int completed=0;
MPI_Status status;
//post an initial non-blocking receive
MPI_Irecv(&(uintCommBuff[0]),1,MPI::UNSIGNED,MPI::ANY_SOURCE,MPI_ANY_TAG,commc,&req);
while(true){
MPI_Test(&req,&completed,&status);
if(completed){
int producerID=status.MPI_SOURCE;
requestQueue.push_back(producerID);
BOOST_LOG_SEV(lg,info) <<"#Received request from "<<producerID;
//post the next receive
completed=0;
MPI_Irecv(&(uintCommBuff[0]),1,MPI::UNSIGNED,MPI::ANY_SOURCE,MPI_ANY_TAG,commc,&req);
}
BOOST_LOG_SEV(lg,info) <<"#Processing "<< requestQueue.size() << " requests";
//process
pthread_mutex_lock(&lock);
if(tasks.size()>0){
//randomly sample with replacement
for(std::list<int>::iterator it=requestQueue.begin();it!=requestQueue.end();it++){
boost::random::uniform_int_distribution<int> d(0,int(tasks.size()-1));
uintCommBuff[0]=tasks[d(rand)];
MPI_Send(&(uintCommBuff[0]),1,MPI::UNSIGNED,*it,1,commc);
BOOST_LOG_SEV(lg,info) <<"#Processed request from "<<*it;
}
requestQueue.clear();
}
pthread_mutex_unlock(&lock);
}
};
protected:
int nTask;
int root;
std::deque<parsplice::Label> tasks;
boost::random::mt19937 rand;
std::list<int> requestQueue;
MPI_Comm commc;
MPI_Comm commp;
pthread_t serverTh;
pthread_t dispatcherTh;
pthread_mutex_t lock;
boost::log::sources::severity_logger< boost::log::trivial::severity_level > lg;
};
#endif /* defined(__ParSplice__Dispatcher__) */
/*
Copyright (c) 2016, Los Alamos National Security, LLC
All rights reserved.
Copyright 2016. Los Alamos National Security, LLC. This software was produced under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National Laboratory (LANL), which is operated by Los Alamos National Security, LLC for the U.S. Department of Energy. The U.S. Government has rights to use, reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to produce derivative works, such modified software should be clearly marked, so as not to confuse it with the version available from LANL.
Additionally, redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of Los Alamos National Security, LLC, Los Alamos National Laboratory, LANL, the U.S. Government, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "NodeManager.h"
This diff is collapsed. Click to expand it.
/*
Copyright (c) 2016, Los Alamos National Security, LLC
All rights reserved.
Copyright 2016. Los Alamos National Security, LLC. This software was produced under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National Laboratory (LANL), which is operated by Los Alamos National Security, LLC for the U.S. Department of Energy. The U.S. Government has rights to use, reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to produce derivative works, such modified software should be clearly marked, so as not to confuse it with the version available from LANL.
Additionally, redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of Los Alamos National Security, LLC, Los Alamos National Laboratory, LANL, the U.S. Government, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ParSpliceCommon.h"
void imerge(parsplice::TrajDB &source, parsplice::TrajDB &supp){
for(parsplice::TrajDB::iterator it=source.begin();it!=source.end();it++){
//loop over trajectories
for(std::deque<parsplice::Trajectory>::iterator itt=it->second.begin();itt!=it->second.end();itt++){
std::cout<<"=========source===========\n";
for(std::list<parsplice::Visit>::iterator ittt=itt->visits.begin();ittt!=itt->visits.end();ittt++){
std::cout<<" -- ( "<<ittt->label<<" ) "<<ittt->duration;
}
std::cout<<"\n";
}
}
for(parsplice::TrajDB::iterator it=supp.begin();it!=supp.end();it++){
//loop over trajectories
for(std::deque<parsplice::Trajectory>::iterator itt=it->second.begin();itt!=it->second.end();itt++){
std::cout<<"=========supp===========\n";
for(std::list<parsplice::Visit>::iterator ittt=itt->visits.begin();ittt!=itt->visits.end();ittt++){
std::cout<<" -- ( "<<ittt->label<<" ) "<<ittt->duration;
}
std::cout<<"\n";
}
}
//loop over initial states
for(parsplice::TrajDB::iterator it=supp.begin();it!=supp.end();it++){
std::cout<<"o "<<source.size()<<" "<<supp.size()<<std::endl;
//loop over trajectories
for(std::deque<parsplice::Trajectory>::iterator itt=it->second.begin();itt!=it->second.end();itt++){
std::cout<<"i "<<it->first<<" "<<itt->empty()<<std::endl;
parsplice::Trajectory &t=*itt;
if(not t.empty()){
parsplice::Label lb=t.front().label;
std::cout<<"ii "<<it->first<<" label "<<lb<<" "<<source.count(lb)<<std::endl;
//if trajectory exist in that bin, try to splice at back. Otherwise, add
if(source.count(lb)>0 and not source[lb].empty()){
if(not source[lb].back().splice(t)){
source[lb].push_back(t);
}
}
else{
std::cout<<"iii "<<it->first<<" label "<<lb<<" "<<source.count(lb)<<std::endl;
source[lb]=std::deque<parsplice::Trajectory>();
source[lb].push_back(t);
}
}
}
}
};
void merge(parsplice::TrajDB &source, parsplice::TrajDB &supp){
//loop over initial states
for(parsplice::TrajDB::iterator it=supp.begin();it!=supp.end();it++){
//loop over trajectories
for(std::deque<parsplice::Trajectory>::iterator itt=it->second.begin();itt!=it->second.end();itt++){
parsplice::Trajectory &t=*itt;
if(not t.empty()){
parsplice::Label lb=t.front().label;
//if trajectory exist in that bin, try to splice at back. Otherwise, add
if(source.count(lb)>0 and not source[lb].empty()){
if(not source[lb].back().splice(t)){
source[lb].push_back(t);
}
}
else{
source[lb]=std::deque<parsplice::Trajectory>();
source[lb].push_back(t);
}
}
}
}
};
void serializeDB(parsplice::TrajDB &source, std::vector<unsigned int> &v, int &i){
int i0=i;
//placeholder for the number of trajectories in the db
v[i++]=0;
parsplice::Trajectory t;
//loop over initial states
for(parsplice::TrajDB::iterator it=source.begin();it!=source.end();it++){
//loop over trajectories
for(std::deque<parsplice::Trajectory>::iterator itt=it->second.begin();itt!=it->second.end();itt++){
itt->serialize(v,i);
v[i0]++;
}
}
};
parsplice::TrajDB deserializeDB( std::vector<unsigned int> &v, int &i){
parsplice::TrajDB db;
parsplice::Trajectory t;
int nt=v[i++];
for(int j=0;j<nt;j++){
t.clear();
t.deserialize(v, i);
parsplice::Label l=t.front().label;
db[l].push_back(t);
}
return db;
};
void logTrajDB(boost::log::sources::severity_logger< boost::log::trivial::severity_level > lg, parsplice::TrajDB &db){
logging::record rec = lg.open_record(keywords::severity = info);
if (rec)
{
logging::record_ostream strm(rec);
strm<<"========== DB ==========\n";
//loop over initial states
for(parsplice::TrajDB::iterator it=db.begin();it!=db.end();it++){
//loop over trajectories
for(std::deque<parsplice::Trajectory>::iterator itt=it->second.begin();itt!=it->second.end();itt++){
strm<<"====================\n";
strm<<itt->length<<"\n";
for(std::list<parsplice::Visit>::iterator ittt=itt->visits.begin();ittt!=itt->visits.end();ittt++){
strm<<" -- ( "<<ittt->label<<" ) "<<ittt->duration;
}
strm<<"\n";
}
}
strm.flush();
lg.push_record(boost::move(rec));
}
};
void logTrajDBTr(boost::log::sources::severity_logger< boost::log::trivial::severity_level > lg, parsplice::TrajDB &db){
logging::record rec = lg.open_record(keywords::severity = trace);
if (rec)
{
logging::record_ostream strm(rec);
strm<<"========== DB ==========\n";
//loop over initial states
for(parsplice::TrajDB::iterator it=db.begin();it!=db.end();it++){
//loop over trajectories
for(std::deque<parsplice::Trajectory>::iterator itt=it->second.begin();itt!=it->second.end();itt++){
strm<<"====================\n";
strm<<itt->length<<"\n";
for(std::list<parsplice::Visit>::iterator ittt=itt->visits.begin();ittt!=itt->visits.end();ittt++){
strm<<" -- ( "<<ittt->label<<" ) "<<ittt->duration;
}
strm<<"\n";
}
}
strm.flush();
lg.push_record(boost::move(rec));
}
};
/*
Copyright (c) 2016, Los Alamos National Security, LLC
All rights reserved.
Copyright 2016. Los Alamos National Security, LLC. This software was produced under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National Laboratory (LANL), which is operated by Los Alamos National Security, LLC for the U.S. Department of Energy. The U.S. Government has rights to use, reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to produce derivative works, such modified software should be clearly marked, so as not to confuse it with the version available from LANL.
Additionally, redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of Los Alamos National Security, LLC, Los Alamos National Laboratory, LANL, the U.S. Government, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __ParSplice__Common__
#define __ParSplice__Common__
#include <stdio.h>
#include <vector>
#include <list>
#include <deque>
#include <memory>
#include <atomic>
#include <future>
#include <boost/unordered_map.hpp>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/utility/setup/settings.hpp>
#include <boost/log/utility/setup/from_settings.hpp>
#include <boost/format.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/timer/timer.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/discrete_distribution.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <boost/random/uniform_01.hpp>
#include <mpi.h>
#include "ParSpliceTypes.h"
#define PARSPLICE_TASKS 1 << 1
#define PARSPLICE_SEGMENTS 1 << 2
namespace logging = boost::log;
namespace sinks = boost::log::sinks;
namespace src = boost::log::sources;
namespace expr = boost::log::expressions;
namespace attrs = boost::log::attributes;
namespace keywords = boost::log::keywords;
using namespace logging::trivial;
#define BUFFER_SIZE 100000000
void imerge(parsplice::TrajDB &source, parsplice::TrajDB &supp);
void merge(parsplice::TrajDB &source, parsplice::TrajDB &supp);
void serializeDB(parsplice::TrajDB &source, std::vector<unsigned int> &v, int &i);
parsplice::TrajDB deserializeDB(std::vector<unsigned int> &v, int &i);
struct Placeholder{
boost::timer::cpu_timer timer;
int producerID;
parsplice::TrajDB db;
Placeholder(){
timer.start();
};
};
void logTrajDB(boost::log::sources::severity_logger< boost::log::trivial::severity_level > lg, parsplice::TrajDB &db);
void logTrajDBTr(boost::log::sources::severity_logger< boost::log::trivial::severity_level > lg, parsplice::TrajDB &db);
#endif /* defined(__ParSplice__Common__) */
/*
Copyright (c) 2016, Los Alamos National Security, LLC
All rights reserved.
Copyright 2016. Los Alamos National Security, LLC. This software was produced under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National Laboratory (LANL), which is operated by Los Alamos National Security, LLC for the U.S. Department of Energy. The U.S. Government has rights to use, reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to produce derivative works, such modified software should be clearly marked, so as not to confuse it with the version available from LANL.
Additionally, redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of Los Alamos National Security, LLC, Los Alamos National Laboratory, LANL, the U.S. Government, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ParSplice_ParSpliceTypes_h
#define ParSplice_ParSpliceTypes_h
#include <stdio.h>
#include <vector>
#include <list>
#include <deque>
#include <memory>
#include <atomic>
#include <future>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/unordered_collections_save_imp.hpp>
#include <boost/serialization/unordered_collections_load_imp.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/unordered_map.hpp>
#include <boost/serialization/unordered_set.hpp>
#include <boost/serialization/deque.hpp>
#include <boost/serialization/list.hpp>
namespace parsplice{
typedef unsigned Label;
class AbstractSpinLock {
public:
virtual void lock()=0;
virtual void unlock()=0;
};
class SpinLock : public AbstractSpinLock {
std::atomic_flag locked = ATOMIC_FLAG_INIT ;
public:
void lock() {
while (locked.test_and_set(std::memory_order_acquire)) { ; }
}
void unlock() {
locked.clear(std::memory_order_release);
}
};
class NoSpinLock : public AbstractSpinLock{
public:
void lock(){};
void unlock(){};
};
struct Visit{
friend class boost::serialization::access;
Label label;
unsigned int duration;
Visit(){
duration=0;
};
void serialize(std::vector<unsigned int> &v, int &i){
v[i++]=(*this).label;
v[i++]=(*this).duration;
};
void deserialize(std::vector<unsigned int> &v, int &i){
(*this).label=v[i++];
(*this).duration=v[i++];
};
template<class Archive>
void serialize(Archive & ar, const unsigned int version){
ar & label;
ar & duration;
};
};
struct Trajectory{
friend class boost::serialization::access;
Trajectory(){
(*this).length=0;
};
void clear(){
visits.clear();
length=0;
index=0;
};
//append a visit to a trajectory. Extends the last visit if possible
void appendVisit(Visit &v, bool extend=true){
(*this).length+=v.duration;
if( extend and !(*this).empty() and (*this).back().label==v.label ){
//extend the last visit
(*this).back().duration+=v.duration;
return;
}
//new visit
(*this).visits.push_back(v);
};
//splice two trajectories
bool splice(Trajectory &t){
//do not splice empty trajectories
if( (*this).empty() or t.empty() ){
return false;
}
//splice only if the beginning and end match
if( (*this).back().label == t.front().label ){
(*this).back().duration+=t.front().duration;
t.visits.pop_front();
(*this).visits.splice((*this).visits.end(), t.visits);
(*this).length+=t.length;
//consume t
t.visits.clear();
t.length=0;
return true;
}
//do nothing
return false;
};
void serialize(std::vector<unsigned int> &v, int &i){
v[i++]=(*this).index;
v[i++]=(*this).visits.size();
for(std::list<Visit>::iterator it=(*this).visits.begin();it!=(*this).visits.end();it++){
it->serialize(v,i);
}
};
void deserialize(std::vector<unsigned int> &v, int &i){
(*this).length=0;
(*this).visits.clear();
(*this).index=v[i++];
unsigned int nVisits=v[i++];
for(int ii=0;ii<nVisits;ii++){
Visit vis;
vis.deserialize(v,i);
(*this).length+=vis.duration;
(*this).visits.push_back(vis);
}
};
bool empty(){
return visits.size()==0;
};
Visit& back(){
return visits.back();
};
Visit& front(){
return visits.front();
};
std::list<Visit> visits;
unsigned int length;
unsigned int index;
template<class Archive>
void serialize(Archive & ar, const unsigned int version){
ar & visits;
ar & length;
ar & index;
};
};
typedef boost::unordered_map< Label, std::deque<Trajectory> > TrajDB;
typedef uint8_t Rdt;
typedef std::vector<Rdt> Rd;
class AbstractParSpliceWorkerDriver{
public:
virtual void generateSegment(parsplice::Label &label, Rd &ref, Rd &hot, parsplice::Trajectory &traj)=0;
virtual void ref(parsplice::Label &label, parsplice::Rd &ref)=0;
};
}
namespace boost {
namespace serialization {
template<class Archive, class Type, class Key, class Hash, class Compare, class Allocator >
inline void save(
Archive & ar,
const boost::unordered_map<Key, Type, Hash, Compare, Allocator> &t,
const unsigned int /* file_version */
){
boost::serialization::stl::save_unordered_collection(ar, t);
}
template<class Archive, class Type, class Key, class Hash, class Compare, class Allocator >
inline void load(
Archive & ar,
boost::unordered_map<Key, Type, Hash, Compare, Allocator> &t,
const unsigned int /* file_version */
){
boost::serialization::stl::load_unordered_collection<Archive,boost::unordered_map<Key, Type, Hash, Compare, Allocator>, boost::serialization::stl::archive_input_unordered_map<
Archive,
boost::unordered_map<Key, Type, Hash, Compare, Allocator>
> >(ar,t);
}
// split non-intrusive serialization function member into separate
// non intrusive save/load member functions
template<class Archive, class Type, class Key, class Hash, class Compare, class Allocator >
inline void serialize(
Archive & ar,
boost::unordered_map<Key, Type, Hash, Compare, Allocator> &t,
const unsigned int file_version
){
boost::serialization::split_free(ar, t, file_version);
}
} // serialization
} // namespace boost
#endif
/*
Copyright (c) 2016, Los Alamos National Security, LLC
All rights reserved.
Copyright 2016. Los Alamos National Security, LLC. This software was produced under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National Laboratory (LANL), which is operated by Los Alamos National Security, LLC for the U.S. Department of Energy. The U.S. Government has rights to use, reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to produce derivative works, such modified software should be clearly marked, so as not to confuse it with the version available from LANL.
Additionally, redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of Los Alamos National Security, LLC, Los Alamos National Laboratory, LANL, the U.S. Government, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "Splicer.h"