diff --git a/fastlib/branches/fastlib-stl/fastlib/CMakeLists.txt b/fastlib/branches/fastlib-stl/fastlib/CMakeLists.txt index ebfd56f700..9e748e2d8b 100644 --- a/fastlib/branches/fastlib-stl/fastlib/CMakeLists.txt +++ b/fastlib/branches/fastlib-stl/fastlib/CMakeLists.txt @@ -27,7 +27,7 @@ set(DIRS math mmanager ## not yet par - #thor # requires pthread linking + thor # requires pthread linking tree # sparse ) #!! diff --git a/fastlib/branches/fastlib-stl/fastlib/par/thread.h b/fastlib/branches/fastlib-stl/fastlib/par/thread.h index 9f1ce3293b..b238bd6cb9 100644 --- a/fastlib/branches/fastlib-stl/fastlib/par/thread.h +++ b/fastlib/branches/fastlib-stl/fastlib/par/thread.h @@ -185,7 +185,7 @@ class Thread { * Mutual exclusion lock to protect shared data. */ class Mutex { - FORBID_ACCIDENTAL_COPIES(Mutex); +// FORBID_ACCIDENTAL_COPIES(Mutex); // safe to remove? friend class WaitCondition; public: diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/CMakeLists.txt b/fastlib/branches/fastlib-stl/fastlib/thor/CMakeLists.txt index 48e887dfb8..a5898ac479 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/CMakeLists.txt +++ b/fastlib/branches/fastlib-stl/fastlib/thor/CMakeLists.txt @@ -46,13 +46,13 @@ set(FASTLIB_SRCS ${FASTLIB_SRCS} ${DIR_SRCS} PARENT_SCOPE) #add_dependencies(col base) # depends on base library # test executable -add_executable(allnn_thor - allnn.cc -) +#add_executable(allnn_thor +# allnn.cc +#) # link col_test against col and base libraries -target_link_libraries(allnn_thor - fastlib -) +#target_link_libraries(allnn_thor +# fastlib +#) #add_executable(allnnbfs_thor # allnnbfs.cc diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/blockdev.cc b/fastlib/branches/fastlib-stl/fastlib/thor/blockdev.cc index 3611f284fb..f09dd8cf17 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/blockdev.cc +++ b/fastlib/branches/fastlib-stl/fastlib/thor/blockdev.cc @@ -28,8 +28,10 @@ void RandomAccessFile::Init(const char *fname, BlockDevice::mode_t mode) { DEBUG_ASSERT_MSG(mode == BlockDevice::M_TEMP, "Null filenames are only valid for temporary files."); const char *tmpdir = fx_param_str(fx_root, "tmpdir", "/tmp"); - fname_.InitSprintf("%s/thor_gnp_XXXXXXXXX", tmpdir); - fd_ = mkstemp(fname_.c_str()); +// fname_.InitSprintf("%s/thor_gnp_", tmpdir); + fname = tmpdir; + fname_ += "/thor_gnp_XXXXXXXXX"; // Aren't there only supposed to be 6 Xs? + fd_ = mkstemp(const_cast (fname_.c_str())); } else { int octal_mode; @@ -46,7 +48,7 @@ void RandomAccessFile::Init(const char *fname, BlockDevice::mode_t mode) { } fd_ = open(fname, octal_mode, 0666); - fname_.Copy(fname); + fname_ = fname; } if (mode == BlockDevice::M_TEMP) { diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/blockdev.h b/fastlib/branches/fastlib-stl/fastlib/thor/blockdev.h index b117e24302..1a7ab54365 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/blockdev.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/blockdev.h @@ -9,10 +9,11 @@ #include "../base/base.h" #include "../col/intmap.h" -#include "../col/col_string.h" #include "../fx/fx.h" #include "../par/thread.h" +#include + /** * An abstracted block device. * @@ -248,7 +249,7 @@ class RandomAccessFile { /** The BlockDevice mode of the file. */ mode_t mode_; /** The filename open. */ - String fname_; + std::string fname_; /** Mutex to protect the lseek-read sequence. */ Mutex mutex_; diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/cache.h b/fastlib/branches/fastlib-stl/fastlib/thor/cache.h index 09fc510e5c..230eba6c81 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/cache.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/cache.h @@ -8,6 +8,7 @@ #define THOR_CACHE_H #include "blockdev.h" +#include /** * Handles events associated with a cache pulling blocks in and out of memory. @@ -19,9 +20,9 @@ class BlockHandler { virtual ~BlockHandler() {} /** Save state. */ - virtual void Serialize(ArrayList* data) const = 0; + virtual void Serialize(std::vector* data) const = 0; /** Initialize from state. */ - virtual void Deserialize(const ArrayList& data) = 0; + virtual void Deserialize(const std::vector& data) = 0; /** Initialize a chunk in frozen state. */ virtual void BlockInitFrozen(BlockDevice::blockid_t blockid, BlockDevice::offset_t begin, diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/cachearray.h b/fastlib/branches/fastlib-stl/fastlib/thor/cachearray.h index 855a4e6241..719fb4bcf3 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/cachearray.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/cachearray.h @@ -19,7 +19,7 @@ class CacheArrayBlockHandler : public BlockHandler { FORBID_ACCIDENTAL_COPIES(CacheArrayBlockHandler); private: - ArrayList default_elem_; + std::vector default_elem_; public: CacheArrayBlockHandler() {} @@ -33,9 +33,9 @@ class CacheArrayBlockHandler : public BlockHandler { */ void Init(const T& default_obj); - void Serialize(ArrayList* data) const; + void Serialize(std::vector* data) const; - void Deserialize(const ArrayList& data); + void Deserialize(const std::vector& data); void BlockInitFrozen(BlockDevice::blockid_t blockid, BlockDevice::offset_t begin, BlockDevice::offset_t bytes, char *block); @@ -106,7 +106,7 @@ class CacheArray { unsigned int n_block_elems_mask_; /** The metadatas array. */ - ArrayList metadatas_; + std::vector metadatas_; /** The circular fixed-size FIFO queue of blocks that are locked in memory. */ BlockDevice::blockid_t *fifo_; diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/cachearray_impl.h b/fastlib/branches/fastlib-stl/fastlib/thor/cachearray_impl.h index 22594566a1..3847c37191 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/cachearray_impl.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/cachearray_impl.h @@ -2,18 +2,18 @@ template void CacheArrayBlockHandler::Init(const T& default_obj) { - default_elem_.Init(ot::FrozenSize(default_obj)); + default_elem_.reserve(ot::FrozenSize(default_obj)); ot::Freeze(default_elem_.begin(), default_obj); } template -void CacheArrayBlockHandler::Serialize(ArrayList* data) const { - data->InitCopy(default_elem_); +void CacheArrayBlockHandler::Serialize(std::vector* data) const { + data->assign(default_elem_.begin(), default_elem_.end()); } template -void CacheArrayBlockHandler::Deserialize(const ArrayList& data) { - default_elem_.InitCopy(data); +void CacheArrayBlockHandler::Deserialize(const std::vector& data) { + default_elem_.assign(data.begin(), data.end()); } template @@ -22,7 +22,7 @@ void CacheArrayBlockHandler::BlockInitFrozen(BlockDevice::blockid_t blockid, DEBUG_ASSERT((begin % default_elem_.size()) == 0); index_t elems = bytes / default_elem_.size(); for (index_t i = 0; i < elems; i++) { - mem::CopyBytes(block, default_elem_.begin(), default_elem_.size()); + mem::CopyBytes(block, &default_elem_.front(), default_elem_.size() ); block += default_elem_.size(); } } @@ -54,8 +54,8 @@ void CacheArrayBlockHandler::BlockThaw(BlockDevice::blockid_t blockid, template void CacheArrayBlockHandler::GetDefaultElement(T *default_element_out) { - ArrayList tmp; - tmp.InitCopy(default_elem_); + std::vector tmp; + tmp.assign(default_elem_.begin(), default_elem_.end()); const T* source = ot::SemiThaw(tmp.begin()); ot::InitCopy(default_element_out, *source); } diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/distribcache.cc b/fastlib/branches/fastlib-stl/fastlib/thor/distribcache.cc index d8f375c304..47648c6b68 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/distribcache.cc +++ b/fastlib/branches/fastlib-stl/fastlib/thor/distribcache.cc @@ -95,7 +95,6 @@ void DistributedCache::InitCommon_(int channel_num_in) { n_fifo_locks_ = 0; world_n_fifo_locks_ = 0; - blocks_.Init(); handler_ = NULL; overflow_free_ = -1; @@ -121,7 +120,7 @@ void DistributedCache::InitCache_(size_t total_ram) { } else { DEBUG_ASSERT(n_sets_ * ASSOC * n_block_bytes_ <= total_ram); } - slots_.Init(n_sets_ << LOG_ASSOC); + slots_.reserve(n_sets_ << LOG_ASSOC); } char *DistributedCache::AllocBlock_() { @@ -161,7 +160,7 @@ void DistributedCache::HandleSyncInfo_(const SyncInfo& info) { } void DistributedCache::HandleStatusInformation_( - const ArrayList& statuses) { + const std::vector& statuses) { // This method is only called after a sync. // However, it is possible that some other machines might have started // writing stuff, so we'll have to take this information with a grain of @@ -170,7 +169,7 @@ void DistributedCache::HandleStatusInformation_( if (n_blocks_ != statuses.size()) { n_blocks_ = statuses.size(); - blocks_.Resize(n_blocks_); + blocks_.reserve(n_blocks_); } for (index_t i = 0; i < n_blocks_; i++) { @@ -203,10 +202,10 @@ void DistributedCache::HandleStatusInformation_( } void DistributedCache::ComputeStatusInformation_( - ArrayList *statuses) const { + std::vector *statuses) const { mutex_.Lock(); DEBUG_ASSERT(n_blocks_ == blocks_.size()); - statuses->Init(n_blocks_); + statuses->reserve(n_blocks_); for (index_t i = 0; i < statuses->size(); i++) { BlockStatus *status = &(*statuses)[i]; const BlockMetadata *block = &blocks_[i]; @@ -223,10 +222,10 @@ void DistributedCache::ComputeStatusInformation_( void DistributedCache::BestEffortWriteback(double portion) { mutex_.Lock(); - Slot *slot = slots_.begin(); + std::vector::iterator slot = slots_.begin(); index_t i = slots_.size(); int start_col = math::RoundInt(ASSOC * (1 - portion)); - BlockMetadata *blocks = blocks_.begin(); + std::vector::iterator blocks = blocks_.begin(); // Might want to software-pipeline this loop, because of the really nasty // indirect load going on. @@ -251,9 +250,9 @@ void DistributedCache::BestEffortWriteback(double portion) { void DistributedCache::StartSync() { // We'll assume everything we have locally is no longer valid. mutex_.Lock(); - Slot *slot = slots_.begin(); + std::vector::iterator slot = slots_.begin(); index_t i = slots_.size(); - BlockMetadata *blocks = blocks_.begin(); + std::vector::iterator blocks = blocks_.begin(); size_t unflushed_bytes = 0; DEBUG_ASSERT_MSG(!syncing_, "Called StartSync twice before WaitSync!"); @@ -410,7 +409,7 @@ void DistributedCache::RemoteWrite(blockid_t blockid, if (unlikely(blockid >= n_blocks_)) { n_blocks_ = blockid + 1; // the default constructor for BlockMetadata should mark the block as new - blocks_.Resize(n_blocks_); + blocks_.reserve(n_blocks_); } BlockMetadata *block = &blocks_[blockid]; if (!block->is_owner()) { @@ -450,7 +449,7 @@ BlockDevice::blockid_t DistributedCache::RemoteAllocBlocks( } n_blocks_ = blockid + n_blocks_to_alloc; - blocks_.GrowTo(n_blocks_); + blocks_.resize(n_blocks_, *(new BlockMetadata)); // these blocks are marked as NOT_DIRTY_NEW MarkOwner_(owner, blockid, n_blocks_); @@ -506,7 +505,7 @@ void DistributedCache::HandleRemoteOwner_(blockid_t block, blockid_t end, int new_owner) { mutex_.Lock(); n_blocks_ = std::max(n_blocks_, end); - blocks_.Resize(n_blocks_); + blocks_.reserve(n_blocks_); MarkOwner_(new_owner, block, end); mutex_.Unlock(); } @@ -980,7 +979,8 @@ void DistributedCache::SyncInfo::MergeWith(const SyncInfo& other) { } } if (old_size < other.statuses.size()) { - statuses.Resize(other.statuses.size()); + // WARNING: This is broken! + statuses.reserve(other.statuses.size()); mem::BitCopy(&statuses[old_size], &other.statuses[old_size], statuses.size() - old_size); } diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/distribcache.h b/fastlib/branches/fastlib-stl/fastlib/thor/distribcache.h index 3143fbce84..b85934c387 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/distribcache.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/distribcache.h @@ -7,9 +7,10 @@ #ifndef THOR_DISTRIBCACHE_H #define THOR_DISTRIBCACHE_H -#include "../col/arraylist.h" #include "../col/rangeset.h" +#include + #include "rpc.h" #include "cache.h" #include "blockdev.h" @@ -140,7 +141,7 @@ class DistributedCache : public BlockDevice { * Information the block handler (or "schema") needs to initialize itself * with. */ - ArrayList block_handler_data; + std::vector block_handler_data; OT_DEF(ConfigResponse) { OT_MY_OBJECT(n_block_bytes); @@ -171,7 +172,7 @@ class DistributedCache : public BlockDevice { IoStats net_stats; int64 n_locks; int64 n_fifo_locks; - ArrayList statuses; + std::vector statuses; OT_DEF(SyncInfo) { OT_MY_OBJECT(disk_stats); @@ -458,7 +459,7 @@ class DistributedCache : public BlockDevice { private: /** A block-to-metadata mapping, keeping track of each block's status. */ - ArrayList blocks_; + std::vector blocks_; /** A schema that regards how to freeze, thaw, and initialize blocks. */ BlockHandler *handler_; @@ -466,7 +467,7 @@ class DistributedCache : public BlockDevice { Mutex mutex_; /** The associtive cache. */ - ArrayList slots_; + std::vector slots_; /** The number of cache sets, same as slots_.size() / ASSOC. */ unsigned n_sets_; @@ -693,7 +694,7 @@ class DistributedCache : public BlockDevice { * After a sync point, handles the change in ownership info. * This is one of the most important parts of our coherency mechanisms. */ - void HandleStatusInformation_(const ArrayList& statuses); + void HandleStatusInformation_(const std::vector& statuses); /** * After a sync point, handles synchronization information. */ @@ -701,7 +702,7 @@ class DistributedCache : public BlockDevice { /** * Marks me as owner of blocks I own and marks other blocks as null. */ - void ComputeStatusInformation_(ArrayList* statuses) const; + void ComputeStatusInformation_(std::vector* statuses) const; /** * Tries to grab a block from cache, if it fails, this pulls it from the * proper source by calling HandleMiss_. diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/kdtree.h b/fastlib/branches/fastlib-stl/fastlib/thor/kdtree.h index 2f61179448..884943add1 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/kdtree.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/kdtree.h @@ -19,7 +19,6 @@ #include "../file/textfile.h" #include "../data/dataset.h" #include "../tree/bounds.h" -#include "../col/arraylist.h" #include "../fx/fx.h" /** diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/rbfs.h b/fastlib/branches/fastlib-stl/fastlib/thor/rbfs.h index 1b90312d35..45cd9ad563 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/rbfs.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/rbfs.h @@ -24,7 +24,7 @@ class DualTreeRecursiveBreadth { }; struct Queue { - ArrayList q; + std::vector q; typename GNP::QSummaryResult summary_result; typename GNP::QPostponed postponed; diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/rbfs_impl.h b/fastlib/branches/fastlib-stl/fastlib/thor/rbfs_impl.h index bcc6197b09..046c3e8508 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/rbfs_impl.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/rbfs_impl.h @@ -193,7 +193,7 @@ void DualTreeRecursiveBreadth::DivideReferences_( Queue child_queue; child_queue.Init(param_); - ArrayList summaries; + std::vector summaries; summaries.Init(parent_queue->q.size()); summaries[0].Init(param_); diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/rpc.h b/fastlib/branches/fastlib-stl/fastlib/thor/rpc.h index 1c9bbe7f09..68de6ca1b2 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/rpc.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/rpc.h @@ -11,12 +11,12 @@ #define THOR_RPC_H #include "../base/base.h" +#include #include "blockdev.h" #include "rpc_base.h" #include "rpc_sock.h" -#include "../col/arraylist.h" //-------------------------------------------------------------------------- @@ -209,7 +209,7 @@ class ReduceChannel : public Channel { FORBID_ACCIDENTAL_COPIES(ReduceTransaction); private: - ArrayList received_; + std::vector received_; int n_received_; TData *data_; const TReductor *reductor_; @@ -243,7 +243,7 @@ class ReduceChannel : public Channel { void Init(int channel_num, const TReductor *reductor_in, TData *data_inout) { Transaction::Init(channel_num); reductor_ = reductor_in; - received_.Init(rpc::n_children()); + received_.reserve(rpc::n_children()); for (index_t i = 0; i < received_.size(); i++) { received_[i] = NULL; } diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/rpc_base.h b/fastlib/branches/fastlib-stl/fastlib/thor/rpc_base.h index 2d5be2c8db..15e2ef5c76 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/rpc_base.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/rpc_base.h @@ -8,6 +8,7 @@ #define THOR_RPC_BASE_H #include "../base/base.h" +#include /** * A Message is the fundamental unit of message-passing in our RPC system. @@ -134,7 +135,7 @@ class Transaction { int channel; int transaction_id; }; - ArrayList peers_; + std::vector peers_; public: /** Create a message of a specified size, which you will later Send(). */ diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/rpc_sock.cc b/fastlib/branches/fastlib-stl/fastlib/thor/rpc_sock.cc index 5ff087620a..33d443da6f 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/rpc_sock.cc +++ b/fastlib/branches/fastlib-stl/fastlib/thor/rpc_sock.cc @@ -113,7 +113,6 @@ RpcSockImpl *RpcSockImpl::instance = NULL; void RpcSockImpl::Init() { channels_.Init(); channels_.default_value() = NULL; - unknown_connections_.Init(); live_pings_ = 0; peer_from_fd_.Init(); peer_from_fd_.default_value() = -1; @@ -175,7 +174,7 @@ void RpcSockImpl::Done() { WakeUpPollingLoop(); polling_thread_.WaitStop(); close(listen_fd_); - peers_.Resize(0); // automatically calls their destructors + peers_.clear(); // automatically calls their destructors } } @@ -259,12 +258,13 @@ int RpcSockImpl::AssignTransaction(int peer_num, Transaction *transaction) { peer->outgoing_free = peer->outgoing_freelist[id]; } else { id = peer->outgoing_transactions.size(); - peer->outgoing_transactions.Resize(id + 1); - peer->outgoing_freelist.Resize(id + 1); +// peer->outgoing_transactions.resize(id + 1); +// peer->outgoing_freelist.Resize(id + 1); } //fprintf(stderr, "%d to %d: registering %d\n", rpc::rank(), peer_num, id); DEBUG_ONLY(peer->outgoing_freelist[id] = -1); - peer->outgoing_transactions[id] = transaction; +// peer->outgoing_transactions[id] = transaction; + peer->outgoing_transactions.push_back(transaction); peer->mutex.Unlock(); return id; } @@ -276,7 +276,7 @@ int RpcSockImpl::AssignTransaction(int peer_num, Transaction *transaction) { void RpcSockImpl::CreatePeers_() { - peers_.Init(n_peers_); + peers_.reserve(n_peers_); if (n_peers_ == 1) { Peer *peer = &peers_[0]; @@ -300,8 +300,6 @@ void RpcSockImpl::CalcChildren_() { unsigned((~rank_) & (rank_-1))); int i; - children_.Init(); - // okay, all peers between my rank and my rank + m - 1 are my direct or // indirect children. the ones that have a power of two difference from // me are my direct children. @@ -311,7 +309,7 @@ void RpcSockImpl::CalcChildren_() { while (i > 1) { i /= 2; - children_.PushBack() = rank_ + i; + children_.push_back(rank_ + i); } parent_ = rank_ - ((~rank_) & (rank_-1)) - 1; @@ -370,14 +368,12 @@ void RpcSockImpl::StartPollingThread_() { } void RpcSockImpl::PollingLoop_() { - ArrayList work_items; + std::vector work_items; fd_set read_fds; fd_set write_fds; fd_set error_fds; int initialization_seconds = 0; - work_items.Init(); - while (status_ != STOP) { index_t j = 0; @@ -439,7 +435,7 @@ void RpcSockImpl::PollingLoop_() { unknown_connections_[j++] = unknown_connections_[i]; } } - unknown_connections_.Resize(j); + unknown_connections_.reserve(j); } bool errors_ok = (status_ == STOP) || (status_ == STOP_SYNC); @@ -503,7 +499,7 @@ void RpcSockImpl::PollingLoop_() { // Accept incoming connections int new_fd; while ((new_fd = accept(listen_fd_, NULL, NULL)) >= 0) { - unknown_connections_.PushBack() = new_fd; + unknown_connections_.push_back(new_fd); RegisterReadFd(-1, new_fd); } } @@ -684,8 +680,6 @@ void RpcSockImpl::DeactivateWriteFd(int fd) { RpcSockImpl::Peer::Peer() { incoming_transactions.Init(); incoming_transactions.default_value() = NULL; - outgoing_transactions.Init(); - outgoing_freelist.Init(); outgoing_free = -1; is_pending = false; } @@ -698,7 +692,6 @@ RpcSockImpl::Peer::~Peer() { void Transaction::Init(int channel_in) { // Set up our internal data. channel_ = channel_in; - peers_.Init(); } Message *Transaction::CreateMessage(int peer, size_t size) { @@ -717,11 +710,12 @@ Message *Transaction::CreateMessage(int peer, size_t size) { if (i == peers_.size()) { // We haven't sent or received from this peer, so we need to send the // channel number to it so that the channel can create a new transaction. - peers_.PushBack(); + PeerInfo peer_info; transaction_id = RpcSockImpl::instance->AssignTransaction(peer, this); - peers_[i].peer = peer; - peers_[i].channel = channel(); - peers_[i].transaction_id = transaction_id; + peer_info.peer = peer; + peer_info.channel = channel(); + peer_info.transaction_id = transaction_id; + peers_.push_back(peer_info); } // Create a message we can send! @@ -737,10 +731,11 @@ void Transaction::TransactionHandleNewSender_(Message *message) { // We'll reply to this with channel -1, meaning that it was the other end // who initiated the transaction ID, i.e., the transaction ID lives in // their namespace. - PeerInfo &peer_info = peers_.PushBack(); + PeerInfo peer_info; peer_info.peer = message->peer(); peer_info.channel = -1; peer_info.transaction_id = message->transaction_id(); + peers_.push_back(peer_info); } void Transaction::Send(Message *message) { @@ -753,7 +748,7 @@ void Transaction::Done() { RpcSockImpl::instance->UnregisterTransaction( peers_[i].peer, peers_[i].channel, peers_[i].transaction_id); } - peers_.Clear(); + peers_.clear(); } void Transaction::Done(int peer) { @@ -763,7 +758,7 @@ void Transaction::Done(int peer) { RpcSockImpl::instance->UnregisterTransaction( peers_[i].peer, peers_[i].channel, peers_[i].transaction_id); peers_[i] = peers_[peers_.size()-1]; - peers_.PopBack(); + peers_.pop_back(); break; } } diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/rpc_sock.h b/fastlib/branches/fastlib-stl/fastlib/thor/rpc_sock.h index b228170ece..fe41684f5a 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/rpc_sock.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/rpc_sock.h @@ -9,7 +9,6 @@ #include "rpc_base.h" -#include "../col/arraylist.h" #include "../math/math_lib.h" #include @@ -34,7 +33,7 @@ * be protected by a mutex. */ class SockConnection { - FORBID_ACCIDENTAL_COPIES(SockConnection); + //FORBID_ACCIDENTAL_COPIES(SockConnection); // ok to remove? =/ public: enum { MAGIC = 314159265 }; @@ -188,11 +187,11 @@ class RpcSockImpl { * a non-negative channel number and incoming messages have a negative * channel number. */ - ArrayList outgoing_transactions; + std::vector outgoing_transactions; /** * Free list of outgoing transactions ready for reuse. */ - ArrayList outgoing_freelist; + std::vector outgoing_freelist; /** * An available outgoing transaction, or -1 if none. */ @@ -261,12 +260,12 @@ class RpcSockImpl { int port_; int parent_; - ArrayList children_; + std::vector children_; int listen_fd_; - ArrayList peers_; + std::vector peers_; - ArrayList unknown_connections_; + std::vector unknown_connections_; DenseIntMap channels_; @@ -331,7 +330,7 @@ class RpcSockImpl { int rank() const { return rank_; } int n_peers() const { return n_peers_; } - const ArrayList& children() const { return children_; } + const std::vector& children() const { return children_; } bool is_root() const { return parent_ == rank_; } int parent() const { return parent_; } diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/sched.cc b/fastlib/branches/fastlib-stl/fastlib/thor/sched.cc index f0880977ee..67873a5c77 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/sched.cc +++ b/fastlib/branches/fastlib-stl/fastlib/thor/sched.cc @@ -29,10 +29,10 @@ void RemoteScheduler::Init(int channel, int destination) { } void RemoteScheduler::GetWork( - int rank, ArrayList *work_items) { + int rank, std::vector& work_items) { WorkRequest request; request.operation = WorkRequest::GIVE_ME_WORK; request.rank = rank; Rpc response(channel_, destination_, request); - work_items->InitCopy(response->work_items); + work_items.assign(response->work_items.begin(), response->work_items.end()); } diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/sched.h b/fastlib/branches/fastlib-stl/fastlib/thor/sched.h index b9bcdb8de0..eece5bc655 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/sched.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/sched.h @@ -13,10 +13,11 @@ #include "thortree.h" #include "../col/heap.h" -#include "../col/arraylist.h" #include "../la/uselapack.h" #include "../tree/bounds.h" +#include + //------------------------------------------------------------------------ /** @@ -45,7 +46,7 @@ class SchedulerInterface { * @param rank the rank of the machine requesting work * @param work where the work will be stored */ - virtual void GetWork(int rank, ArrayList *work) = 0; + virtual void GetWork(int rank, std::vector *work) = 0; /** * Report any relevant statistics to fastexec. @@ -75,7 +76,7 @@ class LockedScheduler : public SchedulerInterface { LockedScheduler(SchedulerInterface *inner) : inner_(inner) {} virtual ~LockedScheduler() { delete inner_; } - virtual void GetWork(int rank, ArrayList *work) { + virtual void GetWork(int rank, std::vector *work) { mutex_.Lock(); inner_->GetWork(rank, work); mutex_.Unlock(); @@ -126,7 +127,7 @@ class CentroidScheduler private: CacheArray *tree_; - ArrayList rankes_; + std::vector rankes_; InternalNode *root_; int n_threads_; double granularity_; @@ -157,7 +158,7 @@ class CentroidScheduler return n_grains_; } - virtual void GetWork(int rank_num, ArrayList *work); + virtual void GetWork(int rank_num, std::vector *work); /** * Gets the number of grains that were not assigned to the original machine. @@ -199,7 +200,7 @@ struct WorkRequest { }; struct WorkResponse { - ArrayList work_items; + std::vector work_items; OT_DEF_BASIC(WorkResponse) { OT_MY_OBJECT(work_items); @@ -232,7 +233,7 @@ class RemoteScheduler void Init(int channel, int destination); - void GetWork(int rank, ArrayList *work_items); + void GetWork(int rank, std::vector& work_items); }; //------------------------------------------------------------------------ diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/sched_impl.h b/fastlib/branches/fastlib-stl/fastlib/thor/sched_impl.h index f76b52e289..312b3d3506 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/sched_impl.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/sched_impl.h @@ -52,7 +52,7 @@ void CentroidScheduler::DistributeInitialWork_( } ProcessScheduler *queue = &rankes_[begin_rank]; - ArrayList node_stack; + std::vector node_stack; node_stack.Init(); node_stack.PushBack() = node; @@ -82,7 +82,7 @@ void CentroidScheduler::DistributeInitialWork_( } template -void CentroidScheduler::GetWork(int rank_num, ArrayList *work) { +void CentroidScheduler::GetWork(int rank_num, std::vector *work) { InternalNode *found_node; ProcessScheduler *queue = &rankes_[rank_num]; @@ -133,9 +133,7 @@ void CentroidScheduler::GetWork(int rank_num, ArrayList *work) { n_preferred_++; } - if (found_node == NULL) { - work->Init(); - } else { + if (found_node != NULL) { // Show user-friendly status messages every 5% increment index_t count = found_node->count(); n_assigned_points_ += count; @@ -144,17 +142,17 @@ void CentroidScheduler::GetWork(int rank_num, ArrayList *work) { n_assigned_points_ * 100 / root_->count()); // Mark all children as complete (non-recursive version) - ArrayList stack; - stack.Init(); - stack.PushBack() = found_node; + std::vector stack; + stack.push_back(found_node); while (stack.size() != 0) { InternalNode *c; - stack.PopBackInit(&c); + c = stack.back(); + stack.pop_back(); c->info() = ALL; for (index_t k = 0; k < Node::CARDINALITY; k++) { InternalNode *c_child = c->child(k); if (c_child) { - stack.PushBack() = c_child; + stack.push_back(c_child); } } } @@ -171,12 +169,12 @@ void CentroidScheduler::GetWork(int rank_num, ArrayList *work) { } } - work->Init(1); - Grain *grain = &(*work)[0]; - grain->node_index = found_node->index(); - grain->node_end_index = found_node->end_index(); - grain->point_begin_index = found_node->node().begin(); - grain->point_end_index = found_node->node().end(); + Grain grain; + grain.node_index = found_node->index(); + grain.node_end_index = found_node->end_index(); + grain.point_begin_index = found_node->node().begin(); + grain.point_end_index = found_node->node().end(); + work->push_back(grain); Vector midpoint; found_node->node().bound().CalculateMidpoint(&midpoint); diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/thor_utils_impl.h b/fastlib/branches/fastlib-stl/fastlib/thor/thor_utils_impl.h index 590ba1f326..b16adec3ab 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/thor_utils_impl.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/thor_utils_impl.h @@ -21,11 +21,10 @@ void thor::ThreadedDualTreeSolver::Doit( stats_.Init(); if (n_threads > 1) { - ArrayList threads; - threads.Init(n_threads); + std::vector threads; + threads.resize(n_threads, new WorkerTask(this)); for (index_t i = 0; i < n_threads; i++) { - threads[i].Init(new WorkerTask(this)); // Set these threads to low priority to make sure the network thread // gets full priority. threads[i].Start(Thread::LOW_PRIORITY); @@ -42,7 +41,7 @@ void thor::ThreadedDualTreeSolver::Doit( template void thor::ThreadedDualTreeSolver::ThreadBody_() { while (1) { - ArrayList work; + std::vector work; mutex_.Lock(); work_queue_->GetWork(rank_, &work); diff --git a/fastlib/branches/fastlib-stl/fastlib/thor/thortree.h b/fastlib/branches/fastlib-stl/fastlib/thor/thortree.h index 7d8d1a24cd..b2d25662c8 100644 --- a/fastlib/branches/fastlib-stl/fastlib/thor/thortree.h +++ b/fastlib/branches/fastlib-stl/fastlib/thor/thortree.h @@ -106,7 +106,7 @@ class ThorTreeDecomposition { * The tree decomposition. */ DecompNode *root_; - ArrayList grain_by_owner_; + std::vector grain_by_owner_; OT_DEF(ThorTreeDecomposition) { OT_PTR(root_); @@ -122,7 +122,7 @@ class ThorTreeDecomposition { DEBUG_ASSERT(root_->info().begin_rank == 0); DEBUG_ASSERT(root_->info().end_rank == rpc::n_peers()); DEBUG_ASSERT(root_in != NULL); - grain_by_owner_.Init(rpc::n_peers()); + grain_by_owner_.reserve(rpc::n_peers()); for (int i = 0; i < grain_by_owner_.size(); i++) { grain_by_owner_[i].InitInvalid(); }