repo
stringlengths
1
152
file
stringlengths
15
205
code
stringlengths
0
41.6M
file_length
int64
0
41.6M
avg_line_length
float64
0
1.81M
max_line_length
int64
0
12.7M
extension_type
stringclasses
90 values
null
ceph-main/src/tools/rbd_mirror/leader_watcher/Types.cc
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #include "Types.h" #include "include/ceph_assert.h" #include "include/stringify.h" #include "common/Formatter.h" namespace rbd { namespace mirror { namespace leader_watcher { namespace { class EncodePayloadVisitor : public boost::static_visitor<void> { public: explicit EncodePayloadVisitor(bufferlist &bl) : m_bl(bl) {} template <typename Payload> inline void operator()(const Payload &payload) const { using ceph::encode; encode(static_cast<uint32_t>(Payload::NOTIFY_OP), m_bl); payload.encode(m_bl); } private: bufferlist &m_bl; }; class DecodePayloadVisitor : public boost::static_visitor<void> { public: DecodePayloadVisitor(__u8 version, bufferlist::const_iterator &iter) : m_version(version), m_iter(iter) {} template <typename Payload> inline void operator()(Payload &payload) const { payload.decode(m_version, m_iter); } private: __u8 m_version; bufferlist::const_iterator &m_iter; }; class DumpPayloadVisitor : public boost::static_visitor<void> { public: explicit DumpPayloadVisitor(Formatter *formatter) : m_formatter(formatter) {} template <typename Payload> inline void operator()(const Payload &payload) const { NotifyOp notify_op = Payload::NOTIFY_OP; m_formatter->dump_string("notify_op", stringify(notify_op)); payload.dump(m_formatter); } private: ceph::Formatter *m_formatter; }; } // anonymous namespace void HeartbeatPayload::encode(bufferlist &bl) const { } void HeartbeatPayload::decode(__u8 version, bufferlist::const_iterator &iter) { } void HeartbeatPayload::dump(Formatter *f) const { } void LockAcquiredPayload::encode(bufferlist &bl) const { } void LockAcquiredPayload::decode(__u8 version, bufferlist::const_iterator &iter) { } void LockAcquiredPayload::dump(Formatter *f) const { } void LockReleasedPayload::encode(bufferlist &bl) const { } void LockReleasedPayload::decode(__u8 version, bufferlist::const_iterator &iter) { } void LockReleasedPayload::dump(Formatter *f) const { } void UnknownPayload::encode(bufferlist &bl) const { ceph_abort(); } void UnknownPayload::decode(__u8 version, bufferlist::const_iterator &iter) { } void UnknownPayload::dump(Formatter *f) const { } void NotifyMessage::encode(bufferlist& bl) const { ENCODE_START(1, 1, bl); boost::apply_visitor(EncodePayloadVisitor(bl), payload); ENCODE_FINISH(bl); } void NotifyMessage::decode(bufferlist::const_iterator& iter) { DECODE_START(1, iter); uint32_t notify_op; decode(notify_op, iter); // select the correct payload variant based upon the encoded op switch (notify_op) { case NOTIFY_OP_HEARTBEAT: payload = HeartbeatPayload(); break; case NOTIFY_OP_LOCK_ACQUIRED: payload = LockAcquiredPayload(); break; case NOTIFY_OP_LOCK_RELEASED: payload = LockReleasedPayload(); break; default: payload = UnknownPayload(); break; } apply_visitor(DecodePayloadVisitor(struct_v, iter), payload); DECODE_FINISH(iter); } void NotifyMessage::dump(Formatter *f) const { apply_visitor(DumpPayloadVisitor(f), payload); } void NotifyMessage::generate_test_instances(std::list<NotifyMessage *> &o) { o.push_back(new NotifyMessage(HeartbeatPayload())); o.push_back(new NotifyMessage(LockAcquiredPayload())); o.push_back(new NotifyMessage(LockReleasedPayload())); } std::ostream &operator<<(std::ostream &out, const NotifyOp &op) { switch (op) { case NOTIFY_OP_HEARTBEAT: out << "Heartbeat"; break; case NOTIFY_OP_LOCK_ACQUIRED: out << "LockAcquired"; break; case NOTIFY_OP_LOCK_RELEASED: out << "LockReleased"; break; default: out << "Unknown (" << static_cast<uint32_t>(op) << ")"; break; } return out; } } // namespace leader_watcher } // namespace mirror } // namespace librbd
3,880
22.95679
82
cc
null
ceph-main/src/tools/rbd_mirror/leader_watcher/Types.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef RBD_MIRROR_LEADER_WATCHER_TYPES_H #define RBD_MIRROR_LEADER_WATCHER_TYPES_H #include "include/int_types.h" #include "include/buffer_fwd.h" #include "include/encoding.h" #include <string> #include <vector> #include <boost/variant.hpp> struct Context; namespace ceph { class Formatter; } namespace rbd { namespace mirror { namespace leader_watcher { struct Listener { typedef std::vector<std::string> InstanceIds; virtual ~Listener() { } virtual void post_acquire_handler(Context *on_finish) = 0; virtual void pre_release_handler(Context *on_finish) = 0; virtual void update_leader_handler( const std::string &leader_instance_id) = 0; virtual void handle_instances_added(const InstanceIds& instance_ids) = 0; virtual void handle_instances_removed(const InstanceIds& instance_ids) = 0; }; enum NotifyOp { NOTIFY_OP_HEARTBEAT = 0, NOTIFY_OP_LOCK_ACQUIRED = 1, NOTIFY_OP_LOCK_RELEASED = 2, }; struct HeartbeatPayload { static const NotifyOp NOTIFY_OP = NOTIFY_OP_HEARTBEAT; HeartbeatPayload() { } void encode(bufferlist &bl) const; void decode(__u8 version, bufferlist::const_iterator &iter); void dump(Formatter *f) const; }; struct LockAcquiredPayload { static const NotifyOp NOTIFY_OP = NOTIFY_OP_LOCK_ACQUIRED; LockAcquiredPayload() { } void encode(bufferlist &bl) const; void decode(__u8 version, bufferlist::const_iterator &iter); void dump(Formatter *f) const; }; struct LockReleasedPayload { static const NotifyOp NOTIFY_OP = NOTIFY_OP_LOCK_RELEASED; LockReleasedPayload() { } void encode(bufferlist &bl) const; void decode(__u8 version, bufferlist::const_iterator &iter); void dump(Formatter *f) const; }; struct UnknownPayload { static const NotifyOp NOTIFY_OP = static_cast<NotifyOp>(-1); UnknownPayload() { } void encode(bufferlist &bl) const; void decode(__u8 version, bufferlist::const_iterator &iter); void dump(Formatter *f) const; }; typedef boost::variant<HeartbeatPayload, LockAcquiredPayload, LockReleasedPayload, UnknownPayload> Payload; struct NotifyMessage { NotifyMessage(const Payload &payload = UnknownPayload()) : payload(payload) { } Payload payload; void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator& it); void dump(Formatter *f) const; static void generate_test_instances(std::list<NotifyMessage *> &o); }; WRITE_CLASS_ENCODER(NotifyMessage); std::ostream &operator<<(std::ostream &out, const NotifyOp &op); } // namespace leader_watcher } // namespace mirror } // namespace librbd using rbd::mirror::leader_watcher::encode; using rbd::mirror::leader_watcher::decode; #endif // RBD_MIRROR_LEADER_WATCHER_TYPES_H
2,870
23.330508
79
h
null
ceph-main/src/tools/rbd_mirror/pool_watcher/RefreshImagesRequest.cc
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #include "tools/rbd_mirror/pool_watcher/RefreshImagesRequest.h" #include "common/debug.h" #include "common/errno.h" #include "cls/rbd/cls_rbd_client.h" #include "librbd/Utils.h" #include <map> #define dout_context g_ceph_context #define dout_subsys ceph_subsys_rbd_mirror #undef dout_prefix #define dout_prefix *_dout << "rbd::mirror::pool_watcher::RefreshImagesRequest " \ << this << " " << __func__ << ": " namespace rbd { namespace mirror { namespace pool_watcher { static const uint32_t MAX_RETURN = 1024; using librbd::util::create_rados_callback; template <typename I> void RefreshImagesRequest<I>::send() { m_image_ids->clear(); mirror_image_list(); } template <typename I> void RefreshImagesRequest<I>::mirror_image_list() { dout(10) << dendl; librados::ObjectReadOperation op; librbd::cls_client::mirror_image_list_start(&op, m_start_after, MAX_RETURN); m_out_bl.clear(); librados::AioCompletion *aio_comp = create_rados_callback< RefreshImagesRequest<I>, &RefreshImagesRequest<I>::handle_mirror_image_list>(this); int r = m_remote_io_ctx.aio_operate(RBD_MIRRORING, aio_comp, &op, &m_out_bl); ceph_assert(r == 0); aio_comp->release(); } template <typename I> void RefreshImagesRequest<I>::handle_mirror_image_list(int r) { dout(10) << "r=" << r << dendl; std::map<std::string, std::string> ids; if (r == 0) { auto it = m_out_bl.cbegin(); r = librbd::cls_client::mirror_image_list_finish(&it, &ids); } if (r < 0 && r != -ENOENT) { derr << "failed to list mirrored images: " << cpp_strerror(r) << dendl; finish(r); return; } // store as global -> local image ids for (auto &id : ids) { m_image_ids->emplace(id.second, id.first); } if (ids.size() == MAX_RETURN) { m_start_after = ids.rbegin()->first; mirror_image_list(); return; } finish(0); } template <typename I> void RefreshImagesRequest<I>::finish(int r) { dout(10) << "r=" << r << dendl; m_on_finish->complete(r); delete this; } } // namespace pool_watcher } // namespace mirror } // namespace rbd template class rbd::mirror::pool_watcher::RefreshImagesRequest<librbd::ImageCtx>;
2,281
24.355556
82
cc
null
ceph-main/src/tools/rbd_mirror/pool_watcher/RefreshImagesRequest.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_RBD_MIRROR_POOL_WATCHER_REFRESH_IMAGES_REQUEST_H #define CEPH_RBD_MIRROR_POOL_WATCHER_REFRESH_IMAGES_REQUEST_H #include "include/buffer.h" #include "include/rados/librados.hpp" #include "tools/rbd_mirror/Types.h" #include <string> struct Context; namespace librbd { struct ImageCtx; } namespace rbd { namespace mirror { namespace pool_watcher { template <typename ImageCtxT = librbd::ImageCtx> class RefreshImagesRequest { public: static RefreshImagesRequest *create(librados::IoCtx &remote_io_ctx, ImageIds *image_ids, Context *on_finish) { return new RefreshImagesRequest(remote_io_ctx, image_ids, on_finish); } RefreshImagesRequest(librados::IoCtx &remote_io_ctx, ImageIds *image_ids, Context *on_finish) : m_remote_io_ctx(remote_io_ctx), m_image_ids(image_ids), m_on_finish(on_finish) { } void send(); private: /** * @verbatim * * <start> * | * | /-------------\ * | | | * v v | (more images) * MIRROR_IMAGE_LIST ---/ * | * v * <finish> * * @endverbatim */ librados::IoCtx &m_remote_io_ctx; ImageIds *m_image_ids; Context *m_on_finish; bufferlist m_out_bl; std::string m_start_after; void mirror_image_list(); void handle_mirror_image_list(int r); void finish(int r); }; } // namespace pool_watcher } // namespace mirror } // namespace rbd extern template class rbd::mirror::pool_watcher::RefreshImagesRequest<librbd::ImageCtx>; #endif // CEPH_RBD_MIRROR_POOL_WATCHER_REFRESH_IMAGES_REQUEST_H
1,718
22.22973
88
h
null
ceph-main/src/tools/rbd_mirror/pool_watcher/Types.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_RBD_MIRROR_POOL_WATCHER_TYPES_H #define CEPH_RBD_MIRROR_POOL_WATCHER_TYPES_H #include "tools/rbd_mirror/Types.h" #include <string> namespace rbd { namespace mirror { namespace pool_watcher { struct Listener { virtual ~Listener() { } virtual void handle_update(const std::string &mirror_uuid, ImageIds &&added_image_ids, ImageIds &&removed_image_ids) = 0; }; } // namespace pool_watcher } // namespace mirror } // namespace rbd #endif // CEPH_RBD_MIRROR_POOL_WATCHER_TYPES_H
656
22.464286
70
h
null
ceph-main/src/tools/rbd_mirror/service_daemon/Types.cc
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #include "tools/rbd_mirror/service_daemon/Types.h" #include <iostream> namespace rbd { namespace mirror { namespace service_daemon { std::ostream& operator<<(std::ostream& os, const CalloutLevel& callout_level) { switch (callout_level) { case CALLOUT_LEVEL_INFO: os << "info"; break; case CALLOUT_LEVEL_WARNING: os << "warning"; break; case CALLOUT_LEVEL_ERROR: os << "error"; break; } return os; } } // namespace service_daemon } // namespace mirror } // namespace rbd
609
19.333333
79
cc
null
ceph-main/src/tools/rbd_mirror/service_daemon/Types.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_RBD_MIRROR_SERVICE_DAEMON_TYPES_H #define CEPH_RBD_MIRROR_SERVICE_DAEMON_TYPES_H #include "include/int_types.h" #include <iosfwd> #include <string> #include <boost/variant.hpp> namespace rbd { namespace mirror { namespace service_daemon { typedef uint64_t CalloutId; const uint64_t CALLOUT_ID_NONE {0}; enum CalloutLevel { CALLOUT_LEVEL_INFO, CALLOUT_LEVEL_WARNING, CALLOUT_LEVEL_ERROR }; std::ostream& operator<<(std::ostream& os, const CalloutLevel& callout_level); typedef boost::variant<bool, uint64_t, std::string> AttributeValue; } // namespace service_daemon } // namespace mirror } // namespace rbd #endif // CEPH_RBD_MIRROR_SERVICE_DAEMON_TYPES_H
782
22.029412
78
h
null
ceph-main/src/tools/rbd_nbd/nbd-netlink.h
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * Copyright (C) 2017 Facebook. All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License v2 as published by the Free Software Foundation. * * 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 021110-1307, USA. */ #ifndef _UAPILINUX_NBD_NETLINK_H #define _UAPILINUX_NBD_NETLINK_H #define NBD_GENL_FAMILY_NAME "nbd" #define NBD_GENL_VERSION 0x1 #define NBD_GENL_MCAST_GROUP_NAME "nbd_mc_group" /* Configuration policy attributes, used for CONNECT */ enum { NBD_ATTR_UNSPEC, NBD_ATTR_INDEX, NBD_ATTR_SIZE_BYTES, NBD_ATTR_BLOCK_SIZE_BYTES, NBD_ATTR_TIMEOUT, NBD_ATTR_SERVER_FLAGS, NBD_ATTR_CLIENT_FLAGS, NBD_ATTR_SOCKETS, NBD_ATTR_DEAD_CONN_TIMEOUT, NBD_ATTR_DEVICE_LIST, NBD_ATTR_BACKEND_IDENTIFIER, __NBD_ATTR_MAX, }; #define NBD_ATTR_MAX (__NBD_ATTR_MAX - 1) /* * This is the format for multiple devices with NBD_ATTR_DEVICE_LIST * * [NBD_ATTR_DEVICE_LIST] * [NBD_DEVICE_ITEM] * [NBD_DEVICE_INDEX] * [NBD_DEVICE_CONNECTED] */ enum { NBD_DEVICE_ITEM_UNSPEC, NBD_DEVICE_ITEM, __NBD_DEVICE_ITEM_MAX, }; #define NBD_DEVICE_ITEM_MAX (__NBD_DEVICE_ITEM_MAX - 1) enum { NBD_DEVICE_UNSPEC, NBD_DEVICE_INDEX, NBD_DEVICE_CONNECTED, __NBD_DEVICE_MAX, }; #define NBD_DEVICE_ATTR_MAX (__NBD_DEVICE_MAX - 1) /* * This is the format for multiple sockets with NBD_ATTR_SOCKETS * * [NBD_ATTR_SOCKETS] * [NBD_SOCK_ITEM] * [NBD_SOCK_FD] * [NBD_SOCK_ITEM] * [NBD_SOCK_FD] */ enum { NBD_SOCK_ITEM_UNSPEC, NBD_SOCK_ITEM, __NBD_SOCK_ITEM_MAX, }; #define NBD_SOCK_ITEM_MAX (__NBD_SOCK_ITEM_MAX - 1) enum { NBD_SOCK_UNSPEC, NBD_SOCK_FD, __NBD_SOCK_MAX, }; #define NBD_SOCK_MAX (__NBD_SOCK_MAX - 1) enum { NBD_CMD_UNSPEC, NBD_CMD_CONNECT, NBD_CMD_DISCONNECT, NBD_CMD_RECONFIGURE, NBD_CMD_LINK_DEAD, NBD_CMD_STATUS, __NBD_CMD_MAX, }; #define NBD_CMD_MAX (__NBD_CMD_MAX - 1) #endif /* _UAPILINUX_NBD_NETLINK_H */
2,423
23
68
h
null
ceph-main/src/tools/rbd_nbd/rbd-nbd.cc
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * rbd-nbd - RBD in userspace * * Copyright (C) 2015 - 2016 Kylin Corporation * * Author: Yunchuan Wen <[email protected]> * Li Wang <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #include "acconfig.h" #include "include/int_types.h" #include "include/scope_guard.h" #include <boost/endian/conversion.hpp> #include <libgen.h> #include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <errno.h> #include <fcntl.h> #include <poll.h> #include <string.h> #include <sys/types.h> #include <unistd.h> #include <linux/nbd.h> #include <linux/fs.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <sys/syscall.h> #include "nbd-netlink.h" #include <libnl3/netlink/genl/genl.h> #include <libnl3/netlink/genl/ctrl.h> #include <libnl3/netlink/genl/mngt.h> #include <filesystem> #include <fstream> #include <iostream> #include <memory> #include <regex> #include <boost/algorithm/string/predicate.hpp> #include <boost/lexical_cast.hpp> #include "common/Formatter.h" #include "common/Preforker.h" #include "common/SubProcess.h" #include "common/TextTable.h" #include "common/ceph_argparse.h" #include "common/config.h" #include "common/dout.h" #include "common/errno.h" #include "common/event_socket.h" #include "common/module.h" #include "common/safe_io.h" #include "common/version.h" #include "global/global_init.h" #include "global/signal_handler.h" #include "include/rados/librados.hpp" #include "include/rbd/librbd.hpp" #include "include/stringify.h" #include "include/xlist.h" #include "mon/MonClient.h" #define dout_context g_ceph_context #define dout_subsys ceph_subsys_rbd #undef dout_prefix #define dout_prefix *_dout << "rbd-nbd: " using namespace std; namespace fs = std::filesystem; using boost::endian::big_to_native; using boost::endian::native_to_big; enum Command { None, Map, Unmap, Attach, Detach, List }; struct Config { int nbds_max = 0; int max_part = 255; int io_timeout = -1; int reattach_timeout = 30; bool exclusive = false; bool notrim = false; bool quiesce = false; bool readonly = false; bool set_max_part = false; bool try_netlink = false; bool show_cookie = false; std::string poolname; std::string nsname; std::string imgname; std::string snapname; std::string devpath; std::string quiesce_hook = CMAKE_INSTALL_LIBEXECDIR "/rbd-nbd/rbd-nbd_quiesce"; std::string format; bool pretty_format = false; std::vector<librbd::encryption_format_t> encryption_formats; std::vector<std::string> encryption_passphrase_files; Command command = None; int pid = 0; std::string cookie; uint64_t snapid = CEPH_NOSNAP; std::string image_spec() const { std::string spec = poolname + "/"; if (!nsname.empty()) { spec += nsname + "/"; } spec += imgname; if (!snapname.empty()) { spec += "@" + snapname; } return spec; } }; static void usage() { std::cout << "Usage: rbd-nbd [options] map <image-or-snap-spec> Map image to nbd device\n" << " detach <device|image-or-snap-spec> Detach image from nbd device\n" << " [options] attach <image-or-snap-spec> Attach image to nbd device\n" << " unmap <device|image-or-snap-spec> Unmap nbd device\n" << " [options] list-mapped List mapped nbd devices\n" << "Map and attach options:\n" << " --device <device path> Specify nbd device path (/dev/nbd{num})\n" << " --encryption-format luks|luks1|luks2\n" << " Image encryption format (default: luks)\n" << " --encryption-passphrase-file Path of file containing passphrase for unlocking image encryption\n" << " --exclusive Forbid writes by other clients\n" << " --notrim Turn off trim/discard\n" << " --io-timeout <sec> Set nbd IO timeout\n" << " --max_part <limit> Override for module param max_part\n" << " --nbds_max <limit> Override for module param nbds_max\n" << " --quiesce Use quiesce callbacks\n" << " --quiesce-hook <path> Specify quiesce hook path\n" << " (default: " << Config().quiesce_hook << ")\n" << " --read-only Map read-only\n" << " --reattach-timeout <sec> Set nbd re-attach timeout\n" << " (default: " << Config().reattach_timeout << ")\n" << " --try-netlink Use the nbd netlink interface\n" << " --show-cookie Show device cookie\n" << " --cookie Specify device cookie\n" << " --snap-id <snap-id> Specify snapshot by ID instead of by name\n" << "\n" << "Unmap and detach options:\n" << " --device <device path> Specify nbd device path (/dev/nbd{num})\n" << " --snap-id <snap-id> Specify snapshot by ID instead of by name\n" << "\n" << "List options:\n" << " --format plain|json|xml Output format (default: plain)\n" << " --pretty-format Pretty formatting (json and xml)\n" << std::endl; generic_server_usage(); } static int nbd = -1; static int nbd_index = -1; static EventSocket terminate_event_sock; #define RBD_NBD_BLKSIZE 512UL #define HELP_INFO 1 #define VERSION_INFO 2 static int parse_args(vector<const char*>& args, std::ostream *err_msg, Config *cfg); static int netlink_disconnect(int index); static int netlink_resize(int nbd_index, uint64_t size); static int run_quiesce_hook(const std::string &quiesce_hook, const std::string &devpath, const std::string &command); static std::string get_cookie(const std::string &devpath); class NBDServer { public: uint64_t quiesce_watch_handle = 0; private: int fd; librbd::Image &image; Config *cfg; public: NBDServer(int fd, librbd::Image& image, Config *cfg) : fd(fd) , image(image) , cfg(cfg) , reader_thread(*this, &NBDServer::reader_entry) , writer_thread(*this, &NBDServer::writer_entry) , quiesce_thread(*this, &NBDServer::quiesce_entry) { std::vector<librbd::config_option_t> options; image.config_list(&options); for (auto &option : options) { if ((option.name == std::string("rbd_cache") || option.name == std::string("rbd_cache_writethrough_until_flush")) && option.value == "false") { allow_internal_flush = true; break; } } } Config *get_cfg() const { return cfg; } private: int terminate_event_fd = -1; ceph::mutex disconnect_lock = ceph::make_mutex("NBDServer::DisconnectLocker"); ceph::condition_variable disconnect_cond; std::atomic<bool> terminated = { false }; std::atomic<bool> allow_internal_flush = { false }; struct IOContext { xlist<IOContext*>::item item; NBDServer *server = nullptr; struct nbd_request request; struct nbd_reply reply; bufferlist data; int command = 0; IOContext() : item(this) {} }; friend std::ostream &operator<<(std::ostream &os, const IOContext &ctx); ceph::mutex lock = ceph::make_mutex("NBDServer::Locker"); ceph::condition_variable cond; xlist<IOContext*> io_pending; xlist<IOContext*> io_finished; void io_start(IOContext *ctx) { std::lock_guard l{lock}; io_pending.push_back(&ctx->item); } void io_finish(IOContext *ctx) { std::lock_guard l{lock}; ceph_assert(ctx->item.is_on_list()); ctx->item.remove_myself(); io_finished.push_back(&ctx->item); cond.notify_all(); } IOContext *wait_io_finish() { std::unique_lock l{lock}; cond.wait(l, [this] { return !io_finished.empty() || (io_pending.empty() && terminated); }); if (io_finished.empty()) return NULL; IOContext *ret = io_finished.front(); io_finished.pop_front(); return ret; } void wait_clean() { std::unique_lock l{lock}; cond.wait(l, [this] { return io_pending.empty(); }); while(!io_finished.empty()) { std::unique_ptr<IOContext> free_ctx(io_finished.front()); io_finished.pop_front(); } } void assert_clean() { std::unique_lock l{lock}; ceph_assert(!reader_thread.is_started()); ceph_assert(!writer_thread.is_started()); ceph_assert(io_pending.empty()); ceph_assert(io_finished.empty()); } static void aio_callback(librbd::completion_t cb, void *arg) { librbd::RBD::AioCompletion *aio_completion = reinterpret_cast<librbd::RBD::AioCompletion*>(cb); IOContext *ctx = reinterpret_cast<IOContext *>(arg); int ret = aio_completion->get_return_value(); dout(20) << __func__ << ": " << *ctx << dendl; if (ret == -EINVAL) { // if shrinking an image, a pagecache writeback might reference // extents outside of the range of the new image extents dout(0) << __func__ << ": masking IO out-of-bounds error" << dendl; ctx->data.clear(); ret = 0; } if (ret < 0) { ctx->reply.error = native_to_big<uint32_t>(-ret); } else if ((ctx->command == NBD_CMD_READ) && ret < static_cast<int>(ctx->request.len)) { int pad_byte_count = static_cast<int> (ctx->request.len) - ret; ctx->data.append_zero(pad_byte_count); dout(20) << __func__ << ": " << *ctx << ": Pad byte count: " << pad_byte_count << dendl; ctx->reply.error = native_to_big<uint32_t>(0); } else { ctx->reply.error = native_to_big<uint32_t>(0); } ctx->server->io_finish(ctx); aio_completion->release(); } void reader_entry() { struct pollfd poll_fds[2]; memset(poll_fds, 0, sizeof(struct pollfd) * 2); poll_fds[0].fd = fd; poll_fds[0].events = POLLIN; poll_fds[1].fd = terminate_event_fd; poll_fds[1].events = POLLIN; while (true) { std::unique_ptr<IOContext> ctx(new IOContext()); ctx->server = this; dout(20) << __func__ << ": waiting for nbd request" << dendl; int r = poll(poll_fds, 2, -1); if (r == -1) { if (errno == EINTR) { continue; } r = -errno; derr << "failed to poll nbd: " << cpp_strerror(r) << dendl; goto error; } if ((poll_fds[1].revents & POLLIN) != 0) { dout(0) << __func__ << ": terminate received" << dendl; goto signal; } if ((poll_fds[0].revents & POLLIN) == 0) { dout(20) << __func__ << ": nothing to read" << dendl; continue; } r = safe_read_exact(fd, &ctx->request, sizeof(struct nbd_request)); if (r < 0) { derr << "failed to read nbd request header: " << cpp_strerror(r) << dendl; goto error; } if (ctx->request.magic != htonl(NBD_REQUEST_MAGIC)) { derr << "invalid nbd request header" << dendl; goto signal; } ctx->request.from = big_to_native(ctx->request.from); ctx->request.type = big_to_native(ctx->request.type); ctx->request.len = big_to_native(ctx->request.len); ctx->reply.magic = native_to_big<uint32_t>(NBD_REPLY_MAGIC); memcpy(ctx->reply.handle, ctx->request.handle, sizeof(ctx->reply.handle)); ctx->command = ctx->request.type & 0x0000ffff; dout(20) << *ctx << ": start" << dendl; switch (ctx->command) { case NBD_CMD_DISC: // NBD_DO_IT will return when pipe is closed dout(0) << "disconnect request received" << dendl; goto signal; case NBD_CMD_WRITE: bufferptr ptr(ctx->request.len); r = safe_read_exact(fd, ptr.c_str(), ctx->request.len); if (r < 0) { derr << *ctx << ": failed to read nbd request data: " << cpp_strerror(r) << dendl; goto error; } ctx->data.push_back(ptr); break; } IOContext *pctx = ctx.release(); io_start(pctx); librbd::RBD::AioCompletion *c = new librbd::RBD::AioCompletion(pctx, aio_callback); switch (pctx->command) { case NBD_CMD_WRITE: image.aio_write(pctx->request.from, pctx->request.len, pctx->data, c); break; case NBD_CMD_READ: image.aio_read(pctx->request.from, pctx->request.len, pctx->data, c); break; case NBD_CMD_FLUSH: image.aio_flush(c); allow_internal_flush = true; break; case NBD_CMD_TRIM: image.aio_discard(pctx->request.from, pctx->request.len, c); break; default: derr << *pctx << ": invalid request command" << dendl; c->release(); goto signal; } } error: { int r = netlink_disconnect(nbd_index); if (r == 1) { ioctl(nbd, NBD_DISCONNECT); } } signal: std::lock_guard l{lock}; terminated = true; cond.notify_all(); std::lock_guard disconnect_l{disconnect_lock}; disconnect_cond.notify_all(); dout(20) << __func__ << ": terminated" << dendl; } void writer_entry() { while (true) { dout(20) << __func__ << ": waiting for io request" << dendl; std::unique_ptr<IOContext> ctx(wait_io_finish()); if (!ctx) { dout(20) << __func__ << ": no io requests, terminating" << dendl; goto done; } dout(20) << __func__ << ": got: " << *ctx << dendl; int r = safe_write(fd, &ctx->reply, sizeof(struct nbd_reply)); if (r < 0) { derr << *ctx << ": failed to write reply header: " << cpp_strerror(r) << dendl; goto error; } if (ctx->command == NBD_CMD_READ && ctx->reply.error == htonl(0)) { r = ctx->data.write_fd(fd); if (r < 0) { derr << *ctx << ": failed to write replay data: " << cpp_strerror(r) << dendl; goto error; } } dout(20) << *ctx << ": finish" << dendl; } error: wait_clean(); done: ::shutdown(fd, SHUT_RDWR); dout(20) << __func__ << ": terminated" << dendl; } bool wait_quiesce() { dout(20) << __func__ << dendl; std::unique_lock locker{lock}; cond.wait(locker, [this] { return quiesce || terminated; }); if (terminated) { return false; } dout(20) << __func__ << ": got quiesce request" << dendl; return true; } void wait_unquiesce(std::unique_lock<ceph::mutex> &locker) { dout(20) << __func__ << dendl; cond.wait(locker, [this] { return !quiesce || terminated; }); dout(20) << __func__ << ": got unquiesce request" << dendl; } void wait_inflight_io() { if (!allow_internal_flush) { return; } uint64_t features = 0; image.features(&features); if ((features & RBD_FEATURE_EXCLUSIVE_LOCK) != 0) { bool is_owner = false; image.is_exclusive_lock_owner(&is_owner); if (!is_owner) { return; } } dout(20) << __func__ << dendl; int r = image.flush(); if (r < 0) { derr << "flush failed: " << cpp_strerror(r) << dendl; } } void quiesce_entry() { ceph_assert(cfg->quiesce); while (wait_quiesce()) { int r = run_quiesce_hook(cfg->quiesce_hook, cfg->devpath, "quiesce"); wait_inflight_io(); { std::unique_lock locker{lock}; ceph_assert(quiesce == true); image.quiesce_complete(quiesce_watch_handle, r); if (r < 0) { quiesce = false; continue; } wait_unquiesce(locker); } run_quiesce_hook(cfg->quiesce_hook, cfg->devpath, "unquiesce"); } dout(20) << __func__ << ": terminated" << dendl; } class ThreadHelper : public Thread { public: typedef void (NBDServer::*entry_func)(); private: NBDServer &server; entry_func func; public: ThreadHelper(NBDServer &_server, entry_func _func) :server(_server) ,func(_func) {} protected: void* entry() override { (server.*func)(); return NULL; } } reader_thread, writer_thread, quiesce_thread; bool started = false; bool quiesce = false; public: void start() { if (!started) { dout(10) << __func__ << ": starting" << dendl; started = true; terminate_event_fd = eventfd(0, EFD_NONBLOCK); ceph_assert(terminate_event_fd > 0); int r = terminate_event_sock.init(terminate_event_fd, EVENT_SOCKET_TYPE_EVENTFD); ceph_assert(r >= 0); reader_thread.create("rbd_reader"); writer_thread.create("rbd_writer"); if (cfg->quiesce) { quiesce_thread.create("rbd_quiesce"); } } } void wait_for_disconnect() { if (!started) return; std::unique_lock l{disconnect_lock}; disconnect_cond.wait(l); } void notify_quiesce() { dout(10) << __func__ << dendl; ceph_assert(cfg->quiesce); std::unique_lock locker{lock}; ceph_assert(quiesce == false); quiesce = true; cond.notify_all(); } void notify_unquiesce() { dout(10) << __func__ << dendl; ceph_assert(cfg->quiesce); std::unique_lock locker{lock}; ceph_assert(quiesce == true); quiesce = false; cond.notify_all(); } ~NBDServer() { if (started) { dout(10) << __func__ << ": terminating" << dendl; terminate_event_sock.notify(); reader_thread.join(); writer_thread.join(); if (cfg->quiesce) { quiesce_thread.join(); } assert_clean(); close(terminate_event_fd); started = false; } } }; std::ostream &operator<<(std::ostream &os, const NBDServer::IOContext &ctx) { os << "[" << std::hex << big_to_native(*((uint64_t *)ctx.request.handle)); switch (ctx.command) { case NBD_CMD_WRITE: os << " WRITE "; break; case NBD_CMD_READ: os << " READ "; break; case NBD_CMD_FLUSH: os << " FLUSH "; break; case NBD_CMD_TRIM: os << " TRIM "; break; case NBD_CMD_DISC: os << " DISC "; break; default: os << " UNKNOWN(" << ctx.command << ") "; break; } os << ctx.request.from << "~" << ctx.request.len << " " << std::dec << big_to_native(ctx.reply.error) << "]"; return os; } class NBDQuiesceWatchCtx : public librbd::QuiesceWatchCtx { public: NBDQuiesceWatchCtx(NBDServer *server) : server(server) { } void handle_quiesce() override { server->notify_quiesce(); } void handle_unquiesce() override { server->notify_unquiesce(); } private: NBDServer *server; }; class NBDWatchCtx : public librbd::UpdateWatchCtx { private: int fd; int nbd_index; bool use_netlink; librados::IoCtx &io_ctx; librbd::Image &image; unsigned long size; public: NBDWatchCtx(int _fd, int _nbd_index, bool _use_netlink, librados::IoCtx &_io_ctx, librbd::Image &_image, unsigned long _size) : fd(_fd) , nbd_index(_nbd_index) , use_netlink(_use_netlink) , io_ctx(_io_ctx) , image(_image) , size(_size) { } ~NBDWatchCtx() override {} void handle_notify() override { librbd::image_info_t info; if (image.stat(info, sizeof(info)) == 0) { unsigned long new_size = info.size; int ret; if (new_size != size) { dout(5) << "resize detected" << dendl; if (ioctl(fd, BLKFLSBUF, NULL) < 0) derr << "invalidate page cache failed: " << cpp_strerror(errno) << dendl; if (use_netlink) { ret = netlink_resize(nbd_index, new_size); } else { ret = ioctl(fd, NBD_SET_SIZE, new_size); if (ret < 0) derr << "resize failed: " << cpp_strerror(errno) << dendl; } if (!ret) size = new_size; if (ioctl(fd, BLKRRPART, NULL) < 0) { derr << "rescan of partition table failed: " << cpp_strerror(errno) << dendl; } if (image.invalidate_cache() < 0) derr << "invalidate rbd cache failed" << dendl; } } } }; class NBDListIterator { public: bool get(Config *cfg) { while (true) { std::string nbd_path = "/sys/block/nbd" + stringify(m_index); if(access(nbd_path.c_str(), F_OK) != 0) { return false; } *cfg = Config(); cfg->devpath = "/dev/nbd" + stringify(m_index++); int pid; std::ifstream ifs; ifs.open(nbd_path + "/pid", std::ifstream::in); if (!ifs.is_open()) { continue; } ifs >> pid; ifs.close(); // If the rbd-nbd is re-attached the pid may store garbage // here. We are sure this is the case when it is negative or // zero. Then we just try to find the attached process scanning // /proc fs. If it is positive we check the process with this // pid first and if it is not rbd-nbd fallback to searching the // attached process. do { if (pid <= 0) { pid = find_attached(cfg->devpath); if (pid <= 0) { break; } } if (get_mapped_info(pid, cfg) >= 0) { return true; } pid = -1; } while (true); } } private: int m_index = 0; std::map<int, Config> m_mapped_info_cache; int get_mapped_info(int pid, Config *cfg) { ceph_assert(!cfg->devpath.empty()); auto it = m_mapped_info_cache.find(pid); if (it != m_mapped_info_cache.end()) { if (it->second.devpath != cfg->devpath) { return -EINVAL; } *cfg = it->second; return 0; } m_mapped_info_cache[pid] = {}; int r; std::string path = "/proc/" + stringify(pid) + "/comm"; std::ifstream ifs; std::string comm; ifs.open(path.c_str(), std::ifstream::in); if (!ifs.is_open()) return -1; ifs >> comm; if (comm != "rbd-nbd") { return -EINVAL; } ifs.close(); path = "/proc/" + stringify(pid) + "/cmdline"; std::string cmdline; std::vector<const char*> args; ifs.open(path.c_str(), std::ifstream::in); if (!ifs.is_open()) return -1; ifs >> cmdline; if (cmdline.empty()) { return -EINVAL; } for (unsigned i = 0; i < cmdline.size(); i++) { char *arg = &cmdline[i]; if (i == 0) { if (strcmp(basename(arg) , "rbd-nbd") != 0) { return -EINVAL; } } else { args.push_back(arg); } while (cmdline[i] != '\0') { i++; } } std::ostringstream err_msg; Config c; r = parse_args(args, &err_msg, &c); if (r < 0) { return r; } if (c.command != Map && c.command != Attach) { return -ENOENT; } c.pid = pid; m_mapped_info_cache.erase(pid); if (!c.devpath.empty()) { m_mapped_info_cache[pid] = c; if (c.devpath != cfg->devpath) { return -ENOENT; } } else { c.devpath = cfg->devpath; } c.cookie = get_cookie(cfg->devpath); *cfg = c; return 0; } int find_attached(const std::string &devpath) { for (auto &entry : fs::directory_iterator("/proc")) { if (!fs::is_directory(entry.status())) { continue; } int pid; try { pid = boost::lexical_cast<uint64_t>(entry.path().filename().c_str()); } catch (boost::bad_lexical_cast&) { continue; } Config cfg; cfg.devpath = devpath; if (get_mapped_info(pid, &cfg) >=0 && cfg.command == Attach) { return cfg.pid; } } return -1; } }; struct EncryptionOptions { std::vector<librbd::encryption_spec_t> specs; ~EncryptionOptions() { for (auto& spec : specs) { switch (spec.format) { case RBD_ENCRYPTION_FORMAT_LUKS: { auto opts = static_cast<librbd::encryption_luks_format_options_t*>(spec.opts); ceph_memzero_s(opts->passphrase.data(), opts->passphrase.size(), opts->passphrase.size()); delete opts; break; } case RBD_ENCRYPTION_FORMAT_LUKS1: { auto opts = static_cast<librbd::encryption_luks1_format_options_t*>(spec.opts); ceph_memzero_s(opts->passphrase.data(), opts->passphrase.size(), opts->passphrase.size()); delete opts; break; } case RBD_ENCRYPTION_FORMAT_LUKS2: { auto opts = static_cast<librbd::encryption_luks2_format_options_t*>(spec.opts); ceph_memzero_s(opts->passphrase.data(), opts->passphrase.size(), opts->passphrase.size()); delete opts; break; } default: ceph_abort(); } } } }; static std::string get_cookie(const std::string &devpath) { std::string cookie; std::ifstream ifs; std::string path = "/sys/block/" + devpath.substr(sizeof("/dev/") - 1) + "/backend"; ifs.open(path, std::ifstream::in); if (ifs.is_open()) { std::getline(ifs, cookie); ifs.close(); } return cookie; } static int load_module(Config *cfg) { ostringstream param; int ret; if (cfg->nbds_max) param << "nbds_max=" << cfg->nbds_max; if (cfg->max_part) param << " max_part=" << cfg->max_part; if (!access("/sys/module/nbd", F_OK)) { if (cfg->nbds_max || cfg->set_max_part) cerr << "rbd-nbd: ignoring kernel module parameter options: nbd module already loaded" << std::endl; return 0; } ret = module_load("nbd", param.str().c_str()); if (ret < 0) cerr << "rbd-nbd: failed to load nbd kernel module: " << cpp_strerror(-ret) << std::endl; return ret; } static int check_device_size(int nbd_index, unsigned long expected_size) { // There are bugs with some older kernel versions that result in an // overflow for large image sizes. This check is to ensure we are // not affected. unsigned long size = 0; std::string path = "/sys/block/nbd" + stringify(nbd_index) + "/size"; std::ifstream ifs; ifs.open(path.c_str(), std::ifstream::in); if (!ifs.is_open()) { cerr << "rbd-nbd: failed to open " << path << std::endl; return -EINVAL; } ifs >> size; size *= RBD_NBD_BLKSIZE; if (size == 0) { // Newer kernel versions will report real size only after nbd // connect. Assume this is the case and return success. return 0; } if (size != expected_size) { cerr << "rbd-nbd: kernel reported invalid device size (" << size << ", expected " << expected_size << ")" << std::endl; return -EINVAL; } return 0; } static int parse_nbd_index(const std::string& devpath) { int index, ret; ret = sscanf(devpath.c_str(), "/dev/nbd%d", &index); if (ret <= 0) { // mean an early matching failure. But some cases need a negative value. if (ret == 0) ret = -EINVAL; cerr << "rbd-nbd: invalid device path: " << devpath << " (expected /dev/nbd{num})" << std::endl; return ret; } return index; } static int try_ioctl_setup(Config *cfg, int fd, uint64_t size, uint64_t blksize, uint64_t flags) { int index = 0, r; if (cfg->devpath.empty()) { char dev[64]; const char *path = "/sys/module/nbd/parameters/nbds_max"; int nbds_max = -1; if (access(path, F_OK) == 0) { std::ifstream ifs; ifs.open(path, std::ifstream::in); if (ifs.is_open()) { ifs >> nbds_max; ifs.close(); } } while (true) { snprintf(dev, sizeof(dev), "/dev/nbd%d", index); nbd = open(dev, O_RDWR); if (nbd < 0) { if (nbd == -EPERM && nbds_max != -1 && index < (nbds_max-1)) { ++index; continue; } r = nbd; cerr << "rbd-nbd: failed to find unused device" << std::endl; goto done; } r = ioctl(nbd, NBD_SET_SOCK, fd); if (r < 0) { close(nbd); ++index; continue; } cfg->devpath = dev; break; } } else { r = parse_nbd_index(cfg->devpath); if (r < 0) goto done; index = r; nbd = open(cfg->devpath.c_str(), O_RDWR); if (nbd < 0) { r = nbd; cerr << "rbd-nbd: failed to open device: " << cfg->devpath << std::endl; goto done; } r = ioctl(nbd, NBD_SET_SOCK, fd); if (r < 0) { r = -errno; cerr << "rbd-nbd: the device " << cfg->devpath << " is busy" << std::endl; close(nbd); goto done; } } r = ioctl(nbd, NBD_SET_BLKSIZE, blksize); if (r < 0) { r = -errno; cerr << "rbd-nbd: NBD_SET_BLKSIZE failed" << std::endl; goto close_nbd; } r = ioctl(nbd, NBD_SET_SIZE, size); if (r < 0) { cerr << "rbd-nbd: NBD_SET_SIZE failed" << std::endl; r = -errno; goto close_nbd; } ioctl(nbd, NBD_SET_FLAGS, flags); if (cfg->io_timeout >= 0) { r = ioctl(nbd, NBD_SET_TIMEOUT, (unsigned long)cfg->io_timeout); if (r < 0) { r = -errno; cerr << "rbd-nbd: failed to set IO timeout: " << cpp_strerror(r) << std::endl; goto close_nbd; } } dout(10) << "ioctl setup complete for " << cfg->devpath << dendl; nbd_index = index; return 0; close_nbd: if (r < 0) { ioctl(nbd, NBD_CLEAR_SOCK); cerr << "rbd-nbd: failed to map, status: " << cpp_strerror(-r) << std::endl; } close(nbd); done: return r; } static void netlink_cleanup(struct nl_sock *sock) { if (!sock) return; nl_close(sock); nl_socket_free(sock); } static struct nl_sock *netlink_init(int *id) { struct nl_sock *sock; int ret; sock = nl_socket_alloc(); if (!sock) { cerr << "rbd-nbd: Could not allocate netlink socket." << std::endl; return NULL; } ret = genl_connect(sock); if (ret < 0) { cerr << "rbd-nbd: Could not connect netlink socket. Error " << ret << std::endl; goto free_sock; } *id = genl_ctrl_resolve(sock, "nbd"); if (*id < 0) // nbd netlink interface not supported. goto close_sock; return sock; close_sock: nl_close(sock); free_sock: nl_socket_free(sock); return NULL; } static int netlink_disconnect(int index) { struct nl_sock *sock; struct nl_msg *msg; int ret, nl_id; sock = netlink_init(&nl_id); if (!sock) // Try ioctl return 1; nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, genl_handle_msg, NULL); msg = nlmsg_alloc(); if (!msg) { cerr << "rbd-nbd: Could not allocate netlink message." << std::endl; goto free_sock; } if (!genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, nl_id, 0, 0, NBD_CMD_DISCONNECT, 0)) { cerr << "rbd-nbd: Could not setup message." << std::endl; goto nla_put_failure; } NLA_PUT_U32(msg, NBD_ATTR_INDEX, index); ret = nl_send_sync(sock, msg); netlink_cleanup(sock); if (ret < 0) { cerr << "rbd-nbd: netlink disconnect failed: " << nl_geterror(-ret) << std::endl; return -EIO; } return 0; nla_put_failure: nlmsg_free(msg); free_sock: netlink_cleanup(sock); return -EIO; } static int netlink_disconnect_by_path(const std::string& devpath) { int index; index = parse_nbd_index(devpath); if (index < 0) return index; return netlink_disconnect(index); } static int netlink_resize(int nbd_index, uint64_t size) { struct nl_sock *sock; struct nl_msg *msg; int nl_id, ret; sock = netlink_init(&nl_id); if (!sock) { cerr << "rbd-nbd: Netlink interface not supported." << std::endl; return 1; } nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, genl_handle_msg, NULL); msg = nlmsg_alloc(); if (!msg) { cerr << "rbd-nbd: Could not allocate netlink message." << std::endl; goto free_sock; } if (!genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, nl_id, 0, 0, NBD_CMD_RECONFIGURE, 0)) { cerr << "rbd-nbd: Could not setup message." << std::endl; goto free_msg; } NLA_PUT_U32(msg, NBD_ATTR_INDEX, nbd_index); NLA_PUT_U64(msg, NBD_ATTR_SIZE_BYTES, size); ret = nl_send_sync(sock, msg); if (ret < 0) { cerr << "rbd-nbd: netlink resize failed: " << nl_geterror(ret) << std::endl; goto free_sock; } netlink_cleanup(sock); dout(10) << "netlink resize complete for nbd" << nbd_index << dendl; return 0; nla_put_failure: free_msg: nlmsg_free(msg); free_sock: netlink_cleanup(sock); return -EIO; } static int netlink_connect_cb(struct nl_msg *msg, void *arg) { struct genlmsghdr *gnlh = (struct genlmsghdr *)nlmsg_data(nlmsg_hdr(msg)); Config *cfg = (Config *)arg; struct nlattr *msg_attr[NBD_ATTR_MAX + 1]; uint32_t index; int ret; ret = nla_parse(msg_attr, NBD_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); if (ret) { cerr << "rbd-nbd: Unsupported netlink reply" << std::endl; return -NLE_MSGTYPE_NOSUPPORT; } if (!msg_attr[NBD_ATTR_INDEX]) { cerr << "rbd-nbd: netlink connect reply missing device index." << std::endl; return -NLE_MSGTYPE_NOSUPPORT; } index = nla_get_u32(msg_attr[NBD_ATTR_INDEX]); cfg->devpath = "/dev/nbd" + stringify(index); nbd_index = index; return NL_OK; } static int netlink_connect(Config *cfg, struct nl_sock *sock, int nl_id, int fd, uint64_t size, uint64_t flags, bool reconnect) { struct nlattr *sock_attr; struct nlattr *sock_opt; struct nl_msg *msg; int ret; if (reconnect) { dout(10) << "netlink try reconnect for " << cfg->devpath << dendl; nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, genl_handle_msg, NULL); } else { nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, netlink_connect_cb, cfg); } msg = nlmsg_alloc(); if (!msg) { cerr << "rbd-nbd: Could not allocate netlink message." << std::endl; return -ENOMEM; } if (!genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, nl_id, 0, 0, reconnect ? NBD_CMD_RECONFIGURE : NBD_CMD_CONNECT, 0)) { cerr << "rbd-nbd: Could not setup message." << std::endl; goto free_msg; } if (!cfg->devpath.empty()) { ret = parse_nbd_index(cfg->devpath); if (ret < 0) goto free_msg; NLA_PUT_U32(msg, NBD_ATTR_INDEX, ret); if (reconnect) { nbd_index = ret; } } if (cfg->io_timeout >= 0) NLA_PUT_U64(msg, NBD_ATTR_TIMEOUT, cfg->io_timeout); NLA_PUT_U64(msg, NBD_ATTR_SIZE_BYTES, size); NLA_PUT_U64(msg, NBD_ATTR_BLOCK_SIZE_BYTES, RBD_NBD_BLKSIZE); NLA_PUT_U64(msg, NBD_ATTR_SERVER_FLAGS, flags); NLA_PUT_U64(msg, NBD_ATTR_DEAD_CONN_TIMEOUT, cfg->reattach_timeout); if (!cfg->cookie.empty()) NLA_PUT_STRING(msg, NBD_ATTR_BACKEND_IDENTIFIER, cfg->cookie.c_str()); sock_attr = nla_nest_start(msg, NBD_ATTR_SOCKETS); if (!sock_attr) { cerr << "rbd-nbd: Could not init sockets in netlink message." << std::endl; goto free_msg; } sock_opt = nla_nest_start(msg, NBD_SOCK_ITEM); if (!sock_opt) { cerr << "rbd-nbd: Could not init sock in netlink message." << std::endl; goto free_msg; } NLA_PUT_U32(msg, NBD_SOCK_FD, fd); nla_nest_end(msg, sock_opt); nla_nest_end(msg, sock_attr); ret = nl_send_sync(sock, msg); if (ret < 0) { cerr << "rbd-nbd: netlink connect failed: " << nl_geterror(ret) << std::endl; return -EIO; } dout(10) << "netlink connect complete for " << cfg->devpath << dendl; return 0; nla_put_failure: free_msg: nlmsg_free(msg); return -EIO; } static int try_netlink_setup(Config *cfg, int fd, uint64_t size, uint64_t flags, bool reconnect) { struct nl_sock *sock; int nl_id, ret; sock = netlink_init(&nl_id); if (!sock) { cerr << "rbd-nbd: Netlink interface not supported. Using ioctl interface." << std::endl; return 1; } dout(10) << "netlink interface supported." << dendl; ret = netlink_connect(cfg, sock, nl_id, fd, size, flags, reconnect); netlink_cleanup(sock); if (ret != 0) return ret; nbd = open(cfg->devpath.c_str(), O_RDWR); if (nbd < 0) { cerr << "rbd-nbd: failed to open device: " << cfg->devpath << std::endl; return nbd; } return 0; } static int run_quiesce_hook(const std::string &quiesce_hook, const std::string &devpath, const std::string &command) { dout(10) << __func__ << ": " << quiesce_hook << " " << devpath << " " << command << dendl; SubProcess hook(quiesce_hook.c_str(), SubProcess::CLOSE, SubProcess::PIPE, SubProcess::PIPE); hook.add_cmd_args(devpath.c_str(), command.c_str(), NULL); bufferlist err; int r = hook.spawn(); if (r < 0) { err.append("subprocess spawn failed"); } else { err.read_fd(hook.get_stderr(), 16384); r = hook.join(); if (r > 0) { r = -r; } } if (r < 0) { derr << __func__ << ": " << quiesce_hook << " " << devpath << " " << command << " failed: " << err.to_str() << dendl; } else { dout(10) << " succeeded: " << err.to_str() << dendl; } return r; } static void handle_signal(int signum) { ceph_assert(signum == SIGINT || signum == SIGTERM); derr << "*** Got signal " << sig_str(signum) << " ***" << dendl; dout(20) << __func__ << ": " << "notifying terminate" << dendl; ceph_assert(terminate_event_sock.is_valid()); terminate_event_sock.notify(); } static NBDServer *start_server(int fd, librbd::Image& image, Config *cfg) { NBDServer *server; server = new NBDServer(fd, image, cfg); server->start(); init_async_signal_handler(); register_async_signal_handler(SIGHUP, sighup_handler); register_async_signal_handler_oneshot(SIGINT, handle_signal); register_async_signal_handler_oneshot(SIGTERM, handle_signal); return server; } static void run_server(Preforker& forker, NBDServer *server, bool netlink_used) { if (g_conf()->daemonize) { global_init_postfork_finish(g_ceph_context); forker.daemonize(); } if (netlink_used) server->wait_for_disconnect(); else ioctl(nbd, NBD_DO_IT); unregister_async_signal_handler(SIGHUP, sighup_handler); unregister_async_signal_handler(SIGINT, handle_signal); unregister_async_signal_handler(SIGTERM, handle_signal); shutdown_async_signal_handler(); } // Eventually it should be removed when pidfd_open is widely supported. static int wait_for_terminate_legacy(int pid, int timeout) { for (int i = 0; ; i++) { if (kill(pid, 0) == -1) { if (errno == ESRCH) { return 0; } int r = -errno; cerr << "rbd-nbd: kill(" << pid << ", 0) failed: " << cpp_strerror(r) << std::endl; return r; } if (i >= timeout * 2) { break; } usleep(500000); } cerr << "rbd-nbd: waiting for process exit timed out" << std::endl; return -ETIMEDOUT; } // Eventually it should be replaced with glibc' pidfd_open // when it is widely available. #ifdef __NR_pidfd_open static int pidfd_open(pid_t pid, unsigned int flags) { return syscall(__NR_pidfd_open, pid, flags); } #else static int pidfd_open(pid_t pid, unsigned int flags) { errno = ENOSYS; return -1; } #endif static int wait_for_terminate(int pid, int timeout) { int fd = pidfd_open(pid, 0); if (fd == -1) { if (errno == ENOSYS) { return wait_for_terminate_legacy(pid, timeout); } if (errno == ESRCH) { return 0; } int r = -errno; cerr << "rbd-nbd: pidfd_open(" << pid << ") failed: " << cpp_strerror(r) << std::endl; return r; } struct pollfd poll_fds[1]; memset(poll_fds, 0, sizeof(struct pollfd)); poll_fds[0].fd = fd; poll_fds[0].events = POLLIN; int r = poll(poll_fds, 1, timeout * 1000); if (r == -1) { r = -errno; cerr << "rbd-nbd: failed to poll rbd-nbd process: " << cpp_strerror(r) << std::endl; goto done; } else { r = 0; } if ((poll_fds[0].revents & POLLIN) == 0) { cerr << "rbd-nbd: waiting for process exit timed out" << std::endl; r = -ETIMEDOUT; } done: close(fd); return r; } static int do_map(int argc, const char *argv[], Config *cfg, bool reconnect) { int r; librados::Rados rados; librbd::RBD rbd; librados::IoCtx io_ctx; librbd::Image image; int read_only = 0; unsigned long flags; unsigned long size; unsigned long blksize = RBD_NBD_BLKSIZE; bool use_netlink; int fd[2]; librbd::image_info_t info; Preforker forker; NBDServer *server; auto args = argv_to_vec(argc, argv); if (args.empty()) { cerr << argv[0] << ": -h or --help for usage" << std::endl; exit(1); } if (ceph_argparse_need_usage(args)) { usage(); exit(0); } auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_DAEMON, CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS); g_ceph_context->_conf.set_val_or_die("pid_file", ""); if (global_init_prefork(g_ceph_context) >= 0) { std::string err; r = forker.prefork(err); if (r < 0) { cerr << err << std::endl; return r; } if (forker.is_parent()) { if (forker.parent_wait(err) != 0) { return -ENXIO; } return 0; } global_init_postfork_start(g_ceph_context); } common_init_finish(g_ceph_context); global_init_chdir(g_ceph_context); if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) == -1) { r = -errno; goto close_ret; } r = rados.init_with_context(g_ceph_context); if (r < 0) goto close_fd; r = rados.connect(); if (r < 0) goto close_fd; r = rados.ioctx_create(cfg->poolname.c_str(), io_ctx); if (r < 0) goto close_fd; io_ctx.set_namespace(cfg->nsname); r = rbd.open(io_ctx, image, cfg->imgname.c_str()); if (r < 0) goto close_fd; if (cfg->exclusive) { r = image.lock_acquire(RBD_LOCK_MODE_EXCLUSIVE); if (r < 0) { cerr << "rbd-nbd: failed to acquire exclusive lock: " << cpp_strerror(r) << std::endl; goto close_fd; } } if (cfg->snapid != CEPH_NOSNAP) { r = image.snap_set_by_id(cfg->snapid); if (r < 0) { cerr << "rbd-nbd: failed to set snap id: " << cpp_strerror(r) << std::endl; goto close_fd; } } else if (!cfg->snapname.empty()) { r = image.snap_set(cfg->snapname.c_str()); if (r < 0) { cerr << "rbd-nbd: failed to set snap name: " << cpp_strerror(r) << std::endl; goto close_fd; } } if (!cfg->encryption_formats.empty()) { EncryptionOptions encryption_options; encryption_options.specs.reserve(cfg->encryption_formats.size()); for (size_t i = 0; i < cfg->encryption_formats.size(); ++i) { std::ifstream file(cfg->encryption_passphrase_files[i], std::ios::in | std::ios::binary); if (file.fail()) { r = -errno; std::cerr << "rbd-nbd: unable to open passphrase file '" << cfg->encryption_passphrase_files[i] << "': " << cpp_strerror(r) << std::endl; goto close_fd; } std::string passphrase((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); file.close(); switch (cfg->encryption_formats[i]) { case RBD_ENCRYPTION_FORMAT_LUKS: { auto opts = new librbd::encryption_luks_format_options_t{ std::move(passphrase)}; encryption_options.specs.push_back( {RBD_ENCRYPTION_FORMAT_LUKS, opts, sizeof(*opts)}); break; } case RBD_ENCRYPTION_FORMAT_LUKS1: { auto opts = new librbd::encryption_luks1_format_options_t{ .passphrase = std::move(passphrase)}; encryption_options.specs.push_back( {RBD_ENCRYPTION_FORMAT_LUKS1, opts, sizeof(*opts)}); break; } case RBD_ENCRYPTION_FORMAT_LUKS2: { auto opts = new librbd::encryption_luks2_format_options_t{ .passphrase = std::move(passphrase)}; encryption_options.specs.push_back( {RBD_ENCRYPTION_FORMAT_LUKS2, opts, sizeof(*opts)}); break; } default: ceph_abort(); } } r = image.encryption_load2(encryption_options.specs.data(), encryption_options.specs.size()); if (r != 0) { cerr << "rbd-nbd: failed to load encryption: " << cpp_strerror(r) << std::endl; goto close_fd; } // luks2 block size can vary upto 4096, while luks1 always uses 512 // currently we don't have an rbd API for querying the loaded encryption blksize = 4096; } r = image.stat(info, sizeof(info)); if (r < 0) goto close_fd; flags = NBD_FLAG_SEND_FLUSH | NBD_FLAG_HAS_FLAGS; if (!cfg->notrim) { flags |= NBD_FLAG_SEND_TRIM; } if (!cfg->snapname.empty() || cfg->readonly) { flags |= NBD_FLAG_READ_ONLY; read_only = 1; } if (info.size > ULONG_MAX) { r = -EFBIG; cerr << "rbd-nbd: image is too large (" << byte_u_t(info.size) << ", max is " << byte_u_t(ULONG_MAX) << ")" << std::endl; goto close_fd; } size = info.size; r = load_module(cfg); if (r < 0) goto close_fd; server = start_server(fd[1], image, cfg); use_netlink = cfg->try_netlink || reconnect; if (use_netlink) { // generate when the cookie is not supplied at CLI if (!reconnect && cfg->cookie.empty()) { uuid_d uuid_gen; uuid_gen.generate_random(); cfg->cookie = uuid_gen.to_string(); } r = try_netlink_setup(cfg, fd[0], size, flags, reconnect); if (r < 0) { goto free_server; } else if (r == 1) { use_netlink = false; } } if (!use_netlink) { r = try_ioctl_setup(cfg, fd[0], size, blksize, flags); if (r < 0) goto free_server; } r = check_device_size(nbd_index, size); if (r < 0) goto close_nbd; r = ioctl(nbd, BLKROSET, (unsigned long) &read_only); if (r < 0) { r = -errno; goto close_nbd; } { NBDQuiesceWatchCtx quiesce_watch_ctx(server); if (cfg->quiesce) { r = image.quiesce_watch(&quiesce_watch_ctx, &server->quiesce_watch_handle); if (r < 0) { goto close_nbd; } } uint64_t handle; NBDWatchCtx watch_ctx(nbd, nbd_index, use_netlink, io_ctx, image, info.size); r = image.update_watch(&watch_ctx, &handle); if (r < 0) goto close_nbd; std::string cookie; if (use_netlink) { cookie = get_cookie(cfg->devpath); ceph_assert(cookie == cfg->cookie || cookie.empty()); } if (cfg->show_cookie && !cookie.empty()) { cout << cfg->devpath << " " << cookie << std::endl; } else { cout << cfg->devpath << std::endl; } run_server(forker, server, use_netlink); if (cfg->quiesce) { r = image.quiesce_unwatch(server->quiesce_watch_handle); ceph_assert(r == 0); } r = image.update_unwatch(handle); ceph_assert(r == 0); } close_nbd: if (r < 0) { if (use_netlink) { netlink_disconnect(nbd_index); } else { ioctl(nbd, NBD_CLEAR_SOCK); cerr << "rbd-nbd: failed to map, status: " << cpp_strerror(-r) << std::endl; } } close(nbd); free_server: delete server; close_fd: close(fd[0]); close(fd[1]); close_ret: image.close(); io_ctx.close(); rados.shutdown(); forker.exit(r < 0 ? EXIT_FAILURE : 0); // Unreachable; return r; } static int do_detach(Config *cfg) { int r = kill(cfg->pid, SIGTERM); if (r == -1) { r = -errno; cerr << "rbd-nbd: failed to terminate " << cfg->pid << ": " << cpp_strerror(r) << std::endl; return r; } return wait_for_terminate(cfg->pid, cfg->reattach_timeout); } static int do_unmap(Config *cfg) { /* * The netlink disconnect call supports devices setup with netlink or ioctl, * so we always try that first. */ int r = netlink_disconnect_by_path(cfg->devpath); if (r < 0) { return r; } if (r == 1) { int nbd = open(cfg->devpath.c_str(), O_RDWR); if (nbd < 0) { cerr << "rbd-nbd: failed to open device: " << cfg->devpath << std::endl; return nbd; } r = ioctl(nbd, NBD_DISCONNECT); if (r < 0) { cerr << "rbd-nbd: the device is not used" << std::endl; } close(nbd); if (r < 0) { return r; } } if (cfg->pid > 0) { r = wait_for_terminate(cfg->pid, cfg->reattach_timeout); } return 0; } static int parse_imgpath(const std::string &imgpath, Config *cfg, std::ostream *err_msg) { std::regex pattern("^(?:([^/]+)/(?:([^/@]+)/)?)?([^@]+)(?:@([^/@]+))?$"); std::smatch match; if (!std::regex_match(imgpath, match, pattern)) { std::cerr << "rbd-nbd: invalid spec '" << imgpath << "'" << std::endl; return -EINVAL; } if (match[1].matched) { cfg->poolname = match[1]; } if (match[2].matched) { cfg->nsname = match[2]; } cfg->imgname = match[3]; if (match[4].matched) cfg->snapname = match[4]; return 0; } static int do_list_mapped_devices(const std::string &format, bool pretty_format) { bool should_print = false; std::unique_ptr<ceph::Formatter> f; TextTable tbl; if (format == "json") { f.reset(new JSONFormatter(pretty_format)); } else if (format == "xml") { f.reset(new XMLFormatter(pretty_format)); } else if (!format.empty() && format != "plain") { std::cerr << "rbd-nbd: invalid output format: " << format << std::endl; return -EINVAL; } if (f) { f->open_array_section("devices"); } else { tbl.define_column("id", TextTable::LEFT, TextTable::LEFT); tbl.define_column("pool", TextTable::LEFT, TextTable::LEFT); tbl.define_column("namespace", TextTable::LEFT, TextTable::LEFT); tbl.define_column("image", TextTable::LEFT, TextTable::LEFT); tbl.define_column("snap", TextTable::LEFT, TextTable::LEFT); tbl.define_column("device", TextTable::LEFT, TextTable::LEFT); tbl.define_column("cookie", TextTable::LEFT, TextTable::LEFT); } Config cfg; NBDListIterator it; while (it.get(&cfg)) { std::string snap = (cfg.snapid != CEPH_NOSNAP ? "@" + std::to_string(cfg.snapid) : cfg.snapname); if (f) { f->open_object_section("device"); f->dump_int("id", cfg.pid); f->dump_string("pool", cfg.poolname); f->dump_string("namespace", cfg.nsname); f->dump_string("image", cfg.imgname); f->dump_string("snap", snap); f->dump_string("device", cfg.devpath); f->dump_string("cookie", cfg.cookie); f->close_section(); } else { should_print = true; tbl << cfg.pid << cfg.poolname << cfg.nsname << cfg.imgname << (snap.empty() ? "-" : snap) << cfg.devpath << cfg.cookie << TextTable::endrow; } } if (f) { f->close_section(); // devices f->flush(std::cout); } if (should_print) { std::cout << tbl; } return 0; } static bool find_mapped_dev_by_spec(Config *cfg, int skip_pid=-1) { Config c; NBDListIterator it; while (it.get(&c)) { if (c.pid != skip_pid && c.poolname == cfg->poolname && c.nsname == cfg->nsname && c.imgname == cfg->imgname && c.snapname == cfg->snapname && (cfg->devpath.empty() || c.devpath == cfg->devpath) && c.snapid == cfg->snapid) { *cfg = c; return true; } } return false; } static int find_proc_by_dev(Config *cfg) { Config c; NBDListIterator it; while (it.get(&c)) { if (c.devpath == cfg->devpath) { *cfg = c; return true; } } return false; } static int parse_args(vector<const char*>& args, std::ostream *err_msg, Config *cfg) { std::string conf_file_list; std::string cluster; CephInitParameters iparams = ceph_argparse_early_args( args, CEPH_ENTITY_TYPE_CLIENT, &cluster, &conf_file_list); ConfigProxy config{false}; config->name = iparams.name; config->cluster = cluster; if (!conf_file_list.empty()) { config.parse_config_files(conf_file_list.c_str(), nullptr, 0); } else { config.parse_config_files(nullptr, nullptr, 0); } config.parse_env(CEPH_ENTITY_TYPE_CLIENT); config.parse_argv(args); cfg->poolname = config.get_val<std::string>("rbd_default_pool"); std::vector<const char*>::iterator i; std::ostringstream err; std::string arg_value; long long snapid; for (i = args.begin(); i != args.end(); ) { if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) { return HELP_INFO; } else if (ceph_argparse_flag(args, i, "-v", "--version", (char*)NULL)) { return VERSION_INFO; } else if (ceph_argparse_witharg(args, i, &cfg->devpath, "--device", (char *)NULL)) { } else if (ceph_argparse_witharg(args, i, &cfg->io_timeout, err, "--io-timeout", (char *)NULL)) { if (!err.str().empty()) { *err_msg << "rbd-nbd: " << err.str(); return -EINVAL; } if (cfg->io_timeout < 0) { *err_msg << "rbd-nbd: Invalid argument for io-timeout!"; return -EINVAL; } } else if (ceph_argparse_witharg(args, i, &cfg->nbds_max, err, "--nbds_max", (char *)NULL)) { if (!err.str().empty()) { *err_msg << "rbd-nbd: " << err.str(); return -EINVAL; } if (cfg->nbds_max < 0) { *err_msg << "rbd-nbd: Invalid argument for nbds_max!"; return -EINVAL; } } else if (ceph_argparse_witharg(args, i, &cfg->max_part, err, "--max_part", (char *)NULL)) { if (!err.str().empty()) { *err_msg << "rbd-nbd: " << err.str(); return -EINVAL; } if ((cfg->max_part < 0) || (cfg->max_part > 255)) { *err_msg << "rbd-nbd: Invalid argument for max_part(0~255)!"; return -EINVAL; } cfg->set_max_part = true; } else if (ceph_argparse_flag(args, i, "--quiesce", (char *)NULL)) { cfg->quiesce = true; } else if (ceph_argparse_witharg(args, i, &cfg->quiesce_hook, "--quiesce-hook", (char *)NULL)) { } else if (ceph_argparse_flag(args, i, "--read-only", (char *)NULL)) { cfg->readonly = true; } else if (ceph_argparse_witharg(args, i, &cfg->reattach_timeout, err, "--reattach-timeout", (char *)NULL)) { if (!err.str().empty()) { *err_msg << "rbd-nbd: " << err.str(); return -EINVAL; } if (cfg->reattach_timeout < 0) { *err_msg << "rbd-nbd: Invalid argument for reattach-timeout!"; return -EINVAL; } } else if (ceph_argparse_flag(args, i, "--exclusive", (char *)NULL)) { cfg->exclusive = true; } else if (ceph_argparse_flag(args, i, "--notrim", (char *)NULL)) { cfg->notrim = true; } else if (ceph_argparse_witharg(args, i, &cfg->io_timeout, err, "--timeout", (char *)NULL)) { if (!err.str().empty()) { *err_msg << "rbd-nbd: " << err.str(); return -EINVAL; } if (cfg->io_timeout < 0) { *err_msg << "rbd-nbd: Invalid argument for timeout!"; return -EINVAL; } *err_msg << "rbd-nbd: --timeout is deprecated (use --io-timeout)"; } else if (ceph_argparse_witharg(args, i, &cfg->format, err, "--format", (char *)NULL)) { } else if (ceph_argparse_flag(args, i, "--pretty-format", (char *)NULL)) { cfg->pretty_format = true; } else if (ceph_argparse_flag(args, i, "--try-netlink", (char *)NULL)) { cfg->try_netlink = true; } else if (ceph_argparse_flag(args, i, "--show-cookie", (char *)NULL)) { cfg->show_cookie = true; } else if (ceph_argparse_witharg(args, i, &cfg->cookie, "--cookie", (char *)NULL)) { } else if (ceph_argparse_witharg(args, i, &snapid, err, "--snap-id", (char *)NULL)) { if (!err.str().empty()) { *err_msg << "rbd-nbd: " << err.str(); return -EINVAL; } if (snapid < 0) { *err_msg << "rbd-nbd: Invalid argument for snap-id!"; return -EINVAL; } cfg->snapid = snapid; } else if (ceph_argparse_witharg(args, i, &arg_value, "--encryption-format", (char *)NULL)) { if (arg_value == "luks1") { cfg->encryption_formats.push_back(RBD_ENCRYPTION_FORMAT_LUKS1); } else if (arg_value == "luks2") { cfg->encryption_formats.push_back(RBD_ENCRYPTION_FORMAT_LUKS2); } else if (arg_value == "luks") { cfg->encryption_formats.push_back(RBD_ENCRYPTION_FORMAT_LUKS); } else { *err_msg << "rbd-nbd: Invalid encryption format"; return -EINVAL; } } else if (ceph_argparse_witharg(args, i, &arg_value, "--encryption-passphrase-file", (char *)NULL)) { cfg->encryption_passphrase_files.push_back(arg_value); } else { ++i; } } if (cfg->encryption_formats.empty() && !cfg->encryption_passphrase_files.empty()) { cfg->encryption_formats.resize(cfg->encryption_passphrase_files.size(), RBD_ENCRYPTION_FORMAT_LUKS); } if (cfg->encryption_formats.size() != cfg->encryption_passphrase_files.size()) { *err_msg << "rbd-nbd: Encryption formats count does not match " << "passphrase files count"; return -EINVAL; } Command cmd = None; if (args.begin() != args.end()) { if (strcmp(*args.begin(), "map") == 0) { cmd = Map; } else if (strcmp(*args.begin(), "unmap") == 0) { cmd = Unmap; } else if (strcmp(*args.begin(), "attach") == 0) { cmd = Attach; } else if (strcmp(*args.begin(), "detach") == 0) { cmd = Detach; } else if (strcmp(*args.begin(), "list-mapped") == 0) { cmd = List; } else { *err_msg << "rbd-nbd: unknown command: " << *args.begin(); return -EINVAL; } args.erase(args.begin()); } if (cmd == None) { *err_msg << "rbd-nbd: must specify command"; return -EINVAL; } std::string cookie; switch (cmd) { case Attach: if (cfg->devpath.empty()) { *err_msg << "rbd-nbd: must specify device to attach"; return -EINVAL; } // Allowing attach without --cookie option for kernel without // NBD_ATTR_BACKEND_IDENTIFIER support for compatibility cookie = get_cookie(cfg->devpath); if (!cookie.empty()) { if (cfg->cookie.empty()) { *err_msg << "rbd-nbd: must specify cookie to attach"; return -EINVAL; } else if (cookie != cfg->cookie) { *err_msg << "rbd-nbd: cookie mismatch"; return -EINVAL; } } else if (!cfg->cookie.empty()) { *err_msg << "rbd-nbd: kernel does not have cookie support"; return -EINVAL; } [[fallthrough]]; case Map: if (args.begin() == args.end()) { *err_msg << "rbd-nbd: must specify image-or-snap-spec"; return -EINVAL; } if (parse_imgpath(*args.begin(), cfg, err_msg) < 0) { return -EINVAL; } args.erase(args.begin()); break; case Detach: case Unmap: if (args.begin() == args.end()) { *err_msg << "rbd-nbd: must specify nbd device or image-or-snap-spec"; return -EINVAL; } if (boost::starts_with(*args.begin(), "/dev/")) { cfg->devpath = *args.begin(); } else { if (parse_imgpath(*args.begin(), cfg, err_msg) < 0) { return -EINVAL; } } args.erase(args.begin()); break; default: //shut up gcc; break; } if (cfg->snapid != CEPH_NOSNAP && !cfg->snapname.empty()) { *err_msg << "rbd-nbd: use either snapname or snapid, not both"; return -EINVAL; } if (args.begin() != args.end()) { *err_msg << "rbd-nbd: unknown args: " << *args.begin(); return -EINVAL; } cfg->command = cmd; return 0; } static int rbd_nbd(int argc, const char *argv[]) { int r; Config cfg; auto args = argv_to_vec(argc, argv); std::ostringstream err_msg; r = parse_args(args, &err_msg, &cfg); if (r == HELP_INFO) { usage(); return 0; } else if (r == VERSION_INFO) { std::cout << pretty_version_to_str() << std::endl; return 0; } else if (r < 0) { cerr << err_msg.str() << std::endl; return r; } if (!err_msg.str().empty()) { cerr << err_msg.str() << std::endl; } switch (cfg.command) { case Attach: ceph_assert(!cfg.devpath.empty()); if (find_mapped_dev_by_spec(&cfg, getpid())) { cerr << "rbd-nbd: " << cfg.devpath << " has process " << cfg.pid << " connected" << std::endl; return -EBUSY; } [[fallthrough]]; case Map: if (cfg.imgname.empty()) { cerr << "rbd-nbd: image name was not specified" << std::endl; return -EINVAL; } r = do_map(argc, argv, &cfg, cfg.command == Attach); if (r < 0) return -EINVAL; break; case Detach: if (cfg.devpath.empty()) { if (!find_mapped_dev_by_spec(&cfg)) { cerr << "rbd-nbd: " << cfg.image_spec() << " is not mapped" << std::endl; return -ENOENT; } } else if (!find_proc_by_dev(&cfg)) { cerr << "rbd-nbd: no process attached to " << cfg.devpath << " found" << std::endl; return -ENOENT; } r = do_detach(&cfg); if (r < 0) return -EINVAL; break; case Unmap: if (cfg.devpath.empty()) { if (!find_mapped_dev_by_spec(&cfg)) { cerr << "rbd-nbd: " << cfg.image_spec() << " is not mapped" << std::endl; return -ENOENT; } } else if (!find_proc_by_dev(&cfg)) { // still try to send disconnect to the device } r = do_unmap(&cfg); if (r < 0) return -EINVAL; break; case List: r = do_list_mapped_devices(cfg.format, cfg.pretty_format); if (r < 0) return -EINVAL; break; default: usage(); break; } return 0; } int main(int argc, const char *argv[]) { int r = rbd_nbd(argc, argv); if (r < 0) { return EXIT_FAILURE; } return 0; }
62,839
25.270903
116
cc
null
ceph-main/src/tools/rbd_recover_tool/test_rbd_recover_tool.sh
#!/usr/bin/env bash # # Copyright (C) 2015 Ubuntu Kylin # # Author: Min Chen <[email protected]> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Library Public License as published by # the Free Software Foundation; either version 2, 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 Library Public License for more details. # # unit test case for rbd-recover-tool #prepare: # - write config files: config/osd_host, config/mon_host, config/storage_path, config/mds_host if exist mds #step 1. rbd export all images as you need #step 2. stop all ceph services #step 3. use ceph_rbd_recover_tool to recover all images #step 4. compare md5sum of recover image with that of export image who has the same image name ssh_opt="-o ConnectTimeout=1" my_dir=$(dirname "$0") tool_dir=$my_dir #storage_path=$my_dir/config/storage_path mon_host=$my_dir/config/mon_host osd_host=$my_dir/config/osd_host mds_host=$my_dir/config/mds_host test_dir= # `cat $storage_path` export_dir= #$test_dir/export recover_dir= #$test_dir/recover image_names= #$test_dir/image_names online_images= #$test_dir/online_images, all images on ceph rbd pool gen_db= #$test_dir/gen_db, label database if exist pool=rbd pool_id=2 function get_pool_id() { local pool_id_file=/tmp/pool_id_file.$$$$ ceph osd pool stats $pool|head -n 1|awk '{print $4}' >$pool_id_file if [ $? -ne 0 ];then echo "$func: get pool id failed: pool = $pool" rm -f $pool_id_file exit fi pool_id=`cat $pool_id_file` echo "$func: pool_id = $pool_id" rm -f $pool_id_file } function init() { local func="init" if [ $# -eq 0 ];then echo "$func: must input <path> to storage images, enough disk space is good" exit fi if [ ! -s $osd_host ];then echo "$func: config/osd_host not exists or empty" exit fi if [ ! -s $mon_host ];then echo "$func: config/mon_host not exists or empty" exit fi if [ ! -e $mds_host ];then echo "$func: config/mds_host not exists" exit fi test_dir=$1 export_dir=$test_dir/export recover_dir=$test_dir/recover image_names=$test_dir/image_names online_images=$test_dir/online_images gen_db=$test_dir/gen_db trap 'echo "ceph cluster is stopped ..."; exit;' INT ceph -s >/dev/null get_pool_id mkdir -p $test_dir mkdir -p $export_dir mkdir -p $recover_dir rm -rf $export_dir/* rm -rf $recover_dir/* } function do_gen_database() { local func="do_gen_database" if [ -s $gen_db ] && [ `cat $gen_db` = 1 ];then echo "$func: database already existed" exit fi bash $tool_dir/rbd-recover-tool database echo 1 >$gen_db } #check if all ceph processes are stopped function check_ceph_service() { local func="check_ceph_service" local res=`cat $osd_host $mon_host $mds_host|sort -u|tr -d [:blank:]|xargs -n 1 -I @ ssh $ssh_opt @ "ps aux|grep -E \"(ceph-osd|ceph-mon|ceph-mds)\"|grep -v grep"` if [ "$res"x != ""x ];then echo "$func: NOT all ceph services are stopped" return 1 exit fi echo "$func: all ceph services are stopped" return 0 } function stop_ceph() { local func="stop_ceph" #cat osd_host|xargs -n 1 -I @ ssh $ssh_opt @ "killall ceph-osd" while read osd do { osd=`echo $osd|tr -d [:blank:]` if [ "$osd"x = ""x ];then continue fi #ssh $ssh_opt $osd "killall ceph-osd ceph-mon ceph-mds" </dev/null ssh $ssh_opt $osd "killall ceph-osd" </dev/null } & done < $osd_host wait echo "waiting kill all osd ..." sleep 1 #cat $mon_host|xargs -n 1 -I @ ssh $ssh_opt @ "killall ceph-mon ceph-osd ceph-mds" cat $mon_host|xargs -n 1 -I @ ssh $ssh_opt @ "killall ceph-mon" #cat $mds_host|xargs -n 1 -I @ ssh $ssh_opt @ "killall ceph-mds ceph-mon ceph-osd" cat $mds_host|xargs -n 1 -I @ ssh $ssh_opt @ "killall ceph-mds" } function create_image() { local func="create_image" if [ ${#} -lt 3 ];then echo "create_image: parameters: <image_name> <size> <image_format>" exit fi local image_name=$1 local size=$2 local image_format=$3 if [ $image_format -lt 1 ] || [ $image_format -gt 2 ];then echo "$func: image_format must be 1 or 2" exit fi local res=`rbd list|grep -E "^$1$"` echo "$func $image_name ..." if [ "$res"x = ""x ];then rbd -p $pool create $image_name --size $size --image_format $image_format else if [ $image_format -eq 2 ];then rbd snap ls $image_name|tail -n +2|awk '{print $2}'|xargs -n 1 -I % rbd snap unprotect $image_name@% fi rbd snap purge $image_name #rbd rm $image_name rbd -p $pool resize --allow-shrink --size $size $image_name fi } function export_image() { local func="export_image" if [ $# -lt 2 ];then echo "$func: parameters: <image_name> <image_format> [<image_size>]" exit fi local image_name=$1 local format=$(($2)) local size=$(($3)) #MB if [ $format -ne 1 ] && [ $format -ne 2 ];then echo "$func: image format must be 1 or 2" exit fi if [ $size -eq 0 ];then size=24 #MB echo "$func: size = $size" fi local mnt=/rbdfuse mount |grep "rbd-fuse on /rbdfuse" &>/dev/null if [ $? -ne 0 ];then rbd-fuse $mnt fi create_image $image_name $size $format dd conv=notrunc if=/dev/urandom of=$mnt/$image_name bs=4M count=$(($size/4)) local export_image_dir=$export_dir/pool_$pool_id/$image_name mkdir -p $export_image_dir local export_md5_nosnap=$export_image_dir/@md5_nosnap >$export_md5_nosnap local export_image_path=$export_image_dir/$image_name rm -f $export_image_path rbd export $pool/$image_name $export_image_path md5sum $export_image_path |awk '{print $1}' >$export_md5_nosnap } function recover_image() { local func="recover_snapshots" if [ $# -lt 1 ];then echo "$func: parameters: <image_name>" exit fi local image_name=$1 #pool_id=29 local recover_image_dir=$recover_dir/pool_$pool_id/$image_name mkdir -p $recover_image_dir local recover_md5_nosnap=$recover_image_dir/@md5_nosnap >$recover_md5_nosnap local snapshot= bash $tool_dir/rbd-recover-tool recover $pool_id/$image_name $recover_dir md5sum $recover_image_dir/$image_name|awk '{print $1}' >$recover_md5_nosnap } function make_snapshot() { local func="make_snapshot" if [ $# -lt 5 ];then echo "$func: parameters: <ofile> <seek> <count> <snap> <export_image_dir>" exit fi local ofile=$1 local seek=$(($2)) local count=$(($3)) local snap=$4 local export_image_dir=$5 if [ $seek -lt 0 ];then echo "$func: seek can not be minus" exit fi if [ $count -lt 1 ];then echo "$func: count must great than zero" exit fi echo "[$snap] $func ..." echo "$1 $2 $3 $4" rbd snap ls $image_name|grep $snap; local res=$? if [ $res -eq 0 ];then return $res fi dd conv=notrunc if=/dev/urandom of=$ofile bs=1M count=$count seek=$seek 2>/dev/null snapshot=$image_name@$snap rbd snap create $snapshot rm -f $export_image_dir/$snapshot rbd export $pool/$image_name $export_image_dir/$snapshot pushd $export_image_dir >/dev/null md5sum $snapshot >> @md5 popd >/dev/null } function recover_snapshots() { local func="recover_snapshots" if [ $# -lt 1 ];then echo "$func: parameters: <image_name>" exit fi local image_name=$1 #pool_id=29 local recover_image_dir=$recover_dir/pool_$pool_id/$image_name mkdir -p $recover_image_dir local recover_md5=$recover_image_dir/@md5 >$recover_md5 local snapshot= # recover head bash $tool_dir/rbd-recover-tool recover $pool_id/$image_name $recover_dir # recover snapshots for((i=1; i<10; i++)) do snapshot=snap$i bash $tool_dir/rbd-recover-tool recover $pool_id/$image_name@$snapshot $recover_dir pushd $recover_image_dir >/dev/null local chksum=`md5sum $image_name|awk '{print $1}'` echo "$chksum $image_name@$snapshot" >>@md5 popd >/dev/null done } function export_snapshots() { local func="export_snapshots" if [ $# -lt 2 ];then echo "$func: parameters: <image_name> <image_format> [<image_size>]" exit fi local image_name=$1 local format=$(($2)) local size=$(($3)) #MB if [ $format -ne 1 ] && [ $format -ne 2 ];then echo "$func: image format must be 1 or 2" exit fi if [ $size -eq 0 ];then size=24 #MB echo "$func: size = $size" fi local mnt=/rbdfuse mount |grep "rbd-fuse on /rbdfuse" &>/dev/null if [ $? -ne 0 ];then rbd-fuse $mnt fi create_image $image_name $size $format local export_image_dir=$export_dir/pool_$pool_id/$image_name mkdir -p $export_image_dir local export_md5=$export_image_dir/@md5 >$export_md5 # create 9 snapshots # image = {object0, object1, object2, object3, object4, object5, ...} # # snap1 : init/write all objects # snap2 : write object0 # snap3 : write object1 # snap4 : write object2 # snap5 : write object3 # snap6 : write object4 # snap7 : write object5 # snap8 : write object0 # snap9 : write object3 make_snapshot $mnt/$image_name 0 $size snap1 $export_image_dir make_snapshot $mnt/$image_name 0 1 snap2 $export_image_dir make_snapshot $mnt/$image_name 4 1 snap3 $export_image_dir make_snapshot $mnt/$image_name 8 1 snap4 $export_image_dir make_snapshot $mnt/$image_name 12 1 snap5 $export_image_dir make_snapshot $mnt/$image_name 16 1 snap6 $export_image_dir make_snapshot $mnt/$image_name 20 1 snap7 $export_image_dir make_snapshot $mnt/$image_name 1 1 snap8 $export_image_dir make_snapshot $mnt/$image_name 13 1 snap9 $export_image_dir } function check_recover_nosnap() { local func="check_recover_nosnap" if [ $# -lt 3 ];then echo "$func: parameters: <export_md5_file> <recover_md5_file> <image_name>" fi local export_md5=$1 local recover_md5=$2 local image_name=$3 local ifpassed="FAILED" echo "================ < $image_name nosnap > ================" local export_md5sum=`cat $export_md5` local recover_md5sum=`cat $recover_md5` if [ "$export_md5sum"x != ""x ] && [ "$export_md5sum"x = "$recover_md5sum"x ];then ifpassed="PASSED" fi echo "export: $export_md5sum" echo "recover: $recover_md5sum $ifpassed" } function check_recover_snapshots() { local func="check_recover_snapshots" if [ $# -lt 3 ];then echo "$func: parameters: <export_md5_file> <recover_md5_file> <image_name>" fi local export_md5=$1 local recover_md5=$2 local image_name=$3 local ifpassed="FAILED" echo "================ < $image_name snapshots > ================" OIFS=$IFS IFS=$'\n' local export_md5s=(`cat $export_md5`) local recover_md5s=(`cat $recover_md5`) for((i=0; i<9; i++)) do OOIFS=$IFS IFS=$' ' local x=$(($i+1)) snapshot=snap$x local export_arr=(`echo ${export_md5s[$i]}`) local recover_arr=(`echo ${recover_md5s[$i]}`) echo "export: ${export_md5s[$i]}" if [ "${export_arr[1]}"x != ""x ] && [ "${export_arr[1]}"x = "${recover_arr[1]}"x ];then ifpassed="PASSED" fi echo "recover: ${recover_md5s[$i]} $ifpassed" IFS=$OOIFS done IFS=$OIFS } # step 1: export image, snapshot function do_export_nosnap() { export_image image_v1_nosnap 1 export_image image_v2_nosnap 2 } function do_export_snap() { export_snapshots image_v1_snap 1 export_snapshots image_v2_snap 2 } # step 2: stop ceph cluster and gen database function stop_cluster_gen_database() { trap 'echo stop ceph cluster failed; exit;' INT HUP stop_ceph sleep 2 check_ceph_service local res=$? while [ $res -ne 0 ] do stop_ceph sleep 2 check_ceph_service res=$? done echo 0 >$gen_db do_gen_database } # step 3: recover image,snapshot function do_recover_nosnap() { recover_image image_v1_nosnap recover_image image_v2_nosnap } function do_recover_snap() { recover_snapshots image_v1_snap recover_snapshots image_v2_snap } # step 4: check md5sum pair<export_md5sum, recover_md5sum> function do_check_recover_nosnap() { local image1=image_v1_nosnap local image2=image_v2_nosnap local export_md5_1=$export_dir/pool_$pool_id/$image1/@md5_nosnap local export_md5_2=$export_dir/pool_$pool_id/$image2/@md5_nosnap local recover_md5_1=$recover_dir/pool_$pool_id/$image1/@md5_nosnap local recover_md5_2=$recover_dir/pool_$pool_id/$image2/@md5_nosnap check_recover_nosnap $export_md5_1 $recover_md5_1 $image1 check_recover_nosnap $export_md5_2 $recover_md5_2 $image2 } function do_check_recover_snap() { local image1=image_v1_snap local image2=image_v2_snap local export_md5_1=$export_dir/pool_$pool_id/$image1/@md5 local export_md5_2=$export_dir/pool_$pool_id/$image2/@md5 local recover_md5_1=$recover_dir/pool_$pool_id/$image1/@md5 local recover_md5_2=$recover_dir/pool_$pool_id/$image2/@md5 check_recover_snapshots $export_md5_1 $recover_md5_1 $image1 check_recover_snapshots $export_md5_2 $recover_md5_2 $image2 } function test_case_1() { do_export_nosnap stop_cluster_gen_database do_recover_nosnap do_check_recover_nosnap } function test_case_2() { do_export_snap stop_cluster_gen_database do_recover_snap do_check_recover_snap } function test_case_3() { do_export_nosnap do_export_snap stop_cluster_gen_database do_recover_nosnap do_recover_snap do_check_recover_nosnap do_check_recover_snap } init $* test_case_3
13,603
24.053407
165
sh
null
ceph-main/src/tools/rbd_wnbd/rbd_wnbd.cc
/* * rbd-wnbd - RBD in userspace * * Copyright (C) 2020 SUSE LINUX GmbH * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #include <objidl.h> // LOCK_WRITE is also defined by objidl.h, we have to avoid // a collision. #undef LOCK_WRITE #include "include/int_types.h" #include <atomic> #include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <errno.h> #include <sys/types.h> #include <sys/socket.h> #include <unistd.h> #include "wnbd_handler.h" #include "wnbd_wmi.h" #include "rbd_wnbd.h" #include <fstream> #include <memory> #include <regex> #include "common/Formatter.h" #include "common/TextTable.h" #include "common/ceph_argparse.h" #include "common/config.h" #include "common/debug.h" #include "common/dout.h" #include "common/errno.h" #include "common/version.h" #include "common/win32/service.h" #include "common/win32/wstring.h" #include "common/admin_socket_client.h" #include "global/global_init.h" #include "include/uuid.h" #include "include/rados/librados.hpp" #include "include/rbd/librbd.hpp" #include <shellapi.h> #define dout_context g_ceph_context #define dout_subsys ceph_subsys_rbd #undef dout_prefix #define dout_prefix *_dout << "rbd-wnbd: " using namespace std; // Wait 2s before recreating the wmi subscription in case of errors #define WMI_SUBSCRIPTION_RETRY_INTERVAL 2 // SCSI adapter modification events aren't received until the entire polling // interval has elapsed (unlike other WMI classes, such as Msvm_ComputerSystem). // With longer intervals, it even seems to miss events. For this reason, // we're using a relatively short interval but have adapter state monitoring // as an optional feature, mainly used for dev / driver certification purposes. #define WNBD_ADAPTER_WMI_POLL_INTERVAL 2 // Wait for wmi events up to two seconds #define WMI_EVENT_TIMEOUT 2 bool is_process_running(DWORD pid) { HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, pid); DWORD ret = WaitForSingleObject(process, 0); CloseHandle(process); return ret == WAIT_TIMEOUT; } DWORD WNBDActiveDiskIterator::fetch_list( PWNBD_CONNECTION_LIST* conn_list) { DWORD curr_buff_sz = 0; DWORD buff_sz = 0; DWORD err = 0; PWNBD_CONNECTION_LIST tmp_list = NULL; // We're using a loop because other connections may show up by the time // we retry. do { if (tmp_list) free(tmp_list); if (buff_sz) { tmp_list = (PWNBD_CONNECTION_LIST) calloc(1, buff_sz); if (!tmp_list) { derr << "Could not allocate " << buff_sz << " bytes." << dendl; err = ERROR_NOT_ENOUGH_MEMORY; break; } } curr_buff_sz = buff_sz; // If the buffer is too small, the return value is 0 and "BufferSize" // will contain the required size. This is counterintuitive, but // Windows drivers can't return a buffer as well as a non-zero status. err = WnbdList(tmp_list, &buff_sz); if (err) break; } while (curr_buff_sz < buff_sz); if (err) { if (tmp_list) free(tmp_list); } else { *conn_list = tmp_list; } return err; } WNBDActiveDiskIterator::WNBDActiveDiskIterator() { DWORD status = WNBDActiveDiskIterator::fetch_list(&conn_list); switch (status) { case 0: // no error break; case ERROR_OPEN_FAILED: error = -ENOENT; break; default: error = -EINVAL; break; } } WNBDActiveDiskIterator::~WNBDActiveDiskIterator() { if (conn_list) { free(conn_list); conn_list = NULL; } } bool WNBDActiveDiskIterator::get(Config *cfg) { index += 1; *cfg = Config(); if (!conn_list || index >= (int)conn_list->Count) { return false; } auto conn_info = conn_list->Connections[index]; auto conn_props = conn_info.Properties; if (strncmp(conn_props.Owner, RBD_WNBD_OWNER_NAME, WNBD_MAX_OWNER_LENGTH)) { dout(10) << "Ignoring disk: " << conn_props.InstanceName << ". Owner: " << conn_props.Owner << dendl; return this->get(cfg); } error = load_mapping_config_from_registry(conn_props.InstanceName, cfg); if (error) { derr << "Could not load registry disk info for: " << conn_props.InstanceName << ". Error: " << error << dendl; return false; } cfg->disk_number = conn_info.DiskNumber; cfg->serial_number = std::string(conn_props.SerialNumber); cfg->pid = conn_props.Pid; cfg->active = cfg->disk_number > 0 && is_process_running(conn_props.Pid); cfg->wnbd_mapped = true; return true; } RegistryDiskIterator::RegistryDiskIterator() { reg_key = new RegistryKey(g_ceph_context, HKEY_LOCAL_MACHINE, SERVICE_REG_KEY, false); if (!reg_key->hKey) { if (!reg_key->missingKey) error = -EINVAL; return; } if (RegQueryInfoKey(reg_key->hKey, NULL, NULL, NULL, &subkey_count, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) { derr << "Could not query registry key: " << SERVICE_REG_KEY << dendl; error = -EINVAL; return; } } bool RegistryDiskIterator::get(Config *cfg) { index += 1; *cfg = Config(); if (!reg_key->hKey || !subkey_count) { return false; } char subkey_name[MAX_PATH] = {0}; DWORD subkey_name_sz = MAX_PATH; int err = RegEnumKeyEx( reg_key->hKey, index, subkey_name, &subkey_name_sz, NULL, NULL, NULL, NULL); if (err == ERROR_NO_MORE_ITEMS) { return false; } else if (err) { derr << "Could not enumerate registry. Error: " << err << dendl; error = -EINVAL; return false; } if (load_mapping_config_from_registry(subkey_name, cfg)) { error = -EINVAL; return false; }; return true; } // Iterate over all RBD mappings, getting info from the registry and the driver. bool WNBDDiskIterator::get(Config *cfg) { *cfg = Config(); bool found_active = active_iterator.get(cfg); if (found_active) { active_devices.insert(cfg->devpath); return true; } error = active_iterator.get_error(); if (error) { dout(5) << ": WNBD iterator error: " << error << dendl; return false; } while(registry_iterator.get(cfg)) { if (active_devices.find(cfg->devpath) != active_devices.end()) { // Skip active devices that were already yielded. continue; } return true; } error = registry_iterator.get_error(); if (error) { dout(5) << ": Registry iterator error: " << error << dendl; } return false; } int get_exe_path(std::string& path) { char buffer[MAX_PATH]; DWORD err = 0; int ret = GetModuleFileNameA(NULL, buffer, MAX_PATH); if (!ret || ret == MAX_PATH) { err = GetLastError(); derr << "Could not retrieve executable path. " << "Error: " << win32_strerror(err) << dendl; return -EINVAL; } path = buffer; return 0; } std::string get_cli_args() { std::ostringstream cmdline; for (int i=1; i<__argc; i++) { if (i > 1) cmdline << " "; cmdline << std::quoted(__argv[i]); } return cmdline.str(); } int send_map_request(std::string arguments) { dout(15) << __func__ << ": command arguments: " << arguments << dendl; BYTE request_buff[SERVICE_PIPE_BUFFSZ] = { 0 }; ServiceRequest* request = (ServiceRequest*) request_buff; request->command = Connect; arguments.copy( (char*)request->arguments, SERVICE_PIPE_BUFFSZ - FIELD_OFFSET(ServiceRequest, arguments)); ServiceReply reply = { 0 }; DWORD bytes_read = 0; BOOL success = CallNamedPipe( SERVICE_PIPE_NAME, request_buff, SERVICE_PIPE_BUFFSZ, &reply, sizeof(reply), &bytes_read, DEFAULT_MAP_TIMEOUT_MS); if (!success) { DWORD err = GetLastError(); derr << "Could not send device map request. " << "Make sure that the ceph service is running. " << "Error: " << win32_strerror(err) << dendl; return -EINVAL; } if (reply.status) { derr << "The ceph service failed to map the image. " << "Check the log file or pass '-f' (foreground mode) " << "for additional information. " << "Error: " << cpp_strerror(reply.status) << dendl; } return reply.status; } // Spawn a subprocess using the specified "rbd-wnbd" command // arguments. A pipe is passed to the child process, // which will allow it to communicate the mapping status int map_device_using_suprocess(std::string arguments, int timeout_ms) { STARTUPINFO si; PROCESS_INFORMATION pi; char ch; DWORD err = 0, status = 0; int exit_code = 0; std::ostringstream command_line; std::string exe_path; // Windows async IO context OVERLAPPED connect_o, read_o; HANDLE connect_event = NULL, read_event = NULL; // Used for waiting on multiple events that are going to be initialized later. HANDLE wait_events[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE}; DWORD bytes_read = 0; // We may get a command line containing an old pipe handle when // recreating mappings, so we'll have to replace it. std::regex pipe_pattern("([\'\"]?--pipe-name[\'\"]? +[\'\"]?[^ ]+[\'\"]?)"); uuid_d uuid; uuid.generate_random(); std::ostringstream pipe_name; pipe_name << "\\\\.\\pipe\\rbd-wnbd-" << uuid; // Create an unique named pipe to communicate with the child. */ HANDLE pipe_handle = CreateNamedPipe( pipe_name.str().c_str(), PIPE_ACCESS_INBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE | FILE_FLAG_OVERLAPPED, PIPE_WAIT, 1, // Only accept one instance SERVICE_PIPE_BUFFSZ, SERVICE_PIPE_BUFFSZ, SERVICE_PIPE_TIMEOUT_MS, NULL); if (pipe_handle == INVALID_HANDLE_VALUE) { err = GetLastError(); derr << "CreateNamedPipe failed: " << win32_strerror(err) << dendl; exit_code = -ECHILD; goto finally; } connect_event = CreateEvent(0, TRUE, FALSE, NULL); read_event = CreateEvent(0, TRUE, FALSE, NULL); if (!connect_event || !read_event) { err = GetLastError(); derr << "CreateEvent failed: " << win32_strerror(err) << dendl; exit_code = -ECHILD; goto finally; } connect_o.hEvent = connect_event; read_o.hEvent = read_event; status = ConnectNamedPipe(pipe_handle, &connect_o); err = GetLastError(); if (status || err != ERROR_IO_PENDING) { if (status) err = status; derr << "ConnectNamedPipe failed: " << win32_strerror(err) << dendl; exit_code = -ECHILD; goto finally; } err = 0; dout(5) << __func__ << ": command arguments: " << arguments << dendl; // We'll avoid running arbitrary commands, instead using the executable // path of this process (expected to be the full rbd-wnbd.exe path). err = get_exe_path(exe_path); if (err) { exit_code = -EINVAL; goto finally; } command_line << std::quoted(exe_path) << " " << std::regex_replace(arguments, pipe_pattern, "") << " --pipe-name " << pipe_name.str(); dout(5) << __func__ << ": command line: " << command_line.str() << dendl; GetStartupInfo(&si); // Create a detached child if (!CreateProcess(NULL, (char*)command_line.str().c_str(), NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi)) { err = GetLastError(); derr << "CreateProcess failed: " << win32_strerror(err) << dendl; exit_code = -ECHILD; goto finally; } wait_events[0] = connect_event; wait_events[1] = pi.hProcess; status = WaitForMultipleObjects(2, wait_events, FALSE, timeout_ms); switch(status) { case WAIT_OBJECT_0: if (!GetOverlappedResult(pipe_handle, &connect_o, &bytes_read, TRUE)) { err = GetLastError(); derr << "Couldn't establish a connection with the child process. " << "Error: " << win32_strerror(err) << dendl; exit_code = -ECHILD; goto clean_process; } // We have an incoming connection. break; case WAIT_OBJECT_0 + 1: // The process has exited prematurely. goto clean_process; case WAIT_TIMEOUT: derr << "Timed out waiting for child process connection." << dendl; goto clean_process; default: derr << "Failed waiting for child process. Status: " << status << dendl; goto clean_process; } // Block and wait for child to say it is ready. dout(5) << __func__ << ": waiting for child notification." << dendl; if (!ReadFile(pipe_handle, &ch, 1, NULL, &read_o)) { err = GetLastError(); if (err != ERROR_IO_PENDING) { derr << "Receiving child process reply failed with: " << win32_strerror(err) << dendl; exit_code = -ECHILD; goto clean_process; } } wait_events[0] = read_event; wait_events[1] = pi.hProcess; // The RBD daemon is expected to write back right after opening the // pipe. We'll use the same timeout value for now. status = WaitForMultipleObjects(2, wait_events, FALSE, timeout_ms); switch(status) { case WAIT_OBJECT_0: if (!GetOverlappedResult(pipe_handle, &read_o, &bytes_read, TRUE)) { err = GetLastError(); derr << "Receiving child process reply failed with: " << win32_strerror(err) << dendl; exit_code = -ECHILD; goto clean_process; } break; case WAIT_OBJECT_0 + 1: // The process has exited prematurely. goto clean_process; case WAIT_TIMEOUT: derr << "Timed out waiting for child process message." << dendl; goto clean_process; default: derr << "Failed waiting for child process. Status: " << status << dendl; goto clean_process; } dout(5) << __func__ << ": received child notification." << dendl; goto finally; clean_process: if (!is_process_running(pi.dwProcessId)) { GetExitCodeProcess(pi.hProcess, (PDWORD)&exit_code); derr << "Daemon failed with: " << cpp_strerror(exit_code) << dendl; } else { // The process closed the pipe without notifying us or exiting. // This is quite unlikely, but we'll terminate the process. dout(0) << "Terminating unresponsive process." << dendl; TerminateProcess(pi.hProcess, 1); exit_code = -EINVAL; } finally: if (exit_code) derr << "Could not start RBD daemon." << dendl; if (pipe_handle) CloseHandle(pipe_handle); if (connect_event) CloseHandle(connect_event); if (read_event) CloseHandle(read_event); return exit_code; } BOOL WINAPI console_handler_routine(DWORD dwCtrlType) { dout(0) << "Received control signal: " << dwCtrlType << ". Exiting." << dendl; std::unique_lock l{shutdown_lock}; if (handler) handler->shutdown(); return true; } int save_config_to_registry(Config* cfg) { std::string strKey{ SERVICE_REG_KEY }; strKey.append("\\"); strKey.append(cfg->devpath); auto reg_key = RegistryKey( g_ceph_context, HKEY_LOCAL_MACHINE, strKey.c_str(), true); if (!reg_key.hKey) { return -EINVAL; } int ret_val = 0; // Registry writes are immediately available to other processes. // Still, we'll do a flush to ensure that the mapping can be // recreated after a system crash. if (reg_key.set("pid", getpid()) || reg_key.set("devpath", cfg->devpath) || reg_key.set("poolname", cfg->poolname) || reg_key.set("nsname", cfg->nsname) || reg_key.set("imgname", cfg->imgname) || reg_key.set("snapname", cfg->snapname) || reg_key.set("command_line", get_cli_args()) || reg_key.set("persistent", cfg->persistent) || reg_key.set("admin_sock_path", g_conf()->admin_socket) || reg_key.flush()) { ret_val = -EINVAL; } return ret_val; } int remove_config_from_registry(Config* cfg) { std::string strKey{ SERVICE_REG_KEY }; strKey.append("\\"); strKey.append(cfg->devpath); return RegistryKey::remove( g_ceph_context, HKEY_LOCAL_MACHINE, strKey.c_str()); } int load_mapping_config_from_registry(string devpath, Config* cfg) { std::string strKey{ SERVICE_REG_KEY }; strKey.append("\\"); strKey.append(devpath); auto reg_key = RegistryKey( g_ceph_context, HKEY_LOCAL_MACHINE, strKey.c_str(), false); if (!reg_key.hKey) { if (reg_key.missingKey) return -ENOENT; else return -EINVAL; } reg_key.get("devpath", cfg->devpath); reg_key.get("poolname", cfg->poolname); reg_key.get("nsname", cfg->nsname); reg_key.get("imgname", cfg->imgname); reg_key.get("snapname", cfg->snapname); reg_key.get("command_line", cfg->command_line); reg_key.get("persistent", cfg->persistent); reg_key.get("admin_sock_path", cfg->admin_sock_path); return 0; } int restart_registered_mappings( int worker_count, int total_timeout, int image_map_timeout) { Config cfg; WNBDDiskIterator iterator; int r; std::atomic<int> err = 0; dout(0) << "remounting persistent disks" << dendl; int total_timeout_ms = max(total_timeout, total_timeout * 1000); int image_map_timeout_ms = max(image_map_timeout, image_map_timeout * 1000); LARGE_INTEGER start_t, counter_freq; QueryPerformanceFrequency(&counter_freq); QueryPerformanceCounter(&start_t); boost::asio::thread_pool pool(worker_count); while (iterator.get(&cfg)) { if (cfg.command_line.empty()) { derr << "Could not recreate mapping, missing command line: " << cfg.devpath << dendl; err = -EINVAL; continue; } if (cfg.wnbd_mapped) { dout(1) << __func__ << ": device already mapped: " << cfg.devpath << dendl; continue; } if (!cfg.persistent) { dout(1) << __func__ << ": cleaning up non-persistent mapping: " << cfg.devpath << dendl; r = remove_config_from_registry(&cfg); if (r) { derr << __func__ << ": could not clean up non-persistent mapping: " << cfg.devpath << dendl; } continue; } boost::asio::post(pool, [cfg, start_t, counter_freq, total_timeout_ms, image_map_timeout_ms, &err]() { LARGE_INTEGER curr_t, elapsed_ms; QueryPerformanceCounter(&curr_t); elapsed_ms.QuadPart = curr_t.QuadPart - start_t.QuadPart; elapsed_ms.QuadPart *= 1000; elapsed_ms.QuadPart /= counter_freq.QuadPart; int time_left_ms = max( 0, total_timeout_ms - (int)elapsed_ms.QuadPart); time_left_ms = min(image_map_timeout_ms, time_left_ms); if (!time_left_ms) { err = -ETIMEDOUT; return; } dout(1) << "Remapping: " << cfg.devpath << ". Timeout: " << time_left_ms << " ms." << dendl; // We'll try to map all devices and return a non-zero value // if any of them fails. int r = map_device_using_suprocess(cfg.command_line, time_left_ms); if (r) { err = r; derr << "Could not create mapping: " << cfg.devpath << ". Error: " << r << dendl; } else { dout(1) << "Successfully remapped: " << cfg.devpath << dendl; } }); } pool.join(); r = iterator.get_error(); if (r) { derr << "Could not fetch all mappings. Error: " << r << dendl; err = r; } return err; } int disconnect_all_mappings( bool unregister, bool hard_disconnect, int soft_disconnect_timeout, int worker_count) { // Although not generally recommended, soft_disconnect_timeout can be 0, // which means infinite timeout. ceph_assert(soft_disconnect_timeout >= 0); ceph_assert(worker_count > 0); int64_t timeout_ms = soft_disconnect_timeout * 1000; Config cfg; WNBDActiveDiskIterator iterator; int r; std::atomic<int> err = 0; boost::asio::thread_pool pool(worker_count); LARGE_INTEGER start_t, counter_freq; QueryPerformanceFrequency(&counter_freq); QueryPerformanceCounter(&start_t); while (iterator.get(&cfg)) { boost::asio::post(pool, [cfg, start_t, counter_freq, timeout_ms, hard_disconnect, unregister, &err]() mutable { LARGE_INTEGER curr_t, elapsed_ms; QueryPerformanceCounter(&curr_t); elapsed_ms.QuadPart = curr_t.QuadPart - start_t.QuadPart; elapsed_ms.QuadPart *= 1000; elapsed_ms.QuadPart /= counter_freq.QuadPart; int64_t time_left_ms = max((int64_t)0, timeout_ms - elapsed_ms.QuadPart); cfg.hard_disconnect = hard_disconnect || !time_left_ms; cfg.hard_disconnect_fallback = true; cfg.soft_disconnect_timeout = time_left_ms / 1000; dout(1) << "Removing mapping: " << cfg.devpath << ". Timeout: " << cfg.soft_disconnect_timeout << "s. Hard disconnect: " << cfg.hard_disconnect << dendl; int r = do_unmap(&cfg, unregister); if (r) { err = r; derr << "Could not remove mapping: " << cfg.devpath << ". Error: " << r << dendl; } else { dout(1) << "Successfully removed mapping: " << cfg.devpath << dendl; } }); } pool.join(); r = iterator.get_error(); if (r == -ENOENT) { dout(0) << __func__ << ": wnbd adapter unavailable, " << "assuming that no wnbd mappings exist." << dendl; err = 0; } else if (r) { derr << "Could not fetch all mappings. Error: " << r << dendl; err = r; } return err; } class RBDService : public ServiceBase { private: bool hard_disconnect; int soft_disconnect_timeout; int thread_count; int service_start_timeout; int image_map_timeout; bool remap_failure_fatal; bool adapter_monitoring_enabled; std::thread adapter_monitor_thread; ceph::mutex start_lock = ceph::make_mutex("RBDService::StartLocker"); ceph::mutex shutdown_lock = ceph::make_mutex("RBDService::ShutdownLocker"); bool started = false; std::atomic<bool> stop_requsted = false; public: RBDService(bool _hard_disconnect, int _soft_disconnect_timeout, int _thread_count, int _service_start_timeout, int _image_map_timeout, bool _remap_failure_fatal, bool _adapter_monitoring_enabled) : ServiceBase(g_ceph_context) , hard_disconnect(_hard_disconnect) , soft_disconnect_timeout(_soft_disconnect_timeout) , thread_count(_thread_count) , service_start_timeout(_service_start_timeout) , image_map_timeout(_image_map_timeout) , remap_failure_fatal(_remap_failure_fatal) , adapter_monitoring_enabled(_adapter_monitoring_enabled) { } static int execute_command(ServiceRequest* request) { switch(request->command) { case Connect: dout(1) << "Received device connect request. Command line: " << (char*)request->arguments << dendl; // TODO: use the configured service map timeout. // TODO: add ceph.conf options. return map_device_using_suprocess( (char*)request->arguments, DEFAULT_MAP_TIMEOUT_MS); default: dout(1) << "Received unsupported command: " << request->command << dendl; return -ENOSYS; } } static DWORD handle_connection(HANDLE pipe_handle) { PBYTE message[SERVICE_PIPE_BUFFSZ] = { 0 }; DWORD bytes_read = 0, bytes_written = 0; DWORD err = 0; DWORD reply_sz = 0; ServiceReply reply = { 0 }; dout(20) << __func__ << ": Receiving message." << dendl; BOOL success = ReadFile( pipe_handle, message, SERVICE_PIPE_BUFFSZ, &bytes_read, NULL); if (!success || !bytes_read) { err = GetLastError(); derr << "Could not read service command: " << win32_strerror(err) << dendl; goto exit; } dout(20) << __func__ << ": Executing command." << dendl; reply.status = execute_command((ServiceRequest*) message); reply_sz = sizeof(reply); dout(20) << __func__ << ": Sending reply. Status: " << reply.status << dendl; success = WriteFile( pipe_handle, &reply, reply_sz, &bytes_written, NULL); if (!success || reply_sz != bytes_written) { err = GetLastError(); derr << "Could not send service command result: " << win32_strerror(err) << dendl; } exit: dout(20) << __func__ << ": Cleaning up connection." << dendl; FlushFileBuffers(pipe_handle); DisconnectNamedPipe(pipe_handle); CloseHandle(pipe_handle); return err; } // We have to support Windows server 2016. Unix sockets only work on // WS 2019, so we can't use the Ceph admin socket abstraction. // Getting the Ceph admin sockets to work with Windows named pipes // would require quite a few changes. static DWORD accept_pipe_connection() { DWORD err = 0; // We're currently using default ACLs, which grant full control to the // LocalSystem account and administrator as well as the owner. dout(20) << __func__ << ": opening new pipe instance" << dendl; HANDLE pipe_handle = CreateNamedPipe( SERVICE_PIPE_NAME, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, SERVICE_PIPE_BUFFSZ, SERVICE_PIPE_BUFFSZ, SERVICE_PIPE_TIMEOUT_MS, NULL); if (pipe_handle == INVALID_HANDLE_VALUE) { err = GetLastError(); derr << "CreatePipe failed: " << win32_strerror(err) << dendl; return -EINVAL; } dout(20) << __func__ << ": waiting for connections." << dendl; BOOL connected = ConnectNamedPipe(pipe_handle, NULL); if (!connected) { err = GetLastError(); if (err != ERROR_PIPE_CONNECTED) { derr << "Pipe connection failed: " << win32_strerror(err) << dendl; CloseHandle(pipe_handle); return err; } } dout(20) << __func__ << ": Connection received." << dendl; // We'll handle the connection in a separate thread and at the same time // accept a new connection. HANDLE handler_thread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE) handle_connection, pipe_handle, 0, 0); if (!handler_thread) { err = GetLastError(); derr << "Could not start pipe connection handler thread: " << win32_strerror(err) << dendl; CloseHandle(pipe_handle); } else { CloseHandle(handler_thread); } return err; } static int pipe_server_loop(LPVOID arg) { dout(5) << "Accepting admin pipe connections." << dendl; while (1) { // This call will block until a connection is received, which will // then be handled in a separate thread. The function returns, allowing // us to accept another simultaneous connection. accept_pipe_connection(); } return 0; } int create_pipe_server() { HANDLE handler_thread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE) pipe_server_loop, NULL, 0, 0); DWORD err = 0; if (!handler_thread) { err = GetLastError(); derr << "Could not start pipe server: " << win32_strerror(err) << dendl; } else { CloseHandle(handler_thread); } return err; } void monitor_wnbd_adapter() { dout(5) << __func__ << ": initializing COM" << dendl; // Initialize the Windows COM library for this thread. COMBootstrapper com_bootstrapper; HRESULT hres = com_bootstrapper.initialize(); if (FAILED(hres)) { return; } WmiSubscription subscription = subscribe_wnbd_adapter_events( WNBD_ADAPTER_WMI_POLL_INTERVAL); dout(5) << __func__ << ": initializing wmi subscription" << dendl; hres = subscription.initialize(); dout(0) << "monitoring wnbd adapter state changes" << dendl; // The event watcher will wait at most WMI_EVENT_TIMEOUT (2s) // and exit the loop if the service is being stopped. while (!stop_requsted) { IWbemClassObject* object; ULONG returned = 0; if (FAILED(hres)) { derr << "couldn't retrieve wnbd adapter events, wmi hresult: " << hres << ". Reestablishing wmi listener in " << WMI_SUBSCRIPTION_RETRY_INTERVAL << " seconds." << dendl; subscription.close(); Sleep(WMI_SUBSCRIPTION_RETRY_INTERVAL * 1000); dout(20) << "recreating wnbd adapter wmi subscription" << dendl; subscription = subscribe_wnbd_adapter_events( WNBD_ADAPTER_WMI_POLL_INTERVAL); hres = subscription.initialize(); continue; } dout(20) << "fetching wnbd adapter events" << dendl; hres = subscription.next( WMI_EVENT_TIMEOUT * 1000, 1, // we'll process one event at a time &object, &returned); if (!FAILED(hres) && returned) { if (WBEM_S_NO_ERROR == object->InheritsFrom(L"__InstanceCreationEvent")) { dout(0) << "wnbd adapter (re)created, remounting disks" << dendl; restart_registered_mappings( thread_count, service_start_timeout, image_map_timeout); } else if (WBEM_S_NO_ERROR == object->InheritsFrom(L"__InstanceDeletionEvent")) { dout(0) << "wnbd adapter removed" << dendl; // nothing to do here } else if (WBEM_S_NO_ERROR == object->InheritsFrom(L"__InstanceModificationEvent")) { dout(0) << "wnbd adapter changed" << dendl; // TODO: look for state changes and log the availability/status } object->Release(); } } dout(10) << "service stop requested, wnbd event monitor exited" << dendl; } int run_hook() override { std::unique_lock l{start_lock}; if (started) { // The run hook is only supposed to be called once per process, // however we're staying cautious. derr << "Service already running." << dendl; return -EALREADY; } started = true; // Restart registered mappings before accepting new ones. int r = restart_registered_mappings( thread_count, service_start_timeout, image_map_timeout); if (r) { if (remap_failure_fatal) { derr << "Couldn't remap all images. Cleaning up." << dendl; return r; } else { dout(0) << "Ignoring image remap failure." << dendl; } } if (adapter_monitoring_enabled) { adapter_monitor_thread = std::thread(&monitor_wnbd_adapter, this); } else { dout(0) << "WNBD adapter monitoring disabled." << dendl; } return create_pipe_server(); } // Invoked when the service is requested to stop. int stop_hook() override { std::unique_lock l{shutdown_lock}; stop_requsted = true; int r = disconnect_all_mappings( false, hard_disconnect, soft_disconnect_timeout, thread_count); if (adapter_monitor_thread.joinable()) { dout(10) << "waiting for wnbd event monitor thread" << dendl; adapter_monitor_thread.join(); dout(10) << "wnbd event monitor stopped" << dendl; } return r; } // Invoked when the system is shutting down. int shutdown_hook() override { return stop_hook(); } }; class WNBDWatchCtx : public librbd::UpdateWatchCtx { private: librados::IoCtx &io_ctx; WnbdHandler* handler; librbd::Image &image; uint64_t size; public: WNBDWatchCtx(librados::IoCtx& io_ctx, WnbdHandler* handler, librbd::Image& image, uint64_t size) : io_ctx(io_ctx) , handler(handler) , image(image) , size(size) { } ~WNBDWatchCtx() override {} void handle_notify() override { uint64_t new_size; if (image.size(&new_size) == 0 && new_size != size && handler->resize(new_size) == 0) { size = new_size; } } }; static void usage() { const char* usage_str =R"( Usage: rbd-wnbd [options] map <image-or-snap-spec> Map an image to wnbd device [options] unmap <device|image-or-snap-spec> Unmap wnbd device [options] list List mapped wnbd devices [options] show <image-or-snap-spec> Show mapped wnbd device stats <image-or-snap-spec> Show IO counters [options] service Windows service entrypoint, handling device lifecycle Map options: --device <device path> Optional mapping unique identifier --exclusive Forbid writes by other clients --read-only Map read-only --non-persistent Do not recreate the mapping when the Ceph service restarts. By default, mappings are persistent --io-req-workers The number of workers that dispatch IO requests. Default: 4 --io-reply-workers The number of workers that dispatch IO replies. Default: 4 Unmap options: --hard-disconnect Skip attempting a soft disconnect --no-hard-disconnect-fallback Immediately return an error if the soft disconnect fails instead of attempting a hard disconnect as fallback --soft-disconnect-timeout Soft disconnect timeout in seconds. The soft disconnect operation uses PnP to notify the Windows storage stack that the device is going to be disconnected. Storage drivers can block this operation if there are pending operations, unflushed caches or open handles. Default: 15 Service options: --hard-disconnect Skip attempting a soft disconnect --soft-disconnect-timeout Cumulative soft disconnect timeout in seconds, used when disconnecting existing mappings. A hard disconnect will be issued when hitting the timeout --service-thread-count The number of workers used when mapping or unmapping images. Default: 8 --start-timeout The service start timeout in seconds. Default: 120 --map-timeout Individual image map timeout in seconds. Default: 20 --remap-failure-fatal If set, the service will stop when failing to remap an image at start time, unmapping images that have been mapped so far. --adapter-monitoring-enabled If set, the service will monitor WNBD adapter WMI events and remount the images when the adapter gets recreated. Mainly used for development and driver certification purposes. Show|List options: --format plain|json|xml Output format (default: plain) --pretty-format Pretty formatting (json and xml) Common options: --wnbd-log-level libwnbd.dll log level )"; std::cout << usage_str; generic_server_usage(); } static Command cmd = None; int construct_devpath_if_missing(Config* cfg) { // Windows doesn't allow us to request specific disk paths when mapping an // image. This will just be used by rbd-wnbd and wnbd as an identifier. if (cfg->devpath.empty()) { if (cfg->imgname.empty()) { derr << "Missing image name." << dendl; return -EINVAL; } if (!cfg->poolname.empty()) { cfg->devpath += cfg->poolname; cfg->devpath += '/'; } if (!cfg->nsname.empty()) { cfg->devpath += cfg->nsname; cfg->devpath += '/'; } cfg->devpath += cfg->imgname; if (!cfg->snapname.empty()) { cfg->devpath += '@'; cfg->devpath += cfg->snapname; } } return 0; } boost::intrusive_ptr<CephContext> do_global_init( int argc, const char *argv[], Config *cfg) { auto args = argv_to_vec(argc, argv); code_environment_t code_env; int flags; switch(cmd) { case Connect: code_env = CODE_ENVIRONMENT_DAEMON; flags = CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS; break; case Service: code_env = CODE_ENVIRONMENT_DAEMON; flags = CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS | CINIT_FLAG_NO_MON_CONFIG | CINIT_FLAG_NO_DAEMON_ACTIONS; break; default: code_env = CODE_ENVIRONMENT_UTILITY; flags = CINIT_FLAG_NO_MON_CONFIG; break; } global_pre_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, code_env, flags); // Avoid cluttering the console when spawning a mapping that will run // in the background. if (g_conf()->daemonize && cfg->parent_pipe.empty()) { flags |= CINIT_FLAG_NO_DAEMON_ACTIONS; } auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, code_env, flags, FALSE); // There's no fork on Windows, we should be safe calling this anytime. common_init_finish(g_ceph_context); global_init_chdir(g_ceph_context); return cct; } static int do_map(Config *cfg) { int r; librados::Rados rados; librbd::RBD rbd; librados::IoCtx io_ctx; librbd::Image image; librbd::image_info_t info; HANDLE parent_pipe_handle = INVALID_HANDLE_VALUE; int err = 0; if (g_conf()->daemonize && cfg->parent_pipe.empty()) { return send_map_request(get_cli_args()); } dout(0) << "Mapping RBD image: " << cfg->devpath << dendl; r = rados.init_with_context(g_ceph_context); if (r < 0) { derr << "rbd-wnbd: couldn't initialize rados: " << cpp_strerror(r) << dendl; goto close_ret; } r = rados.connect(); if (r < 0) { derr << "rbd-wnbd: couldn't connect to rados: " << cpp_strerror(r) << dendl; goto close_ret; } r = rados.ioctx_create(cfg->poolname.c_str(), io_ctx); if (r < 0) { derr << "rbd-wnbd: couldn't create IO context: " << cpp_strerror(r) << dendl; goto close_ret; } io_ctx.set_namespace(cfg->nsname); r = rbd.open(io_ctx, image, cfg->imgname.c_str()); if (r < 0) { derr << "rbd-wnbd: couldn't open rbd image: " << cpp_strerror(r) << dendl; goto close_ret; } if (cfg->exclusive) { r = image.lock_acquire(RBD_LOCK_MODE_EXCLUSIVE); if (r < 0) { derr << "rbd-wnbd: failed to acquire exclusive lock: " << cpp_strerror(r) << dendl; goto close_ret; } } if (!cfg->snapname.empty()) { r = image.snap_set(cfg->snapname.c_str()); if (r < 0) { derr << "rbd-wnbd: couldn't use snapshot: " << cpp_strerror(r) << dendl; goto close_ret; } } r = image.stat(info, sizeof(info)); if (r < 0) goto close_ret; if (info.size > _UI64_MAX) { r = -EFBIG; derr << "rbd-wnbd: image is too large (" << byte_u_t(info.size) << ", max is " << byte_u_t(_UI64_MAX) << ")" << dendl; goto close_ret; } // We're storing mapping details in the registry even for non-persistent // mappings. This allows us to easily retrieve mapping details such // as the rbd pool or admin socket path. // We're cleaning up the registry entry when the non-persistent mapping // gets disconnected or when the ceph service restarts. r = save_config_to_registry(cfg); if (r < 0) goto close_ret; handler = new WnbdHandler(image, cfg->devpath, info.size / RBD_WNBD_BLKSIZE, RBD_WNBD_BLKSIZE, !cfg->snapname.empty() || cfg->readonly, g_conf().get_val<bool>("rbd_cache"), cfg->io_req_workers, cfg->io_reply_workers); r = handler->start(); if (r) { r = r == ERROR_ALREADY_EXISTS ? -EEXIST : -EINVAL; goto close_ret; } // We're informing the parent processes that the initialization // was successful. if (!cfg->parent_pipe.empty()) { parent_pipe_handle = CreateFile( cfg->parent_pipe.c_str(), GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (parent_pipe_handle == INVALID_HANDLE_VALUE) { derr << "Could not open parent pipe: " << win32_strerror(err) << dendl; } else if (!WriteFile(parent_pipe_handle, "a", 1, NULL, NULL)) { // TODO: consider exiting in this case. The parent didn't wait for us, // maybe it was killed after a timeout. err = GetLastError(); derr << "Failed to communicate with the parent: " << win32_strerror(err) << dendl; } else { dout(5) << __func__ << ": submitted parent notification." << dendl; } if (parent_pipe_handle != INVALID_HANDLE_VALUE) CloseHandle(parent_pipe_handle); global_init_postfork_finish(g_ceph_context); } { uint64_t watch_handle; WNBDWatchCtx watch_ctx(io_ctx, handler, image, info.size); r = image.update_watch(&watch_ctx, &watch_handle); if (r < 0) { derr << __func__ << ": update_watch failed with error: " << cpp_strerror(r) << dendl; handler->shutdown(); goto close_ret; } handler->wait(); r = image.update_unwatch(watch_handle); if (r < 0) derr << __func__ << ": update_unwatch failed with error: " << cpp_strerror(r) << dendl; handler->shutdown(); } close_ret: // The registry record shouldn't be removed for (already) running mappings. if (!cfg->persistent) { dout(5) << __func__ << ": cleaning up non-persistent mapping: " << cfg->devpath << dendl; r = remove_config_from_registry(cfg); if (r) { derr << __func__ << ": could not clean up non-persistent mapping: " << cfg->devpath << dendl; } } std::unique_lock l{shutdown_lock}; image.close(); io_ctx.close(); rados.shutdown(); if (handler) { delete handler; handler = nullptr; } return r; } static int do_unmap(Config *cfg, bool unregister) { WNBD_REMOVE_OPTIONS remove_options = {0}; remove_options.Flags.HardRemove = cfg->hard_disconnect; remove_options.Flags.HardRemoveFallback = cfg->hard_disconnect_fallback; remove_options.SoftRemoveTimeoutMs = cfg->soft_disconnect_timeout * 1000; remove_options.SoftRemoveRetryIntervalMs = SOFT_REMOVE_RETRY_INTERVAL * 1000; int err = WnbdRemoveEx(cfg->devpath.c_str(), &remove_options); if (err && err != ERROR_FILE_NOT_FOUND) { return -EINVAL; } if (unregister) { err = remove_config_from_registry(cfg); if (err) { derr << "rbd-wnbd: failed to unregister device: " << cfg->devpath << ". Error: " << err << dendl; return -EINVAL; } } return 0; } static int parse_imgpath(const std::string &imgpath, Config *cfg, std::ostream *err_msg) { std::regex pattern("^(?:([^/]+)/(?:([^/@]+)/)?)?([^@]+)(?:@([^/@]+))?$"); std::smatch match; if (!std::regex_match(imgpath, match, pattern)) { derr << "rbd-wnbd: invalid spec '" << imgpath << "'" << dendl; return -EINVAL; } if (match[1].matched) { cfg->poolname = match[1]; } if (match[2].matched) { cfg->nsname = match[2]; } cfg->imgname = match[3]; if (match[4].matched) cfg->snapname = match[4]; return 0; } static int do_list_mapped_devices(const std::string &format, bool pretty_format) { std::unique_ptr<ceph::Formatter> f; TextTable tbl; if (format == "json") { f.reset(new JSONFormatter(pretty_format)); } else if (format == "xml") { f.reset(new XMLFormatter(pretty_format)); } else if (!format.empty() && format != "plain") { derr << "rbd-wnbd: invalid output format: " << format << dendl; return -EINVAL; } if (f) { f->open_array_section("devices"); } else { tbl.define_column("id", TextTable::LEFT, TextTable::LEFT); tbl.define_column("pool", TextTable::LEFT, TextTable::LEFT); tbl.define_column("namespace", TextTable::LEFT, TextTable::LEFT); tbl.define_column("image", TextTable::LEFT, TextTable::LEFT); tbl.define_column("snap", TextTable::LEFT, TextTable::LEFT); tbl.define_column("device", TextTable::LEFT, TextTable::LEFT); tbl.define_column("disk_number", TextTable::LEFT, TextTable::LEFT); tbl.define_column("status", TextTable::LEFT, TextTable::LEFT); } Config cfg; WNBDDiskIterator wnbd_disk_iterator; while (wnbd_disk_iterator.get(&cfg)) { const char* status = cfg.active ? WNBD_STATUS_ACTIVE : WNBD_STATUS_INACTIVE; if (f) { f->open_object_section("device"); f->dump_int("id", cfg.pid ? cfg.pid : -1); f->dump_string("device", cfg.devpath); f->dump_string("pool", cfg.poolname); f->dump_string("namespace", cfg.nsname); f->dump_string("image", cfg.imgname); f->dump_string("snap", cfg.snapname); f->dump_int("disk_number", cfg.disk_number ? cfg.disk_number : -1); f->dump_string("status", status); f->close_section(); } else { if (cfg.snapname.empty()) { cfg.snapname = "-"; } tbl << (cfg.pid ? cfg.pid : -1) << cfg.poolname << cfg.nsname << cfg.imgname << cfg.snapname << cfg.devpath << cfg.disk_number << status << TextTable::endrow; } } int error = wnbd_disk_iterator.get_error(); if (error) { derr << "Could not get disk list: " << error << dendl; return error; } if (f) { f->close_section(); f->flush(std::cout); } else { std::cout << tbl; } return 0; } static int do_show_mapped_device(std::string format, bool pretty_format, std::string devpath) { std::unique_ptr<ceph::Formatter> f; TextTable tbl; if (format.empty() || format == "plain") { format = "json"; pretty_format = true; } if (format == "json") { f.reset(new JSONFormatter(pretty_format)); } else if (format == "xml") { f.reset(new XMLFormatter(pretty_format)); } else { derr << "rbd-wnbd: invalid output format: " << format << dendl; return -EINVAL; } Config cfg; int error = load_mapping_config_from_registry(devpath, &cfg); if (error) { derr << "Could not load registry disk info for: " << devpath << ". Error: " << error << dendl; return error; } WNBD_CONNECTION_INFO conn_info = { 0 }; // If the device is currently disconnected but there is a persistent // mapping record, we'll show that. DWORD ret = WnbdShow(devpath.c_str(), &conn_info); if (ret && ret != ERROR_FILE_NOT_FOUND) { return -EINVAL; } auto conn_props = conn_info.Properties; cfg.active = conn_info.DiskNumber > 0 && is_process_running(conn_props.Pid); f->open_object_section("device"); f->dump_int("id", conn_props.Pid ? conn_props.Pid : -1); f->dump_string("device", cfg.devpath); f->dump_string("pool", cfg.poolname); f->dump_string("namespace", cfg.nsname); f->dump_string("image", cfg.imgname); f->dump_string("snap", cfg.snapname); f->dump_int("persistent", cfg.persistent); f->dump_int("disk_number", conn_info.DiskNumber ? conn_info.DiskNumber : -1); f->dump_string("status", cfg.active ? WNBD_STATUS_ACTIVE : WNBD_STATUS_INACTIVE); f->dump_string("pnp_device_id", to_string(conn_info.PNPDeviceID)); f->dump_int("readonly", conn_props.Flags.ReadOnly); f->dump_int("block_size", conn_props.BlockSize); f->dump_int("block_count", conn_props.BlockCount); f->dump_int("flush_enabled", conn_props.Flags.FlushSupported); f->close_section(); f->flush(std::cout); return 0; } static int do_stats(std::string search_devpath) { Config cfg; WNBDDiskIterator wnbd_disk_iterator; while (wnbd_disk_iterator.get(&cfg)) { if (cfg.devpath != search_devpath) continue; AdminSocketClient client = AdminSocketClient(cfg.admin_sock_path); std::string output; std::string result = client.do_request("{\"prefix\":\"wnbd stats\"}", &output); if (!result.empty()) { std::cerr << "Admin socket error: " << result << std::endl; return -EINVAL; } std::cout << output << std::endl; return 0; } int error = wnbd_disk_iterator.get_error(); if (!error) { error = -ENOENT; } derr << "Could not find the specified disk." << dendl; return error; } static int parse_args(std::vector<const char*>& args, std::ostream *err_msg, Command *command, Config *cfg) { std::string conf_file_list; std::string cluster; CephInitParameters iparams = ceph_argparse_early_args( args, CEPH_ENTITY_TYPE_CLIENT, &cluster, &conf_file_list); ConfigProxy config{false}; config->name = iparams.name; config->cluster = cluster; if (!conf_file_list.empty()) { config.parse_config_files(conf_file_list.c_str(), nullptr, 0); } else { config.parse_config_files(nullptr, nullptr, 0); } config.parse_env(CEPH_ENTITY_TYPE_CLIENT); config.parse_argv(args); cfg->poolname = config.get_val<std::string>("rbd_default_pool"); std::vector<const char*>::iterator i; std::ostringstream err; // TODO: consider using boost::program_options like Device.cc does. // This should simplify argument parsing. Also, some arguments must be tied // to specific commands, for example the disconnect timeout. Luckily, // this is enforced by the "rbd device" wrapper. for (i = args.begin(); i != args.end(); ) { if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) { return HELP_INFO; } else if (ceph_argparse_flag(args, i, "-v", "--version", (char*)NULL)) { return VERSION_INFO; } else if (ceph_argparse_witharg(args, i, &cfg->devpath, "--device", (char *)NULL)) { } else if (ceph_argparse_witharg(args, i, &cfg->format, err, "--format", (char *)NULL)) { } else if (ceph_argparse_flag(args, i, "--read-only", (char *)NULL)) { cfg->readonly = true; } else if (ceph_argparse_flag(args, i, "--exclusive", (char *)NULL)) { cfg->exclusive = true; } else if (ceph_argparse_flag(args, i, "--non-persistent", (char *)NULL)) { cfg->persistent = false; } else if (ceph_argparse_flag(args, i, "--pretty-format", (char *)NULL)) { cfg->pretty_format = true; } else if (ceph_argparse_flag(args, i, "--remap-failure-fatal", (char *)NULL)) { cfg->remap_failure_fatal = true; } else if (ceph_argparse_flag(args, i, "--adapter-monitoring-enabled", (char *)NULL)) { cfg->adapter_monitoring_enabled = true; } else if (ceph_argparse_witharg(args, i, &cfg->parent_pipe, err, "--pipe-name", (char *)NULL)) { if (!err.str().empty()) { *err_msg << "rbd-wnbd: " << err.str(); return -EINVAL; } } else if (ceph_argparse_witharg(args, i, (int*)&cfg->wnbd_log_level, err, "--wnbd-log-level", (char *)NULL)) { if (!err.str().empty()) { *err_msg << "rbd-wnbd: " << err.str(); return -EINVAL; } if (cfg->wnbd_log_level < 0) { *err_msg << "rbd-wnbd: Invalid argument for wnbd-log-level"; return -EINVAL; } } else if (ceph_argparse_witharg(args, i, (int*)&cfg->io_req_workers, err, "--io-req-workers", (char *)NULL)) { if (!err.str().empty()) { *err_msg << "rbd-wnbd: " << err.str(); return -EINVAL; } if (cfg->io_req_workers <= 0) { *err_msg << "rbd-wnbd: Invalid argument for io-req-workers"; return -EINVAL; } } else if (ceph_argparse_witharg(args, i, (int*)&cfg->io_reply_workers, err, "--io-reply-workers", (char *)NULL)) { if (!err.str().empty()) { *err_msg << "rbd-wnbd: " << err.str(); return -EINVAL; } if (cfg->io_reply_workers <= 0) { *err_msg << "rbd-wnbd: Invalid argument for io-reply-workers"; return -EINVAL; } } else if (ceph_argparse_witharg(args, i, (int*)&cfg->service_thread_count, err, "--service-thread-count", (char *)NULL)) { if (!err.str().empty()) { *err_msg << "rbd-wnbd: " << err.str(); return -EINVAL; } if (cfg->service_thread_count <= 0) { *err_msg << "rbd-wnbd: Invalid argument for service-thread-count"; return -EINVAL; } } else if (ceph_argparse_flag(args, i, "--hard-disconnect", (char *)NULL)) { cfg->hard_disconnect = true; } else if (ceph_argparse_flag(args, i, "--no-hard-disconnect-fallback", (char *)NULL)) { cfg->hard_disconnect_fallback = false; } else if (ceph_argparse_witharg(args, i, (int*)&cfg->soft_disconnect_timeout, err, "--soft-disconnect-timeout", (char *)NULL)) { if (!err.str().empty()) { *err_msg << "rbd-wnbd: " << err.str(); return -EINVAL; } if (cfg->soft_disconnect_timeout < 0) { *err_msg << "rbd-wnbd: Invalid argument for soft-disconnect-timeout"; return -EINVAL; } } else if (ceph_argparse_witharg(args, i, (int*)&cfg->service_start_timeout, err, "--start-timeout", (char *)NULL)) { if (!err.str().empty()) { *err_msg << "rbd-wnbd: " << err.str(); return -EINVAL; } if (cfg->service_start_timeout <= 0) { *err_msg << "rbd-wnbd: Invalid argument for start-timeout"; return -EINVAL; } } else if (ceph_argparse_witharg(args, i, (int*)&cfg->image_map_timeout, err, "--map-timeout", (char *)NULL)) { if (!err.str().empty()) { *err_msg << "rbd-wnbd: " << err.str(); return -EINVAL; } if (cfg->image_map_timeout <= 0) { *err_msg << "rbd-wnbd: Invalid argument for map-timeout"; return -EINVAL; } } else { ++i; } } Command cmd = None; if (args.begin() != args.end()) { if (strcmp(*args.begin(), "map") == 0) { cmd = Connect; } else if (strcmp(*args.begin(), "unmap") == 0) { cmd = Disconnect; } else if (strcmp(*args.begin(), "list") == 0) { cmd = List; } else if (strcmp(*args.begin(), "show") == 0) { cmd = Show; } else if (strcmp(*args.begin(), "service") == 0) { cmd = Service; } else if (strcmp(*args.begin(), "stats") == 0) { cmd = Stats; } else if (strcmp(*args.begin(), "help") == 0) { return HELP_INFO; } else { *err_msg << "rbd-wnbd: unknown command: " << *args.begin(); return -EINVAL; } args.erase(args.begin()); } if (cmd == None) { *err_msg << "rbd-wnbd: must specify command"; return -EINVAL; } switch (cmd) { case Connect: case Disconnect: case Show: case Stats: if (args.begin() == args.end()) { *err_msg << "rbd-wnbd: must specify wnbd device or image-or-snap-spec"; return -EINVAL; } if (parse_imgpath(*args.begin(), cfg, err_msg) < 0) { return -EINVAL; } args.erase(args.begin()); break; default: //shut up gcc; break; } if (args.begin() != args.end()) { *err_msg << "rbd-wnbd: unknown args: " << *args.begin(); return -EINVAL; } *command = cmd; return 0; } static int rbd_wnbd(int argc, const char *argv[]) { Config cfg; auto args = argv_to_vec(argc, argv); // Avoid using dout before calling "do_global_init" if (args.empty()) { std::cout << argv[0] << ": -h or --help for usage" << std::endl; exit(1); } std::ostringstream err_msg; int r = parse_args(args, &err_msg, &cmd, &cfg); if (r == HELP_INFO) { usage(); return 0; } else if (r == VERSION_INFO) { std::cout << pretty_version_to_str() << std::endl; return 0; } else if (r < 0) { std::cout << err_msg.str() << std::endl; return r; } auto cct = do_global_init(argc, argv, &cfg); WnbdSetLogger(WnbdHandler::LogMessage); WnbdSetLogLevel(cfg.wnbd_log_level); switch (cmd) { case Connect: if (construct_devpath_if_missing(&cfg)) { return -EINVAL; } r = do_map(&cfg); if (r < 0) return r; break; case Disconnect: if (construct_devpath_if_missing(&cfg)) { return -EINVAL; } r = do_unmap(&cfg, true); if (r < 0) return r; break; case List: r = do_list_mapped_devices(cfg.format, cfg.pretty_format); if (r < 0) return r; break; case Show: if (construct_devpath_if_missing(&cfg)) { return r; } r = do_show_mapped_device(cfg.format, cfg.pretty_format, cfg.devpath); if (r < 0) return r; break; case Service: { RBDService service(cfg.hard_disconnect, cfg.soft_disconnect_timeout, cfg.service_thread_count, cfg.service_start_timeout, cfg.image_map_timeout, cfg.remap_failure_fatal, cfg.adapter_monitoring_enabled); // This call will block until the service stops. r = RBDService::initialize(&service); if (r < 0) return r; break; } case Stats: if (construct_devpath_if_missing(&cfg)) { return -EINVAL; } return do_stats(cfg.devpath); default: usage(); break; } return 0; } int main(int argc, const char *argv[]) { SetConsoleCtrlHandler(console_handler_routine, true); // Avoid the Windows Error Reporting dialog. SetErrorMode(GetErrorMode() | SEM_NOGPFAULTERRORBOX); int r = rbd_wnbd(argc, argv); if (r < 0) { return r; } return 0; }
58,098
30.035791
95
cc
null
ceph-main/src/tools/rbd_wnbd/rbd_wnbd.h
/* * Ceph - scalable distributed file system * * Copyright (C) 2020 SUSE LINUX GmbH * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef RBD_WNBD_H #define RBD_WNBD_H #include <string.h> #include <iostream> #include <vector> #include "include/compat.h" #include "common/win32/registry.h" #include "wnbd_handler.h" #define SERVICE_REG_KEY "SYSTEM\\CurrentControlSet\\Services\\rbd-wnbd" #define SERVICE_PIPE_NAME "\\\\.\\pipe\\rbd-wnbd" #define SERVICE_PIPE_TIMEOUT_MS 5000 #define SERVICE_PIPE_BUFFSZ 4096 #define DEFAULT_MAP_TIMEOUT_MS 30000 #define RBD_WNBD_BLKSIZE 512UL #define DEFAULT_SERVICE_START_TIMEOUT 120 #define DEFAULT_IMAGE_MAP_TIMEOUT 20 #define HELP_INFO 1 #define VERSION_INFO 2 #define WNBD_STATUS_ACTIVE "active" #define WNBD_STATUS_INACTIVE "inactive" #define DEFAULT_SERVICE_THREAD_COUNT 8 static WnbdHandler* handler = nullptr; ceph::mutex shutdown_lock = ceph::make_mutex("RbdWnbd::ShutdownLock"); struct Config { bool exclusive = false; bool readonly = false; std::string parent_pipe; std::string poolname; std::string nsname; std::string imgname; std::string snapname; std::string devpath; std::string format; bool pretty_format = false; bool hard_disconnect = false; int soft_disconnect_timeout = DEFAULT_SOFT_REMOVE_TIMEOUT; bool hard_disconnect_fallback = true; int service_start_timeout = DEFAULT_SERVICE_START_TIMEOUT; int image_map_timeout = DEFAULT_IMAGE_MAP_TIMEOUT; bool remap_failure_fatal = false; bool adapter_monitoring_enabled = false; // TODO: consider moving those fields to a separate structure. Those // provide connection information without actually being configurable. // The disk number is provided by Windows. int disk_number = -1; int pid = 0; std::string serial_number; bool active = false; bool wnbd_mapped = false; std::string command_line; std::string admin_sock_path; WnbdLogLevel wnbd_log_level = WnbdLogLevelInfo; int io_req_workers = DEFAULT_IO_WORKER_COUNT; int io_reply_workers = DEFAULT_IO_WORKER_COUNT; int service_thread_count = DEFAULT_SERVICE_THREAD_COUNT; // register the mapping, recreating it when the Ceph service starts. bool persistent = true; }; enum Command { None, Connect, Disconnect, List, Show, Service, Stats }; typedef struct { Command command; BYTE arguments[1]; } ServiceRequest; typedef struct { int status; } ServiceReply; bool is_process_running(DWORD pid); void unmap_at_exit(); int disconnect_all_mappings( bool unregister, bool hard_disconnect, int soft_disconnect_timeout, int worker_count); int restart_registered_mappings( int worker_count, int total_timeout, int image_map_timeout); int map_device_using_suprocess(std::string command_line); int construct_devpath_if_missing(Config* cfg); int save_config_to_registry(Config* cfg); int remove_config_from_registry(Config* cfg); int load_mapping_config_from_registry(std::string devpath, Config* cfg); BOOL WINAPI console_handler_routine(DWORD dwCtrlType); static int parse_args(std::vector<const char*>& args, std::ostream *err_msg, Command *command, Config *cfg); static int do_unmap(Config *cfg, bool unregister); class BaseIterator { public: virtual ~BaseIterator() {}; virtual bool get(Config *cfg) = 0; int get_error() { return error; } protected: int error = 0; int index = -1; }; // Iterate over mapped devices, retrieving info from the driver. class WNBDActiveDiskIterator : public BaseIterator { public: WNBDActiveDiskIterator(); ~WNBDActiveDiskIterator(); bool get(Config *cfg); private: PWNBD_CONNECTION_LIST conn_list = NULL; static DWORD fetch_list(PWNBD_CONNECTION_LIST* conn_list); }; // Iterate over the Windows registry key, retrieving registered mappings. class RegistryDiskIterator : public BaseIterator { public: RegistryDiskIterator(); ~RegistryDiskIterator() { delete reg_key; } bool get(Config *cfg); private: DWORD subkey_count = 0; char subkey_name[MAX_PATH]; RegistryKey* reg_key = NULL; }; // Iterate over all RBD mappings, getting info from the registry and driver. class WNBDDiskIterator : public BaseIterator { public: bool get(Config *cfg); private: // We'll keep track of the active devices. std::set<std::string> active_devices; WNBDActiveDiskIterator active_iterator; RegistryDiskIterator registry_iterator; }; #endif // RBD_WNBD_H
4,685
23.154639
76
h
null
ceph-main/src/tools/rbd_wnbd/wnbd_handler.cc
/* * Ceph - scalable distributed file system * * Copyright (C) 2020 SUSE LINUX GmbH * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #define dout_context g_ceph_context #define dout_subsys ceph_subsys_rbd #include "wnbd_handler.h" #define _NTSCSI_USER_MODE_ #include <rpc.h> #include <ddk/scsi.h> #include <boost/thread/tss.hpp> #include "common/debug.h" #include "common/errno.h" #include "common/safe_io.h" #include "common/SubProcess.h" #include "common/Formatter.h" #include "global/global_context.h" #include "rbd_wnbd.h" WnbdHandler::~WnbdHandler() { if (started && wnbd_disk) { dout(10) << __func__ << ": terminating" << dendl; shutdown(); reply_tpool->join(); WnbdClose(wnbd_disk); started = false; delete reply_tpool; delete admin_hook; } } int WnbdHandler::wait() { int err = 0; if (started && wnbd_disk) { dout(10) << __func__ << ": waiting" << dendl; err = WnbdWaitDispatcher(wnbd_disk); if (err) { derr << __func__ << " failed waiting for dispatcher to stop: " << err << dendl; } } return err; } int WnbdAdminHook::call ( std::string_view command, const cmdmap_t& cmdmap, const bufferlist&, Formatter *f, std::ostream& errss, bufferlist& out) { if (command == "wnbd stats") { return m_handler->dump_stats(f); } return -ENOSYS; } int WnbdHandler::dump_stats(Formatter *f) { if (!f) { return -EINVAL; } WNBD_USR_STATS stats = { 0 }; DWORD err = WnbdGetUserspaceStats(wnbd_disk, &stats); if (err) { derr << "Failed to retrieve WNBD userspace stats. Error: " << err << dendl; return -EINVAL; } f->open_object_section("stats"); f->dump_int("TotalReceivedRequests", stats.TotalReceivedRequests); f->dump_int("TotalSubmittedRequests", stats.TotalSubmittedRequests); f->dump_int("TotalReceivedReplies", stats.TotalReceivedReplies); f->dump_int("UnsubmittedRequests", stats.UnsubmittedRequests); f->dump_int("PendingSubmittedRequests", stats.PendingSubmittedRequests); f->dump_int("PendingReplies", stats.PendingReplies); f->dump_int("ReadErrors", stats.ReadErrors); f->dump_int("WriteErrors", stats.WriteErrors); f->dump_int("FlushErrors", stats.FlushErrors); f->dump_int("UnmapErrors", stats.UnmapErrors); f->dump_int("InvalidRequests", stats.InvalidRequests); f->dump_int("TotalRWRequests", stats.TotalRWRequests); f->dump_int("TotalReadBlocks", stats.TotalReadBlocks); f->dump_int("TotalWrittenBlocks", stats.TotalWrittenBlocks); f->close_section(); return 0; } void WnbdHandler::shutdown() { std::unique_lock l{shutdown_lock}; if (!terminated && wnbd_disk) { // We're requesting the disk to be removed but continue serving IO // requests until the driver sends us the "Disconnect" event. // TODO: expose PWNBD_REMOVE_OPTIONS, we're using the defaults ATM. WnbdRemove(wnbd_disk, NULL); wait(); terminated = true; } } void WnbdHandler::aio_callback(librbd::completion_t cb, void *arg) { librbd::RBD::AioCompletion *aio_completion = reinterpret_cast<librbd::RBD::AioCompletion*>(cb); WnbdHandler::IOContext* ctx = static_cast<WnbdHandler::IOContext*>(arg); int ret = aio_completion->get_return_value(); dout(20) << __func__ << ": " << *ctx << dendl; if (ret == -EINVAL) { // if shrinking an image, a pagecache writeback might reference // extents outside of the range of the new image extents dout(0) << __func__ << ": masking IO out-of-bounds error" << *ctx << dendl; ctx->data.clear(); ret = 0; } if (ret < 0) { ctx->err_code = -ret; // TODO: check the actual error. ctx->set_sense(SCSI_SENSE_MEDIUM_ERROR, SCSI_ADSENSE_UNRECOVERED_ERROR); } else if ((ctx->req_type == WnbdReqTypeRead) && ret < static_cast<int>(ctx->req_size)) { int pad_byte_count = static_cast<int> (ctx->req_size) - ret; ctx->data.append_zero(pad_byte_count); dout(20) << __func__ << ": " << *ctx << ": Pad byte count: " << pad_byte_count << dendl; ctx->err_code = 0; } else { ctx->err_code = 0; } boost::asio::post( *ctx->handler->reply_tpool, [&, ctx]() { ctx->handler->send_io_response(ctx); }); aio_completion->release(); } void WnbdHandler::send_io_response(WnbdHandler::IOContext *ctx) { std::unique_ptr<WnbdHandler::IOContext> pctx{ctx}; ceph_assert(WNBD_DEFAULT_MAX_TRANSFER_LENGTH >= pctx->data.length()); WNBD_IO_RESPONSE wnbd_rsp = {0}; wnbd_rsp.RequestHandle = pctx->req_handle; wnbd_rsp.RequestType = pctx->req_type; wnbd_rsp.Status = pctx->wnbd_status; int err = 0; // Use TLS to store an overlapped structure so that we avoid // recreating one each time we send a reply. static boost::thread_specific_ptr<OVERLAPPED> overlapped_tls( // Cleanup routine [](LPOVERLAPPED p_overlapped) { if (p_overlapped->hEvent) { CloseHandle(p_overlapped->hEvent); } delete p_overlapped; }); LPOVERLAPPED overlapped = overlapped_tls.get(); if (!overlapped) { overlapped = new OVERLAPPED{0}; HANDLE overlapped_evt = CreateEventA(0, TRUE, TRUE, NULL); if (!overlapped_evt) { err = GetLastError(); derr << "Could not create event. Error: " << err << dendl; return; } overlapped->hEvent = overlapped_evt; overlapped_tls.reset(overlapped); } if (!ResetEvent(overlapped->hEvent)) { err = GetLastError(); derr << "Could not reset event. Error: " << err << dendl; return; } err = WnbdSendResponseEx( pctx->handler->wnbd_disk, &wnbd_rsp, pctx->data.c_str(), pctx->data.length(), overlapped); if (err == ERROR_IO_PENDING) { DWORD returned_bytes = 0; err = 0; // We've got ERROR_IO_PENDING, which means that the operation is in // progress. We'll use GetOverlappedResult to wait for it to complete // and then retrieve the result. if (!GetOverlappedResult(pctx->handler->wnbd_disk, overlapped, &returned_bytes, TRUE)) { err = GetLastError(); derr << "Could not send response. Request id: " << wnbd_rsp.RequestHandle << ". Error: " << err << dendl; } } } void WnbdHandler::IOContext::set_sense(uint8_t sense_key, uint8_t asc, uint64_t info) { WnbdSetSenseEx(&wnbd_status, sense_key, asc, info); } void WnbdHandler::IOContext::set_sense(uint8_t sense_key, uint8_t asc) { WnbdSetSense(&wnbd_status, sense_key, asc); } void WnbdHandler::Read( PWNBD_DISK Disk, UINT64 RequestHandle, PVOID Buffer, UINT64 BlockAddress, UINT32 BlockCount, BOOLEAN ForceUnitAccess) { WnbdHandler* handler = nullptr; ceph_assert(!WnbdGetUserContext(Disk, (PVOID*)&handler)); WnbdHandler::IOContext* ctx = new WnbdHandler::IOContext(); ctx->handler = handler; ctx->req_handle = RequestHandle; ctx->req_type = WnbdReqTypeRead; ctx->req_size = BlockCount * handler->block_size; ctx->req_from = BlockAddress * handler->block_size; ceph_assert(ctx->req_size <= WNBD_DEFAULT_MAX_TRANSFER_LENGTH); int op_flags = 0; if (ForceUnitAccess) { op_flags |= LIBRADOS_OP_FLAG_FADVISE_FUA; } dout(20) << *ctx << ": start" << dendl; librbd::RBD::AioCompletion *c = new librbd::RBD::AioCompletion(ctx, aio_callback); handler->image.aio_read2(ctx->req_from, ctx->req_size, ctx->data, c, op_flags); dout(20) << *ctx << ": submitted" << dendl; } void WnbdHandler::Write( PWNBD_DISK Disk, UINT64 RequestHandle, PVOID Buffer, UINT64 BlockAddress, UINT32 BlockCount, BOOLEAN ForceUnitAccess) { WnbdHandler* handler = nullptr; ceph_assert(!WnbdGetUserContext(Disk, (PVOID*)&handler)); WnbdHandler::IOContext* ctx = new WnbdHandler::IOContext(); ctx->handler = handler; ctx->req_handle = RequestHandle; ctx->req_type = WnbdReqTypeWrite; ctx->req_size = BlockCount * handler->block_size; ctx->req_from = BlockAddress * handler->block_size; bufferptr ptr((char*)Buffer, ctx->req_size); ctx->data.push_back(ptr); int op_flags = 0; if (ForceUnitAccess) { op_flags |= LIBRADOS_OP_FLAG_FADVISE_FUA; } dout(20) << *ctx << ": start" << dendl; librbd::RBD::AioCompletion *c = new librbd::RBD::AioCompletion(ctx, aio_callback); handler->image.aio_write2(ctx->req_from, ctx->req_size, ctx->data, c, op_flags); dout(20) << *ctx << ": submitted" << dendl; } void WnbdHandler::Flush( PWNBD_DISK Disk, UINT64 RequestHandle, UINT64 BlockAddress, UINT32 BlockCount) { WnbdHandler* handler = nullptr; ceph_assert(!WnbdGetUserContext(Disk, (PVOID*)&handler)); WnbdHandler::IOContext* ctx = new WnbdHandler::IOContext(); ctx->handler = handler; ctx->req_handle = RequestHandle; ctx->req_type = WnbdReqTypeFlush; ctx->req_size = BlockCount * handler->block_size; ctx->req_from = BlockAddress * handler->block_size; dout(20) << *ctx << ": start" << dendl; librbd::RBD::AioCompletion *c = new librbd::RBD::AioCompletion(ctx, aio_callback); handler->image.aio_flush(c); dout(20) << *ctx << ": submitted" << dendl; } void WnbdHandler::Unmap( PWNBD_DISK Disk, UINT64 RequestHandle, PWNBD_UNMAP_DESCRIPTOR Descriptors, UINT32 Count) { WnbdHandler* handler = nullptr; ceph_assert(!WnbdGetUserContext(Disk, (PVOID*)&handler)); ceph_assert(1 == Count); WnbdHandler::IOContext* ctx = new WnbdHandler::IOContext(); ctx->handler = handler; ctx->req_handle = RequestHandle; ctx->req_type = WnbdReqTypeUnmap; ctx->req_size = Descriptors[0].BlockCount * handler->block_size; ctx->req_from = Descriptors[0].BlockAddress * handler->block_size; dout(20) << *ctx << ": start" << dendl; librbd::RBD::AioCompletion *c = new librbd::RBD::AioCompletion(ctx, aio_callback); handler->image.aio_discard(ctx->req_from, ctx->req_size, c); dout(20) << *ctx << ": submitted" << dendl; } void WnbdHandler::LogMessage( WnbdLogLevel LogLevel, const char* Message, const char* FileName, UINT32 Line, const char* FunctionName) { // We're already passing the log level to WNBD, so we'll use the highest // log level here. dout(0) << "libwnbd.dll!" << FunctionName << " " << WnbdLogLevelToStr(LogLevel) << " " << Message << dendl; } int WnbdHandler::resize(uint64_t new_size) { int err = 0; uint64_t new_block_count = new_size / block_size; dout(5) << "Resizing disk. Block size: " << block_size << ". New block count: " << new_block_count << ". Old block count: " << wnbd_disk->Properties.BlockCount << "." << dendl; err = WnbdSetDiskSize(wnbd_disk, new_block_count); if (err) { derr << "WNBD: Setting disk size failed with error: " << win32_strerror(err) << dendl; return -EINVAL; } dout(5) << "Successfully resized disk to: " << new_block_count << " blocks" << dendl; return 0; } int WnbdHandler::start() { int err = 0; WNBD_PROPERTIES wnbd_props = {0}; instance_name.copy(wnbd_props.InstanceName, sizeof(wnbd_props.InstanceName)); ceph_assert(strlen(RBD_WNBD_OWNER_NAME) < WNBD_MAX_OWNER_LENGTH); strncpy(wnbd_props.Owner, RBD_WNBD_OWNER_NAME, WNBD_MAX_OWNER_LENGTH); wnbd_props.BlockCount = block_count; wnbd_props.BlockSize = block_size; wnbd_props.MaxUnmapDescCount = 1; wnbd_props.Flags.ReadOnly = readonly; wnbd_props.Flags.UnmapSupported = 1; if (rbd_cache_enabled) { wnbd_props.Flags.FUASupported = 1; wnbd_props.Flags.FlushSupported = 1; } err = WnbdCreate(&wnbd_props, &RbdWnbdInterface, this, &wnbd_disk); if (err) goto exit; started = true; err = WnbdStartDispatcher(wnbd_disk, io_req_workers); if (err) { derr << "Could not start WNBD dispatcher. Error: " << err << dendl; } exit: return err; } std::ostream &operator<<(std::ostream &os, const WnbdHandler::IOContext &ctx) { os << "[" << std::hex << ctx.req_handle; switch (ctx.req_type) { case WnbdReqTypeRead: os << " READ "; break; case WnbdReqTypeWrite: os << " WRITE "; break; case WnbdReqTypeFlush: os << " FLUSH "; break; case WnbdReqTypeUnmap: os << " TRIM "; break; default: os << " UNKNOWN(" << ctx.req_type << ") "; break; } os << ctx.req_from << "~" << ctx.req_size << " " << std::dec << ntohl(ctx.err_code) << "]"; return os; }
12,469
26.286652
85
cc
null
ceph-main/src/tools/rbd_wnbd/wnbd_handler.h
/* * Ceph - scalable distributed file system * * Copyright (C) 2020 SUSE LINUX GmbH * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef WNBD_HANDLER_H #define WNBD_HANDLER_H #include <wnbd.h> #include "common/admin_socket.h" #include "common/ceph_context.h" #include "common/Thread.h" #include "include/rbd/librbd.hpp" #include "include/xlist.h" #include "global/global_context.h" // TODO: make this configurable. #define RBD_WNBD_MAX_TRANSFER 2 * 1024 * 1024 #define SOFT_REMOVE_RETRY_INTERVAL 2 #define DEFAULT_SOFT_REMOVE_TIMEOUT 15 #define DEFAULT_IO_WORKER_COUNT 4 // Not defined by mingw. #ifndef SCSI_ADSENSE_UNRECOVERED_ERROR #define SCSI_ADSENSE_UNRECOVERED_ERROR 0x11 #endif // The following will be assigned to the "Owner" field of the WNBD // parameters, which can be used to determine the application managing // a disk. We'll ignore other disks. #define RBD_WNBD_OWNER_NAME "ceph-rbd-wnbd" class WnbdHandler; class WnbdAdminHook : public AdminSocketHook { WnbdHandler *m_handler; public: explicit WnbdAdminHook(WnbdHandler *handler) : m_handler(handler) { g_ceph_context->get_admin_socket()->register_command( "wnbd stats", this, "get WNBD stats"); } ~WnbdAdminHook() override { g_ceph_context->get_admin_socket()->unregister_commands(this); } int call(std::string_view command, const cmdmap_t& cmdmap, const bufferlist&, Formatter *f, std::ostream& errss, bufferlist& out) override; }; class WnbdHandler { private: librbd::Image &image; std::string instance_name; uint64_t block_count; uint32_t block_size; bool readonly; bool rbd_cache_enabled; uint32_t io_req_workers; uint32_t io_reply_workers; WnbdAdminHook* admin_hook; boost::asio::thread_pool* reply_tpool; public: WnbdHandler(librbd::Image& _image, std::string _instance_name, uint64_t _block_count, uint32_t _block_size, bool _readonly, bool _rbd_cache_enabled, uint32_t _io_req_workers, uint32_t _io_reply_workers) : image(_image) , instance_name(_instance_name) , block_count(_block_count) , block_size(_block_size) , readonly(_readonly) , rbd_cache_enabled(_rbd_cache_enabled) , io_req_workers(_io_req_workers) , io_reply_workers(_io_reply_workers) { admin_hook = new WnbdAdminHook(this); // Instead of relying on librbd's own thread pool, we're going to use a // separate one. This allows us to make assumptions on the threads that // are going to send the IO replies and thus be able to cache Windows // OVERLAPPED structures. reply_tpool = new boost::asio::thread_pool(_io_reply_workers); } int resize(uint64_t new_size); int start(); // Wait for the handler to stop, which normally happens when the driver // passes the "Disconnect" request. int wait(); void shutdown(); int dump_stats(Formatter *f); ~WnbdHandler(); static VOID LogMessage( WnbdLogLevel LogLevel, const char* Message, const char* FileName, UINT32 Line, const char* FunctionName); private: ceph::mutex shutdown_lock = ceph::make_mutex("WnbdHandler::DisconnectLocker"); bool started = false; bool terminated = false; WNBD_DISK* wnbd_disk = nullptr; struct IOContext { xlist<IOContext*>::item item; WnbdHandler *handler = nullptr; WNBD_STATUS wnbd_status = {0}; WnbdRequestType req_type = WnbdReqTypeUnknown; uint64_t req_handle = 0; uint32_t err_code = 0; size_t req_size; uint64_t req_from; bufferlist data; IOContext() : item(this) {} void set_sense(uint8_t sense_key, uint8_t asc, uint64_t info); void set_sense(uint8_t sense_key, uint8_t asc); }; friend std::ostream &operator<<(std::ostream &os, const IOContext &ctx); void send_io_response(IOContext *ctx); static void aio_callback(librbd::completion_t cb, void *arg); // WNBD IO entry points static void Read( PWNBD_DISK Disk, UINT64 RequestHandle, PVOID Buffer, UINT64 BlockAddress, UINT32 BlockCount, BOOLEAN ForceUnitAccess); static void Write( PWNBD_DISK Disk, UINT64 RequestHandle, PVOID Buffer, UINT64 BlockAddress, UINT32 BlockCount, BOOLEAN ForceUnitAccess); static void Flush( PWNBD_DISK Disk, UINT64 RequestHandle, UINT64 BlockAddress, UINT32 BlockCount); static void Unmap( PWNBD_DISK Disk, UINT64 RequestHandle, PWNBD_UNMAP_DESCRIPTOR Descriptors, UINT32 Count); static constexpr WNBD_INTERFACE RbdWnbdInterface = { Read, Write, Flush, Unmap, }; }; std::ostream &operator<<(std::ostream &os, const WnbdHandler::IOContext &ctx); #endif // WNBD_HANDLER_H
4,886
24.857143
80
h
null
ceph-main/src/tools/rbd_wnbd/wnbd_wmi.cc
/* * Ceph - scalable distributed file system * * Copyright (c) 2019 SUSE LLC * Copyright (C) 2022 Cloudbase Solutions * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #include "wnbd_wmi.h" #include "common/debug.h" #include "common/win32/wstring.h" #define dout_context g_ceph_context #define dout_subsys ceph_subsys_rbd #undef dout_prefix #define dout_prefix *_dout << "rbd-wnbd: " // Initializes the COM library for use by the calling thread using // COINIT_MULTITHREADED. static HRESULT co_initialize_basic() { dout(10) << "initializing COM library" << dendl; HRESULT hres = CoInitializeEx(0, COINIT_MULTITHREADED); if (FAILED(hres)) { derr << "CoInitializeEx failed. HRESULT: " << hres << dendl; return hres; } // CoInitializeSecurity must be called once per process. static bool com_security_flags_set = false; if (!com_security_flags_set) { hres = CoInitializeSecurity( NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); if (FAILED(hres)) { derr << "CoInitializeSecurity failed. HRESULT: " << hres << dendl; CoUninitialize(); return hres; } com_security_flags_set = true; } return 0; } // co_uninitialize must be called once for every successful // co_initialize_basic call. Any WMI objects (including connections, // event subscriptions, etc) must be released beforehand. static void co_uninitialize() { dout(10) << "closing COM library" << dendl; CoUninitialize(); } HRESULT COMBootstrapper::initialize() { std::unique_lock l{init_lock}; HRESULT hres = co_initialize_basic(); if (!FAILED(hres)) { initialized = true; } return hres; } void COMBootstrapper::cleanup() { if (initialized) { co_uninitialize(); initialized = false; } } void WmiConnection::close() { dout(20) << "closing wmi conn: " << this << ", svc: " << wbem_svc << ", loc: " << wbem_loc << dendl; if (wbem_svc != NULL) { wbem_svc->Release(); wbem_svc = NULL; } if (wbem_loc != NULL) { wbem_loc->Release(); wbem_loc = NULL; } } HRESULT WmiConnection::initialize() { HRESULT hres = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&wbem_loc); if (FAILED(hres)) { derr << "CoCreateInstance failed. HRESULT: " << hres << dendl; return hres; } hres = wbem_loc->ConnectServer( _bstr_t(ns.c_str()).GetBSTR(), NULL, NULL, NULL, WBEM_FLAG_CONNECT_USE_MAX_WAIT, NULL, NULL, &wbem_svc); if (FAILED(hres)) { derr << "Could not connect to WMI service. HRESULT: " << hres << dendl; return hres; } if (!wbem_svc) { hres = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_INVALID_HANDLE); derr << "WMI connection failed, no WMI service object received." << dendl; return hres; } hres = CoSetProxyBlanket( wbem_svc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE); if (FAILED(hres)) { derr << "CoSetProxyBlanket failed. HRESULT:" << hres << dendl; } return hres; } HRESULT get_property_str( IWbemClassObject* cls_obj, const std::wstring& property, std::wstring& value) { VARIANT vt_prop; VariantInit(&vt_prop); HRESULT hres = cls_obj->Get(property.c_str(), 0, &vt_prop, 0, 0); if (!FAILED(hres)) { VARIANT vt_bstr_prop; VariantInit(&vt_bstr_prop); hres = VariantChangeType(&vt_bstr_prop, &vt_prop, 0, VT_BSTR); if (!FAILED(hres)) { value = vt_bstr_prop.bstrVal; } VariantClear(&vt_bstr_prop); } VariantClear(&vt_prop); if (FAILED(hres)) { derr << "Could not get WMI property: " << to_string(property) << ". HRESULT: " << hres << dendl; } return hres; } HRESULT get_property_int( IWbemClassObject* cls_obj, const std::wstring& property, uint32_t& value) { VARIANT vt_prop; VariantInit(&vt_prop); HRESULT hres = cls_obj->Get(property.c_str(), 0, &vt_prop, 0, 0); if (!FAILED(hres)) { VARIANT vt_uint_prop; VariantInit(&vt_uint_prop); hres = VariantChangeType(&vt_uint_prop, &vt_prop, 0, VT_UINT); if (!FAILED(hres)) { value = vt_uint_prop.intVal; } VariantClear(&vt_uint_prop); } VariantClear(&vt_prop); if (FAILED(hres)) { derr << "Could not get WMI property: " << to_string(property) << ". HRESULT: " << hres << dendl; } return hres; } HRESULT WmiSubscription::initialize() { HRESULT hres = conn.initialize(); if (FAILED(hres)) { derr << "Could not create WMI connection" << dendl; return hres; } hres = conn.wbem_svc->ExecNotificationQuery( _bstr_t(L"WQL").GetBSTR(), _bstr_t(query.c_str()).GetBSTR(), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &event_enum); if (FAILED(hres)) { derr << "Notification query failed, unable to subscribe to " << "WMI events. HRESULT: " << hres << dendl; } else { dout(20) << "wmi subscription initialized: " << this << ", event enum: " << event_enum << ", conn: " << &conn << ", conn svc: " << conn.wbem_svc << dendl; } return hres; } void WmiSubscription::close() { dout(20) << "closing wmi subscription: " << this << ", event enum: " << event_enum << dendl; if (event_enum != NULL) { event_enum->Release(); event_enum = NULL; } } HRESULT WmiSubscription::next( long timeout, ULONG count, IWbemClassObject **objects, ULONG *returned) { if (!event_enum) { HRESULT hres = MAKE_HRESULT( SEVERITY_ERROR, FACILITY_WIN32, ERROR_INVALID_HANDLE); derr << "WMI subscription uninitialized." << dendl; return hres; } HRESULT hres = event_enum->Next(timeout, count, objects, returned); if (FAILED(hres)) { derr << "Unable to retrieve WMI events. HRESULT: " << hres << dendl; } return hres; } WmiSubscription subscribe_wnbd_adapter_events( uint32_t interval) { std::wostringstream query_stream; query_stream << L"SELECT * FROM __InstanceOperationEvent " << L"WITHIN " << interval << L"WHERE TargetInstance ISA 'Win32_ScsiController' " << L"AND TargetInstance.Description=" << L"'WNBD SCSI Virtual Adapter'"; return WmiSubscription(L"root\\cimv2", query_stream.str()); }
6,511
23.854962
78
cc
null
ceph-main/src/tools/rbd_wnbd/wnbd_wmi.h
/* * Ceph - scalable distributed file system * * Copyright (c) 2019 SUSE LLC * Copyright (C) 2022 Cloudbase Solutions * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #pragma once #include <comutil.h> #define _WIN32_DCOM #include <wbemcli.h> #include <string> #include <vector> #include "common/ceph_mutex.h" // Convenience helper for initializing and cleaning up the // Windows COM library using "COINIT_MULTITHREADED" concurrency mode. // Any WMI objects (including connections, event subscriptions, etc) // must be released before the COM library gets closed. class COMBootstrapper { private: bool initialized = false; ceph::mutex init_lock = ceph::make_mutex("COMBootstrapper::InitLocker"); public: HRESULT initialize(); void cleanup(); ~COMBootstrapper() { cleanup(); } }; class WmiConnection { private: std::wstring ns; public: IWbemLocator* wbem_loc; IWbemServices* wbem_svc; WmiConnection(std::wstring ns) : ns(ns) , wbem_loc(nullptr) , wbem_svc(nullptr) { } ~WmiConnection() { close(); } HRESULT initialize(); void close(); }; HRESULT get_property_str( IWbemClassObject* cls_obj, const std::wstring& property, std::wstring& value); HRESULT get_property_int( IWbemClassObject* cls_obj, const std::wstring& property, uint32_t& value); class WmiSubscription { private: std::wstring query; WmiConnection conn; IEnumWbemClassObject *event_enum; public: WmiSubscription(std::wstring ns, std::wstring query) : query(query) , conn(WmiConnection(ns)) , event_enum(nullptr) { } ~WmiSubscription() { close(); } HRESULT initialize(); void close(); // IEnumWbemClassObject::Next wrapper HRESULT next( long timeout, ULONG count, IWbemClassObject **objects, ULONG *returned); }; WmiSubscription subscribe_wnbd_adapter_events(uint32_t interval);
2,059
17.727273
74
h
null
ceph-main/src/tracing/tracing-common.h
#if !defined(TRACING_COMMON_H) #define TRACING_COMMON_H // Amount of buffer data to dump when using ceph_ctf_sequence or ceph_ctf_sequencep. // If 0, then *_data field is omitted entirely. #if !defined(CEPH_TRACE_BUF_TRUNC_LEN) #define CEPH_TRACE_BUF_TRUNC_LEN 0u #endif // TODO: This is GCC-specific. Replace CEPH_MAX and CEPH_MIN with standard macros, if possible. #define CEPH_MAX(a,b) \ ({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ _a > _b ? _a : _b; }) #define CEPH_MIN(a,b) \ ({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ _a < _b ? _a : _b; }) // type should be an integer type // val should have type type* #define ceph_ctf_integerp(type, field, val) \ ctf_integer(type, field, (val) == NULL ? 0 : (val)) \ ctf_integer(uint8_t, field##_isnull, (val) == NULL) // val should have type char* #define ceph_ctf_string(field, val) \ ctf_string(field, (val) == NULL ? "" : (val)) \ ctf_integer(uint8_t, field##_isnull, (val) == NULL) // val should have type char** #define ceph_ctf_stringp(field, val) \ ctf_string(field, ((val) == NULL || *(val) == NULL) ? "" : *(val)) \ ctf_integer(uint8_t, field##_isnull, (val) == NULL) \ ctf_integer(uint8_t, field##_data_isnull, (val) == NULL || *(val) == NULL) // val should have type type* // lenval should have type lentype #if CEPH_TRACE_BUF_TRUNC_LEN > 0 #define ceph_ctf_sequence(type, field, val, lentype, lenval) \ ctf_integer_hex(void*, field, val) \ ctf_sequence(type, field##_data, (val) == NULL ? "" : (val), lentype, (val) == NULL ? 0 : CEPH_MIN((lenval), CEPH_TRACE_BUF_TRUNC_LEN)) \ ctf_integer(uint8_t, field##_isnull, (val) == NULL) \ ctf_integer(lentype, field##_len, lenval) #else #define ceph_ctf_sequence(type, field, val, lentype, lenval) \ ctf_integer_hex(void*, field, val) \ ctf_integer(uint8_t, field##_isnull, (val) == NULL) \ ctf_integer(lentype, field##_len, lenval) #endif // val should have type type** // lenval should have type lentype* #if CEPH_TRACE_BUF_TRUNC_LEN > 0 #define ceph_ctf_sequencep(type, field, val, lentype, lenval) \ ctf_integer_hex(void*, field, val) \ ctf_sequence(type, \ field##_data, \ ((val) == NULL || *(val) == NULL) ? "" : *(val), \ lentype, \ ((val) == NULL || *(val) == NULL || (lenval) == NULL) ? 0 : CEPH_MIN(*(lenval), CEPH_TRACE_BUF_TRUNC_LEN)) \ ctf_integer(uint8_t, field##_isnull, (val) == NULL) \ ctf_integer(uint8_t, field##_data_isnull, ((val) == NULL || *(val) == NULL)) \ ctf_integer(lentype, field##_len, (lenval) == NULL ? 0 : *(lenval)) \ ctf_integer(lentype, field##_len_isnull, (lenval) == NULL) #else #define ceph_ctf_sequencep(type, field, val, lentype, lenval) \ ctf_integer_hex(void*, field, val) \ ctf_integer(uint8_t, field##_isnull, (val) == NULL) \ ctf_integer(uint8_t, field##_data_isnull, ((val) == NULL || *(val) == NULL)) \ ctf_integer(lentype, field##_len, (lenval) == NULL ? 0 : *(lenval)) \ ctf_integer(lentype, field##_len_isnull, (lenval) == NULL) #endif // p should be of type struct timeval* #define ceph_ctf_timevalp(field, p) \ ctf_integer(long int, field##_sec, (p) == NULL ? 0 : (p)->tv_sec) \ ctf_integer(long int, field##_usec, (p) == NULL ? 0 : (p)->tv_usec) \ ctf_integer(uint8_t, field##_isnull, (p) == NULL) // p should be of type struct timespec* #define ceph_ctf_timespecp(field, p) \ ctf_integer(long int, field##_sec, (p) == NULL ? 0 : (p)->tv_sec) \ ctf_integer(long int, field##_nsec, (p) == NULL ? 0 : (p)->tv_nsec) \ ctf_integer(uint8_t, field##_isnull, (p) == NULL) // val should be of type time_t // Currently assumes that time_t is an integer and no more than 64 bits wide. // This is verified by the configure script. #define ceph_ctf_time_t(field, val) \ ctf_integer(uint64_t, field, (uint64_t)(val)) // val should be of type time_t* // Currently assumes that time_t is an integer and no more than 64 bits wide. // This is verified by the configure script. #define ceph_ctf_time_tp(field, val) \ ctf_integer(uint64_t, field, (val) == NULL ? 0 : (uint64_t)(*val)) \ ctf_integer(uint8_t, field##_isnull, (val) == NULL) #endif /* TRACING_COMMON_H */
4,279
40.553398
141
h
lightly
lightly-master/docs/source/_templates/footer.html
<!-- Copied from https://github.com/readthedocs/sphinx_rtd_theme/blob/ddf840cb7206d7c45270560f077b12daa147f915/sphinx_rtd_theme/footer.html Adapted to add link to website from copyright in the footer, see comment below --> <footer> {% if (theme_prev_next_buttons_location == 'bottom' or theme_prev_next_buttons_location == 'both') and (next or prev) %} <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> {% if next %} <a href="{{ next.link|e }}" class="btn btn-neutral float-right" title="{{ next.title|striptags|e }}" accesskey="n" rel="next">{{ _('Next') }} <span class="fa fa-arrow-circle-right"></span></a> {% endif %} {% if prev %} <a href="{{ prev.link|e }}" class="btn btn-neutral float-left" title="{{ prev.title|striptags|e }}" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> {{ _('Previous') }}</a> {% endif %} </div> {% endif %} <hr/> <div role="contentinfo"> <p> {%- if show_copyright %} {%- if hasdoc('copyright') %} {% set path = pathto('copyright') %} {% set copyright = copyright|e %} &copy; <a href="{{ path }}">{% trans %}Copyright{% endtrans %}</a> {{ copyright }} {%- else %} {% set copyright = copyright|e %} <!-- Adapted to include link to website --> &copy; {% trans %}Copyright{% endtrans %} {{ copyright_year }}, <a href="{{ website_url }}">{{ copyright }}</a> {%- endif %} {%- endif %} {%- if build_id and build_url %} <span class="build"> {# Translators: Build is a noun, not a verb #} {% trans %}Build{% endtrans %} <a href="{{ build_url }}">{{ build_id }}</a>. </span> {%- elif commit %} <span class="commit"> {% trans %}Revision{% endtrans %} <code>{{ commit }}</code>. </span> {%- elif last_updated %} <span class="lastupdated"> {% trans last_updated=last_updated|e %}Last updated on {{ last_updated }}.{% endtrans %} </span> {%- endif %} </p> </div> {%- if show_sphinx %} {% set sphinx_web = '<a href="http://sphinx-doc.org/">Sphinx</a>' %} {% set readthedocs_web = '<a href="https://readthedocs.org">Read the Docs</a>' %} {% trans sphinx_web=sphinx_web, readthedocs_web=readthedocs_web %}Built with {{ sphinx_web }} using a{% endtrans %} <a href="https://github.com/rtfd/sphinx_rtd_theme">{% trans %}theme{% endtrans %}</a> {% trans %}provided by {{ readthedocs_web }}{% endtrans %}. {%- endif %} {%- block extrafooter %} {% endblock %} </footer>
2,704
44.083333
269
html
lightly
lightly-master/docs/source/_templates/layout.html
{% extends "!layout.html" %} {# Custom CSS overrides #} {% set bootswatch_css_custom = ['/_static/my-styles.css'] %} <!-- Copy from https://github.com/readthedocs/sphinx_rtd_theme/blob/ddf840cb7206d7c45270560f077b12daa147f915/sphinx_rtd_theme/layout.html#L184-L205 We need this to override the footer --> {%- block content %} {% if theme_style_external_links|tobool %} <div class="rst-content style-external-links"> {% else %} <div class="rst-content"> {% endif %} {% include "breadcrumbs.html" %} <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> {%- block document %} <div itemprop="articleBody"> {% block body %}{% endblock %} </div> {% if self.comments()|trim %} <div class="articleComments"> {% block comments %}{% endblock %} </div> {% endif%} </div> {%- endblock %} {% include "footer.html" %} </div> {%- endblock %} {% block footer %} {{ super() }} <!-- Google Analytics --> <script> (function (i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m) })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga'); var host = window.location.hostname; if (host != "localhost") { ga('create', 'UA-147883152-5', 'auto'); ga('send', 'pageview'); } </script> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-147883152-5"></script> <script> window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', 'UA-147883152-5'); </script> <style> /* Sidebar header (and topbar for mobile) */ .wy-side-nav-search, .wy-nav-top { background: #092643; } /* Sidebar */ .wy-nav-side { background: #092643; } /*body{ font-family: "Arial, Helvetica, sans-serif"; }*/ </style> {% endblock %}
2,190
25.083333
145
html
lightly
lightly-master/tests/UNMOCKED_end2end_tests/run_all_unmocked_tests.sh
#!/bin/bash set -e # Get the parameters export LIGHTLY_TOKEN=$1 [[ -z "$LIGHTLY_TOKEN" ]] && { echo "Error: token is empty" ; exit 1; } echo "############################### token: ${LIGHTLY_TOKEN}" DATE_TIME=$(date +%Y-%m-%d-%H-%M-%S) echo "############################### Download the clothing_dataset_small" DIR_DATASET=clothing_dataset_small if [ -d $DIR_DATASET ]; then echo "Skipping download of dataset, it already exists." else git clone https://github.com/alexeygrigorev/clothing-dataset-small $DIR_DATASET fi INPUT_DIR="${DIR_DATASET}/test/dress" CUSTOM_METADATA_FILENAME="${DIR_DATASET}/custom_metadata.json" python tests/UNMOCKED_end2end_tests/create_custom_metadata_from_input_dir.py $INPUT_DIR $CUSTOM_METADATA_FILENAME # Run the tests echo "############################### Test 1" lightly-magic input_dir=$INPUT_DIR trainer.max_epochs=0 echo "############################### Test 2" lightly-magic input_dir=$INPUT_DIR trainer.max_epochs=1 echo "############################### Delete dataset again" rm -rf $DIR_DATASET
1,045
31.6875
113
sh
evo
evo-master/.ci/debian_install_pip3.sh
#!/bin/bash set -e apt update apt install -y python3-pip
59
7.571429
26
sh
evo
evo-master/.ci/ros_entrypoint.sh
#!/bin/bash set -e source "/opt/ros/$ROS_DISTRO/setup.bash" exec "$@"
72
9.428571
40
sh
evo
evo-master/.ci/ros_run_tests.sh
#!/bin/bash set -e workdir=$1 source /opt/ros/$ROS_DISTRO/setup.sh cd $workdir pytest -sv
93
8.4
36
sh
evo
evo-master/.ci/run_yapf.sh
#!/bin/bash set -e if [ ! -f setup.py ]; then echo "Error: please execute it in the base directory of the repository." exit 1 fi # Exclude 3rd party files. yapf --recursive --in-place -vv . \ --exclude "fastentrypoints.py" \ --exclude "evo/core/transformations.py" \ --exclude "test/tum_benchmark_tools/*" \
322
19.1875
74
sh
evo
evo-master/contrib/print_duplicate_timestamps.sh
#!/bin/bash set -e usage=" Print lines with duplicate timestamps in TUM or EuRoC trajectory files.\n\n Usage: ./print_duplicates.sh TRAJECTORY " if [ "$#" -ne 1 ]; then echo -e $usage exit 1 fi cut -d" " -f 1 $1 | uniq -D
235
12.882353
75
sh
evo
evo-master/test/run_all_demos.sh
#!/usr/bin/env bash set -e # exit on error n="" if [[ $* == *--no_plots* ]]; then n="--no_plots" fi # run all demo scripts to get cheap app tests yes | demos/traj_demo.sh "$n" yes | demos/ape_demo.sh "$n" yes | demos/rpe_demo.sh "$n" yes | demos/res_demo.sh "$n" yes | demos/latex_demo.sh "$n" echo "enter 'y' to clean, any other key to exit" read input if [[ $input == y ]]; then demos/clean.sh exit 0 fi
422
18.227273
48
sh
evo
evo-master/test/demos/ape_demo.sh
#!/usr/bin/env bash set -e # exit on error # printf "\033c" resets the output function log { printf "\033c"; echo -e "\033[32m[$BASH_SOURCE] $1\033[0m"; } function echo_and_run { echo -e "\$ $@" ; read input; "$@" ; read input; } # always run in script directory parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) cd "$parent_path" p="-p" if [[ $* == *--no_plots* ]]; then p= fi log "minimal command" echo_and_run evo_ape kitti ../data/KITTI_00_gt.txt ../data/KITTI_00_ORB.txt log "show more output and plot: -v or --verbose and -p or --plot" echo_and_run evo_ape kitti ../data/KITTI_00_gt.txt ../data/KITTI_00_ORB.txt -v $p log "align the trajectories" echo_and_run evo_ape kitti ../data/KITTI_00_gt.txt ../data/KITTI_00_ORB.txt -va $p log "use other pose_relation (e.g. angle) with -r or --pose_relation" echo_and_run evo_ape kitti ../data/KITTI_00_gt.txt ../data/KITTI_00_ORB.txt -va $p --pose_relation angle_deg log "save results" echo_and_run evo_ape kitti ../data/KITTI_00_gt.txt ../data/KITTI_00_ORB.txt -va --save_results ORB_ape.zip log "run multiple and save results" log "first..." echo_and_run evo_ape kitti ../data/KITTI_00_gt.txt ../data/KITTI_00_ORB.txt -a --save_results ORB_ape.zip log "second..." echo_and_run evo_ape kitti ../data/KITTI_00_gt.txt ../data/KITTI_00_SPTAM.txt -a --save_results SPTAM_ape.zip
1,350
35.513514
109
sh
evo
evo-master/test/demos/clean.sh
#!/usr/bin/env bash # always run in script directory parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) cd "$parent_path" rm -I *.bag *.kitti *.tum *.csv *.pdf *.zip *.pgf *.log *.aux *.json
204
24.625
68
sh
evo
evo-master/test/demos/config_demo.sh
#!/usr/bin/env bash set -e # exit on error # printf "\033c" resets the output function log { printf "\033c"; echo -e "\033[32m[$BASH_SOURCE] $1\033[0m"; } function echo_and_run { echo -e "\$ $@" ; read input; "$@" ; read input; } # always run in script directory parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) cd "$parent_path" log "show package settings" echo_and_run evo_config show if [ -e cfg.json ]; then log "show arbitrary .json config" echo_and_run evo_config show cfg.json fi log "set some package settings" echo_and_run evo_config set plot_figsize 6 5 plot_usetex plot_fontfamily serif if [ -e cfg.json ]; then log "set parameter of some arbitrary .json config" echo_and_run evo_config set -c cfg.json mode speed fi log "reset package settings to defaults" echo_and_run evo_config reset log "generate a .json config from arbitrary command line options" echo_and_run evo_config generate --flag --number 2.5 --string plot.pdf --list 1 2.3 4
989
29
85
sh
evo
evo-master/test/demos/latex_demo.sh
#!/usr/bin/env bash # set -e # exit on error # printf "\033c" resets the output function log { printf "\033c"; echo -e "\033[32m[$BASH_SOURCE] $1\033[0m"; } function echo_and_run { echo -e "\$ $@" ; read input; "$@" ; read input; } # always run in script directory parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) cd "$parent_path" log "configure LaTeX-friendly settings" echo_and_run evo_config set plot_figsize 5 5 plot_usetex plot_fontfamily serif plot_linewidth 0.5 plot_seaborn_style whitegrid log "generate .pgf figures" echo_and_run evo_res *rpe.zip --save_plot example.pgf log "generate .pdf from .tex" echo_and_run pdflatex example.tex if [[ ! $* == *--no_plots* ]]; then evince example.pdf fi yes | evo_config reset
751
27.923077
126
sh
evo
evo-master/test/demos/res_demo.sh
#!/usr/bin/env bash # printf "\033c" resets the output function log { printf "\033c"; echo -e "\033[32m[$BASH_SOURCE] $1\033[0m"; } function echo_and_run { echo -e "\$ $@" ; read input; "$@" ; read input; } # always run in script directory parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) cd "$parent_path" p="-p" if [[ $* == *--no_plots* ]]; then p= fi for m in ape rpe do ls *$m.zip > /dev/null retcode=$?; if [ $retcode != 0 ]; then echo "missing files: "*$m.zip echo "run {ape, rpe}_demo.sh before this demo" exit 1 else echo "found files for $m" fi done set -e # exit on error for m in ape rpe do log "load results from evo_${m}..." echo_and_run evo_res *"$m".zip log "load results from evo_$m and plot them" echo_and_run evo_res *"$m".zip $p log "load results from evo_$m and save plots in pdf" echo_and_run evo_res *"$m".zip --save_plot "$m".pdf log "load results from evo_$m and save stats in table" echo_and_run evo_res *"$m".zip --save_table "$m".csv done
1,073
23.409091
76
sh
evo
evo-master/test/demos/rpe_demo.sh
#!/usr/bin/env bash set -e # exit on error # printf "\033c" resets the output function log { printf "\033c"; echo -e "\033[32m[$BASH_SOURCE] $1\033[0m"; } function echo_and_run { echo -e "\$ $@" ; read input; "$@" ; read input; } # always run in script directory parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) cd "$parent_path" p="-p" if [[ $* == *--no_plots* ]]; then p= fi log "minimal command (delta = 1 frame)" echo_and_run evo_rpe kitti ../data/KITTI_00_gt.txt ../data/KITTI_00_ORB.txt log "show more output and plot: -v or --verbose and -p or --plot" echo_and_run evo_rpe kitti ../data/KITTI_00_gt.txt ../data/KITTI_00_ORB.txt -v $p log "use a different delta between the pose pairs:\n-d or --delta and -u or --delta_unit" echo_and_run evo_rpe kitti ../data/KITTI_00_gt.txt ../data/KITTI_00_ORB.txt -v -d 10 -u m $p log "use other pose_relation (e.g. angle) with -r or --pose_relation" echo_and_run evo_rpe kitti ../data/KITTI_00_gt.txt ../data/KITTI_00_ORB.txt -v -d 10 -u m -r angle_deg $p log "save results" echo_and_run evo_rpe kitti ../data/KITTI_00_gt.txt ../data/KITTI_00_ORB.txt -v -d 10 -u m --save_results ORB_rpe.zip log "run multiple and save results" log "first..." echo_and_run evo_rpe kitti ../data/KITTI_00_gt.txt ../data/KITTI_00_ORB.txt -d 10 -u m --save_results ORB_rpe.zip log "second..." echo_and_run evo_rpe kitti ../data/KITTI_00_gt.txt ../data/KITTI_00_SPTAM.txt -d 10 -u m --save_results SPTAM_rpe.zip
1,462
38.540541
117
sh
evo
evo-master/test/demos/traj_demo.sh
#!/usr/bin/env bash set -e # exit on error # printf "\033c" resets the output function log { printf "\033c"; echo -e "\033[32m[$BASH_SOURCE] $1\033[0m"; } function echo_and_run { echo -e "\$ $@" ; read input; "$@" ; read input; } # always run in script directory parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) cd "$parent_path" p="-p" if [[ $* == *--no_plots* ]]; then p= fi log "read single info" echo_and_run evo_traj tum ../data/fr2_desk_ORB.txt log "verbose mode: -v or --verbose" echo_and_run evo_traj tum ../data/fr2_desk_ORB.txt -v log "do a full check of the trajectory" echo_and_run evo_traj tum ../data/fr2_desk_ORB.txt --full_check log "load multiple trajectories" echo_and_run evo_traj tum ../data/fr2_desk_* log "plot trajectories: -p or --plot" echo_and_run evo_traj tum ../data/fr2_desk_* --ref=../data/fr2_desk_groundtruth.txt --plot_mode xyz $p log "align to reference to resolve mess: -a or --align" echo_and_run evo_traj tum ../data/fr2_desk_* --ref=../data/fr2_desk_groundtruth.txt --plot_mode=xyz -a $p log "additionally, scale for monocular trajectories" echo_and_run evo_traj tum ../data/fr2_desk_* --ref=../data/fr2_desk_groundtruth.txt --plot_mode=xyz -as $p log "save in other format - here: bagfile" echo_and_run evo_traj tum ../data/fr2_desk_* --ref=../data/fr2_desk_groundtruth.txt -as --save_as_bag log "plot bag contents" echo_and_run evo_traj bag *.bag --all_topics --ref=fr2_desk_groundtruth $p
1,462
31.511111
106
sh
null
qimera-main/eval_cifar100_4bit.sh
#!/bin/bash python main.py --conf_path ./cifar100_resnet20.hocon --multi_label_prob 0.4 --multi_label_num 10 --id 01 --eval
124
40.666667
111
sh
null
qimera-main/eval_cifar10_4bit.sh
#!/bin/bash python main.py --conf_path ./cifar10_resnet20.hocon --multi_label_prob 0.4 --multi_label_num 2 --id 01 --randemb --eval
132
43.333333
119
sh
null
qimera-main/eval_imgnet_mobilenet_v2_4bit.sh
#!/bin/bash python main.py --conf_path ./imagenet_mobilenet_v2.hocon --multi_label_prob 0.4 --multi_label_num 500 --id 01 --randemb --eval
139
45.666667
126
sh
null
qimera-main/eval_imgnet_resnet18_4bit.sh
#!/bin/bash python main.py --conf_path ./imagenet_resnet18.hocon --multi_label_prob 0.4 --multi_label_num 100 --id 01 --eval
125
41
112
sh
null
qimera-main/eval_imgnet_resnet50_4bit.sh
#!/bin/bash python main.py --conf_path ./imagenet_resnet50.hocon --multi_label_prob 0.7 --multi_label_num 500 --id 01 --eval
125
41
112
sh
null
qimera-main/run_cifar100_4bit.sh
#!/bin/bash python main.py --conf_path ./cifar100_resnet20.hocon --multi_label_prob 0.4 --multi_label_num 10 --id 01
117
38.333333
104
sh
null
qimera-main/run_cifar10_4bit.sh
#!/bin/bash python main.py --conf_path ./cifar10_resnet20.hocon --multi_label_prob 0.4 --multi_label_num 2 --id 01 --randemb
125
41
112
sh
null
qimera-main/run_imgnet_mobilenet_v2_4bit.sh
#!/bin/bash python main.py --conf_path ./imagenet_mobilenet_v2.hocon --multi_label_prob 0.4 --multi_label_num 100 --id 01 --randemb
132
43.333333
119
sh
null
qimera-main/run_imgnet_resnet18_4bit.sh
#!/bin/bash python main.py --conf_path ./imagenet_resnet18.hocon --multi_label_prob 0.4 --multi_label_num 500 --id 01 --randemb
128
42
115
sh
null
qimera-main/run_imgnet_resnet50_4bit.sh
#!/bin/bash python main.py --conf_path ./imagenet_resnet50.hocon --multi_label_prob 0.7 --multi_label_num 500 --id 01
118
38.666667
105
sh
null
qimera-main/other_train_scripts/eval_cifar100_5bit.sh
#!/bin/bash python main.py --conf_path ./cifar100_resnet20.hocon --multi_label_prob 0.4 --multi_label_num 50 --id 01 --qw 5 --qa 5 --eval
139
45.666667
126
sh
null
qimera-main/other_train_scripts/eval_cifar10_5bit.sh
#!/bin/bash python main.py --conf_path ./cifar10_resnet20.hocon --multi_label_prob 0.4 --multi_label_num 2 --id 01 --randemb --qw 5 --qa 5 --eval
146
48
133
sh
null
qimera-main/other_train_scripts/eval_imgnet_mobilenet_v2_5bit.sh
#!/bin/bash python main.py --conf_path ./imagenet_mobilenet_v2.hocon --multi_label_prob 0.4 --multi_label_num 100 --id 01 --randemb --qw 5 --qa 5 --eval
154
50.666667
141
sh
null
qimera-main/other_train_scripts/eval_imgnet_resnet18_5bit.sh
#!/bin/bash python main.py --conf_path ./imagenet_resnet18.hocon --multi_label_prob 0.4 --multi_label_num 100 --id 01 --randemb --qw 5 --qa 5 --eval
150
49.333333
137
sh
null
qimera-main/other_train_scripts/eval_imgnet_resnet50_5bit.sh
#!/bin/bash python main.py --conf_path ./imagenet_resnet50.hocon --multi_label_prob 0.7 --multi_label_num 100 --id 01 --qw 5 --qa 5 --eval
140
46
127
sh
null
qimera-main/other_train_scripts/run_cifar100_5bit.sh
#!/bin/bash python main.py --conf_path ./cifar100_resnet20.hocon --multi_label_prob 0.4 --multi_label_num 50 --id 01 --qw 5 --qa 5
132
43.333333
119
sh
null
qimera-main/other_train_scripts/run_cifar10_5bit.sh
#!/bin/bash python main.py --conf_path ./cifar10_resnet20.hocon --multi_label_prob 0.4 --multi_label_num 2 --id 01 --randemb --qw 5 --qa 5
139
45.666667
126
sh
null
qimera-main/other_train_scripts/run_imgnet_mobilenet_v2_5bit.sh
#!/bin/bash python main.py --conf_path ./imagenet_mobilenet_v2.hocon --multi_label_prob 0.4 --multi_label_num 100 --id 01 --randemb --qw 5 --qa 5
147
48.333333
134
sh
null
qimera-main/other_train_scripts/run_imgnet_resnet18_5bit.sh
#!/bin/bash python main.py --conf_path ./imagenet_resnet18.hocon --multi_label_prob 0.4 --multi_label_num 100 --id 01 --randemb --qw 5 --qa 5
143
47
130
sh
null
qimera-main/other_train_scripts/run_imgnet_resnet50_5bit.sh
#!/bin/bash python main.py --conf_path ./imagenet_resnet50.hocon --multi_label_prob 0.7 --multi_label_num 100 --id 01 --qw 5 --qa 5
133
43.666667
120
sh
AMG
AMG-master/HYPRE.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header file for HYPRE library * *****************************************************************************/ #ifndef HYPRE_HEADER #define HYPRE_HEADER #define HYPRE_NO_GLOBAL_PARTITION 1 /*-------------------------------------------------------------------------- * Type definitions *--------------------------------------------------------------------------*/ #ifdef HYPRE_BIGINT typedef long long int HYPRE_Int; #define HYPRE_MPI_INT MPI_LONG_LONG #else typedef int HYPRE_Int; #define HYPRE_MPI_INT MPI_INT #endif /*-------------------------------------------------------------------------- * Constants *--------------------------------------------------------------------------*/ #define HYPRE_UNITIALIZED -999 #define HYPRE_PETSC_MAT_PARILUT_SOLVER 222 #define HYPRE_PARILUT 333 #define HYPRE_STRUCT 1111 #define HYPRE_SSTRUCT 3333 #define HYPRE_PARCSR 5555 #define HYPRE_ISIS 9911 #define HYPRE_PETSC 9933 #define HYPRE_PFMG 10 #define HYPRE_SMG 11 #define HYPRE_Jacobi 17 #endif
2,050
30.553846
81
h
AMG
AMG-master/IJ_mv/HYPRE_IJ_mv.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef HYPRE_IJ_MV_HEADER #define HYPRE_IJ_MV_HEADER #include "HYPRE_utilities.h" #ifdef __cplusplus extern "C" { #endif /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name IJ System Interface * * This interface represents a linear-algebraic conceptual view of a * linear system. The 'I' and 'J' in the name are meant to be * mnemonic for the traditional matrix notation A(I,J). * * @memo A linear-algebraic conceptual interface **/ /*@{*/ /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name IJ Matrices **/ /*@{*/ struct hypre_IJMatrix_struct; /** * The matrix object. **/ typedef struct hypre_IJMatrix_struct *HYPRE_IJMatrix; /** * Create a matrix object. Each process owns some unique consecutive * range of rows, indicated by the global row indices {\tt ilower} and * {\tt iupper}. The row data is required to be such that the value * of {\tt ilower} on any process $p$ be exactly one more than the * value of {\tt iupper} on process $p-1$. Note that the first row of * the global matrix may start with any integer value. In particular, * one may use zero- or one-based indexing. * * For square matrices, {\tt jlower} and {\tt jupper} typically should * match {\tt ilower} and {\tt iupper}, respectively. For rectangular * matrices, {\tt jlower} and {\tt jupper} should define a * partitioning of the columns. This partitioning must be used for * any vector $v$ that will be used in matrix-vector products with the * rectangular matrix. The matrix data structure may use {\tt jlower} * and {\tt jupper} to store the diagonal blocks (rectangular in * general) of the matrix separately from the rest of the matrix. * * Collective. **/ HYPRE_Int HYPRE_IJMatrixCreate(MPI_Comm comm, HYPRE_Int ilower, HYPRE_Int iupper, HYPRE_Int jlower, HYPRE_Int jupper, HYPRE_IJMatrix *matrix); /** * Destroy a matrix object. An object should be explicitly destroyed * using this destructor when the user's code no longer needs direct * access to it. Once destroyed, the object must not be referenced * again. Note that the object may not be deallocated at the * completion of this call, since there may be internal package * references to the object. The object will then be destroyed when * all internal reference counts go to zero. **/ HYPRE_Int HYPRE_IJMatrixDestroy(HYPRE_IJMatrix matrix); /** * Prepare a matrix object for setting coefficient values. This * routine will also re-initialize an already assembled matrix, * allowing users to modify coefficient values. **/ HYPRE_Int HYPRE_IJMatrixInitialize(HYPRE_IJMatrix matrix); /** * Sets values for {\tt nrows} rows or partial rows of the matrix. * The arrays {\tt ncols} * and {\tt rows} are of dimension {\tt nrows} and contain the number * of columns in each row and the row indices, respectively. The * array {\tt cols} contains the column indices for each of the {\tt * rows}, and is ordered by rows. The data in the {\tt values} array * corresponds directly to the column entries in {\tt cols}. Erases * any previous values at the specified locations and replaces them * with new ones, or, if there was no value there before, inserts a * new one if set locally. Note that it is not possible to set values * on other processors. If one tries to set a value from proc i on proc j, * proc i will erase all previous occurrences of this value in its stack * (including values generated with AddToValues), and treat it like * a zero value. The actual value needs to be set on proc j. * * Note that a threaded version (threaded over the number of rows) * will be called if * HYPRE_IJMatrixSetOMPFlag is set to a value != 0. * This requires that rows[i] != rows[j] for i!= j * and is only efficient if a large number of rows is set in one call * to HYPRE_IJMatrixSetValues. * * Not collective. * **/ HYPRE_Int HYPRE_IJMatrixSetValues(HYPRE_IJMatrix matrix, HYPRE_Int nrows, HYPRE_Int *ncols, const HYPRE_Int *rows, const HYPRE_Int *cols, const HYPRE_Complex *values); /** * Adds to values for {\tt nrows} rows or partial rows of the matrix. * Usage details are analogous to \Ref{HYPRE_IJMatrixSetValues}. * Adds to any previous values at the specified locations, or, if * there was no value there before, inserts a new one. * AddToValues can be used to add to values on other processors. * * Note that a threaded version (threaded over the number of rows) * will be called if * HYPRE_IJMatrixSetOMPFlag is set to a value != 0. * This requires that rows[i] != rows[j] for i!= j * and is only efficient if a large number of rows is added in one call * to HYPRE_IJMatrixAddToValues. * * Not collective. * **/ HYPRE_Int HYPRE_IJMatrixAddToValues(HYPRE_IJMatrix matrix, HYPRE_Int nrows, HYPRE_Int *ncols, const HYPRE_Int *rows, const HYPRE_Int *cols, const HYPRE_Complex *values); /** * Finalize the construction of the matrix before using. **/ HYPRE_Int HYPRE_IJMatrixAssemble(HYPRE_IJMatrix matrix); /** * Gets number of nonzeros elements for {\tt nrows} rows specified in {\tt rows} * and returns them in {\tt ncols}, which needs to be allocated by the * user. **/ HYPRE_Int HYPRE_IJMatrixGetRowCounts(HYPRE_IJMatrix matrix, HYPRE_Int nrows, HYPRE_Int *rows, HYPRE_Int *ncols); /** * Gets values for {\tt nrows} rows or partial rows of the matrix. * Usage details are * analogous to \Ref{HYPRE_IJMatrixSetValues}. **/ HYPRE_Int HYPRE_IJMatrixGetValues(HYPRE_IJMatrix matrix, HYPRE_Int nrows, HYPRE_Int *ncols, HYPRE_Int *rows, HYPRE_Int *cols, HYPRE_Complex *values); /** * Set the storage type of the matrix object to be constructed. * Currently, {\tt type} can only be {\tt HYPRE\_PARCSR}. * * Not collective, but must be the same on all processes. * * @see HYPRE_IJMatrixGetObject **/ HYPRE_Int HYPRE_IJMatrixSetObjectType(HYPRE_IJMatrix matrix, HYPRE_Int type); /** * Get the storage type of the constructed matrix object. **/ HYPRE_Int HYPRE_IJMatrixGetObjectType(HYPRE_IJMatrix matrix, HYPRE_Int *type); /** * Gets range of rows owned by this processor and range * of column partitioning for this processor. **/ HYPRE_Int HYPRE_IJMatrixGetLocalRange(HYPRE_IJMatrix matrix, HYPRE_Int *ilower, HYPRE_Int *iupper, HYPRE_Int *jlower, HYPRE_Int *jupper); /** * Get a reference to the constructed matrix object. * * @see HYPRE_IJMatrixSetObjectType **/ HYPRE_Int HYPRE_IJMatrixGetObject(HYPRE_IJMatrix matrix, void **object); /** * (Optional) Set the max number of nonzeros to expect in each row. * The array {\tt sizes} contains estimated sizes for each row on this * process. This call can significantly improve the efficiency of * matrix construction, and should always be utilized if possible. * * Not collective. **/ HYPRE_Int HYPRE_IJMatrixSetRowSizes(HYPRE_IJMatrix matrix, const HYPRE_Int *sizes); /** * (Optional) Sets the exact number of nonzeros in each row of * the diagonal and off-diagonal blocks. The diagonal block is the * submatrix whose column numbers correspond to rows owned by this * process, and the off-diagonal block is everything else. The arrays * {\tt diag\_sizes} and {\tt offdiag\_sizes} contain estimated sizes * for each row of the diagonal and off-diagonal blocks, respectively. * This routine can significantly improve the efficiency of matrix * construction, and should always be utilized if possible. * * Not collective. **/ HYPRE_Int HYPRE_IJMatrixSetDiagOffdSizes(HYPRE_IJMatrix matrix, const HYPRE_Int *diag_sizes, const HYPRE_Int *offdiag_sizes); /** * (Optional) Sets the maximum number of elements that are expected to be set * (or added) on other processors from this processor * This routine can significantly improve the efficiency of matrix * construction, and should always be utilized if possible. * * Not collective. **/ HYPRE_Int HYPRE_IJMatrixSetMaxOffProcElmts(HYPRE_IJMatrix matrix, HYPRE_Int max_off_proc_elmts); /** * (Optional) Sets the print level, if the user wants to print * error messages. The default is 0, i.e. no error messages are printed. * **/ HYPRE_Int HYPRE_IJMatrixSetPrintLevel(HYPRE_IJMatrix matrix, HYPRE_Int print_level); /** * (Optional) if set, will use a threaded version of * HYPRE_IJMatrixSetValues and HYPRE_IJMatrixAddToValues. * This is only useful if a large number of rows is set or added to * at once. * * NOTE that the values in the rows array of HYPRE_IJMatrixSetValues * or HYPRE_IJMatrixAddToValues must be different from each other !!! * * This option is VERY inefficient if only a small number of rows * is set or added at once and/or * if reallocation of storage is required and/or * if values are added to off processor values. * **/ HYPRE_Int HYPRE_IJMatrixSetOMPFlag(HYPRE_IJMatrix matrix, HYPRE_Int omp_flag); /** * Read the matrix from file. This is mainly for debugging purposes. **/ HYPRE_Int HYPRE_IJMatrixRead(const char *filename, MPI_Comm comm, HYPRE_Int type, HYPRE_IJMatrix *matrix); /** * Print the matrix to file. This is mainly for debugging purposes. **/ HYPRE_Int HYPRE_IJMatrixPrint(HYPRE_IJMatrix matrix, const char *filename); /*@}*/ /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name IJ Vectors **/ /*@{*/ struct hypre_IJVector_struct; /** * The vector object. **/ typedef struct hypre_IJVector_struct *HYPRE_IJVector; /** * Create a vector object. Each process owns some unique consecutive * range of vector unknowns, indicated by the global indices {\tt * jlower} and {\tt jupper}. The data is required to be such that the * value of {\tt jlower} on any process $p$ be exactly one more than * the value of {\tt jupper} on process $p-1$. Note that the first * index of the global vector may start with any integer value. In * particular, one may use zero- or one-based indexing. * * Collective. **/ HYPRE_Int HYPRE_IJVectorCreate(MPI_Comm comm, HYPRE_Int jlower, HYPRE_Int jupper, HYPRE_IJVector *vector); /** * Destroy a vector object. An object should be explicitly destroyed * using this destructor when the user's code no longer needs direct * access to it. Once destroyed, the object must not be referenced * again. Note that the object may not be deallocated at the * completion of this call, since there may be internal package * references to the object. The object will then be destroyed when * all internal reference counts go to zero. **/ HYPRE_Int HYPRE_IJVectorDestroy(HYPRE_IJVector vector); /** * Prepare a vector object for setting coefficient values. This * routine will also re-initialize an already assembled vector, * allowing users to modify coefficient values. **/ HYPRE_Int HYPRE_IJVectorInitialize(HYPRE_IJVector vector); /** * (Optional) Sets the maximum number of elements that are expected to be set * (or added) on other processors from this processor * This routine can significantly improve the efficiency of matrix * construction, and should always be utilized if possible. * * Not collective. **/ HYPRE_Int HYPRE_IJVectorSetMaxOffProcElmts(HYPRE_IJVector vector, HYPRE_Int max_off_proc_elmts); /** * Sets values in vector. The arrays {\tt values} and {\tt indices} * are of dimension {\tt nvalues} and contain the vector values to be * set and the corresponding global vector indices, respectively. * Erases any previous values at the specified locations and replaces * them with new ones. Note that it is not possible to set values * on other processors. If one tries to set a value from proc i on proc j, * proc i will erase all previous occurrences of this value in its stack * (including values generated with AddToValues), and treat it like * a zero value. The actual value needs to be set on proc j. * * Not collective. **/ HYPRE_Int HYPRE_IJVectorSetValues(HYPRE_IJVector vector, HYPRE_Int nvalues, const HYPRE_Int *indices, const HYPRE_Complex *values); /** * Adds to values in vector. Usage details are analogous to * \Ref{HYPRE_IJVectorSetValues}. * Adds to any previous values at the specified locations, or, if * there was no value there before, inserts a new one. * AddToValues can be used to add to values on other processors. * * Not collective. **/ HYPRE_Int HYPRE_IJVectorAddToValues(HYPRE_IJVector vector, HYPRE_Int nvalues, const HYPRE_Int *indices, const HYPRE_Complex *values); /** * Finalize the construction of the vector before using. **/ HYPRE_Int HYPRE_IJVectorAssemble(HYPRE_IJVector vector); /** * Gets values in vector. Usage details are analogous to * \Ref{HYPRE_IJVectorSetValues}. * * Not collective. **/ HYPRE_Int HYPRE_IJVectorGetValues(HYPRE_IJVector vector, HYPRE_Int nvalues, const HYPRE_Int *indices, HYPRE_Complex *values); /** * Set the storage type of the vector object to be constructed. * Currently, {\tt type} can only be {\tt HYPRE\_PARCSR}. * * Not collective, but must be the same on all processes. * * @see HYPRE_IJVectorGetObject **/ HYPRE_Int HYPRE_IJVectorSetObjectType(HYPRE_IJVector vector, HYPRE_Int type); /** * Get the storage type of the constructed vector object. **/ HYPRE_Int HYPRE_IJVectorGetObjectType(HYPRE_IJVector vector, HYPRE_Int *type); /** * Returns range of the part of the vector owned by this processor. **/ HYPRE_Int HYPRE_IJVectorGetLocalRange(HYPRE_IJVector vector, HYPRE_Int *jlower, HYPRE_Int *jupper); /** * Get a reference to the constructed vector object. * * @see HYPRE_IJVectorSetObjectType **/ HYPRE_Int HYPRE_IJVectorGetObject(HYPRE_IJVector vector, void **object); /** * (Optional) Sets the print level, if the user wants to print * error messages. The default is 0, i.e. no error messages are printed. * **/ HYPRE_Int HYPRE_IJVectorSetPrintLevel(HYPRE_IJVector vector, HYPRE_Int print_level); /** * Read the vector from file. This is mainly for debugging purposes. **/ HYPRE_Int HYPRE_IJVectorRead(const char *filename, MPI_Comm comm, HYPRE_Int type, HYPRE_IJVector *vector); /** * Print the vector to file. This is mainly for debugging purposes. **/ HYPRE_Int HYPRE_IJVectorPrint(HYPRE_IJVector vector, const char *filename); /*@}*/ /*@}*/ #ifdef __cplusplus } #endif #endif
17,922
37.297009
81
h
AMG
AMG-master/IJ_mv/IJ_matrix.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header info for the hypre_IJMatrix structures * *****************************************************************************/ #ifndef hypre_IJ_MATRIX_HEADER #define hypre_IJ_MATRIX_HEADER /*-------------------------------------------------------------------------- * hypre_IJMatrix: *--------------------------------------------------------------------------*/ typedef struct hypre_IJMatrix_struct { MPI_Comm comm; HYPRE_Int *row_partitioning; /* distribution of rows across processors */ HYPRE_Int *col_partitioning; /* distribution of columns */ HYPRE_Int object_type; /* Indicates the type of "object" */ void *object; /* Structure for storing local portion */ void *translator; /* optional storage_type specfic structure for holding additional local info */ void *assumed_part; /* IJMatrix assumed partition */ HYPRE_Int assemble_flag; /* indicates whether matrix has been assembled */ HYPRE_Int global_first_row; /* these for data items are necessary */ HYPRE_Int global_first_col; /* to be able to avoind using the global */ HYPRE_Int global_num_rows; /* global partition */ HYPRE_Int global_num_cols; HYPRE_Int omp_flag; HYPRE_Int print_level; } hypre_IJMatrix; /*-------------------------------------------------------------------------- * Accessor macros: hypre_IJMatrix *--------------------------------------------------------------------------*/ #define hypre_IJMatrixComm(matrix) ((matrix) -> comm) #define hypre_IJMatrixRowPartitioning(matrix) ((matrix) -> row_partitioning) #define hypre_IJMatrixColPartitioning(matrix) ((matrix) -> col_partitioning) #define hypre_IJMatrixObjectType(matrix) ((matrix) -> object_type) #define hypre_IJMatrixObject(matrix) ((matrix) -> object) #define hypre_IJMatrixTranslator(matrix) ((matrix) -> translator) #define hypre_IJMatrixAssumedPart(matrix) ((matrix) -> assumed_part) #define hypre_IJMatrixAssembleFlag(matrix) ((matrix) -> assemble_flag) #define hypre_IJMatrixGlobalFirstRow(matrix) ((matrix) -> global_first_row) #define hypre_IJMatrixGlobalFirstCol(matrix) ((matrix) -> global_first_col) #define hypre_IJMatrixGlobalNumRows(matrix) ((matrix) -> global_num_rows) #define hypre_IJMatrixGlobalNumCols(matrix) ((matrix) -> global_num_cols) #define hypre_IJMatrixOMPFlag(matrix) ((matrix) -> omp_flag) #define hypre_IJMatrixPrintLevel(matrix) ((matrix) -> print_level) /*-------------------------------------------------------------------------- * prototypes for operations on local objects *--------------------------------------------------------------------------*/ #ifdef PETSC_AVAILABLE /* IJMatrix_petsc.c */ HYPRE_Int hypre_GetIJMatrixParCSRMatrix( HYPRE_IJMatrix IJmatrix, Mat *reference ) #endif #ifdef ISIS_AVAILABLE /* IJMatrix_isis.c */ HYPRE_Int hypre_GetIJMatrixISISMatrix( HYPRE_IJMatrix IJmatrix, RowMatrix *reference ) #endif #endif
4,194
41.373737
87
h
AMG
AMG-master/IJ_mv/IJ_vector.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header info for the hypre_IJMatrix structures * *****************************************************************************/ #ifndef hypre_IJ_VECTOR_HEADER #define hypre_IJ_VECTOR_HEADER /*-------------------------------------------------------------------------- * hypre_IJVector: *--------------------------------------------------------------------------*/ typedef struct hypre_IJVector_struct { MPI_Comm comm; HYPRE_Int *partitioning; /* Indicates partitioning over tasks */ HYPRE_Int object_type; /* Indicates the type of "local storage" */ void *object; /* Structure for storing local portion */ void *translator; /* Structure for storing off processor information */ void *assumed_part; /* IJ Vector assumed partition */ HYPRE_Int global_first_row; /* these for data items are necessary */ HYPRE_Int global_num_rows; /* to be able to avoid using the global */ /* global partition */ HYPRE_Int print_level; } hypre_IJVector; /*-------------------------------------------------------------------------- * Accessor macros: hypre_IJVector *--------------------------------------------------------------------------*/ #define hypre_IJVectorComm(vector) ((vector) -> comm) #define hypre_IJVectorPartitioning(vector) ((vector) -> partitioning) #define hypre_IJVectorObjectType(vector) ((vector) -> object_type) #define hypre_IJVectorObject(vector) ((vector) -> object) #define hypre_IJVectorTranslator(vector) ((vector) -> translator) #define hypre_IJVectorAssumedPart(vector) ((vector) -> assumed_part) #define hypre_IJVectorGlobalFirstRow(vector) ((vector) -> global_first_row) #define hypre_IJVectorGlobalNumRows(vector) ((vector) -> global_num_rows) #define hypre_IJVectorPrintLevel(vector) ((vector) -> print_level) /*-------------------------------------------------------------------------- * prototypes for operations on local objects *--------------------------------------------------------------------------*/ /* #include "./internal_protos.h" */ #endif
3,239
36.674419
86
h
AMG
AMG-master/IJ_mv/_hypre_IJ_mv.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /*#include <HYPRE_config.h>*/ #ifndef hypre_IJ_HEADER #define hypre_IJ_HEADER #include "_hypre_utilities.h" #include "seq_mv.h" #include "_hypre_parcsr_mv.h" #include "HYPRE_IJ_mv.h" #ifdef __cplusplus extern "C" { #endif /****************************************************************************** * * Header info for Auxiliary Parallel CSR Matrix data structures * * Note: this matrix currently uses 0-based indexing. * *****************************************************************************/ #ifndef hypre_AUX_PARCSR_MATRIX_HEADER #define hypre_AUX_PARCSR_MATRIX_HEADER /*-------------------------------------------------------------------------- * Auxiliary Parallel CSR Matrix *--------------------------------------------------------------------------*/ typedef struct { HYPRE_Int local_num_rows; /* defines number of rows on this processors */ HYPRE_Int local_num_cols; /* defines number of cols of diag */ HYPRE_Int need_aux; /* if need_aux = 1, aux_j, aux_data are used to generate the parcsr matrix (default), for need_aux = 0, data is put directly into parcsr structure (requires the knowledge of offd_i and diag_i ) */ HYPRE_Int *row_length; /* row_length_diag[i] contains number of stored elements in i-th row */ HYPRE_Int *row_space; /* row_space_diag[i] contains space allocated to i-th row */ HYPRE_Int **aux_j; /* contains collected column indices */ HYPRE_Complex **aux_data; /* contains collected data */ HYPRE_Int *indx_diag; /* indx_diag[i] points to first empty space of portion in diag_j , diag_data assigned to row i */ HYPRE_Int *indx_offd; /* indx_offd[i] points to first empty space of portion in offd_j , offd_data assigned to row i */ HYPRE_Int max_off_proc_elmts; /* length of off processor stash set for SetValues and AddTOValues */ HYPRE_Int current_num_elmts; /* current no. of elements stored in stash */ HYPRE_Int off_proc_i_indx; /* pointer to first empty space in set_off_proc_i_set */ HYPRE_Int *off_proc_i; /* length 2*num_off_procs_elmts, contains info pairs (code, no. of elmts) where code contains global row no. if SetValues, and (-global row no. -1) if AddToValues*/ HYPRE_Int *off_proc_j; /* contains column indices */ HYPRE_Complex *off_proc_data; /* contains corresponding data */ HYPRE_Int cancel_indx; /* number of elements that have to be deleted due to setting values from another processor */ } hypre_AuxParCSRMatrix; /*-------------------------------------------------------------------------- * Accessor functions for the Parallel CSR Matrix structure *--------------------------------------------------------------------------*/ #define hypre_AuxParCSRMatrixLocalNumRows(matrix) ((matrix) -> local_num_rows) #define hypre_AuxParCSRMatrixLocalNumCols(matrix) ((matrix) -> local_num_cols) #define hypre_AuxParCSRMatrixNeedAux(matrix) ((matrix) -> need_aux) #define hypre_AuxParCSRMatrixRowLength(matrix) ((matrix) -> row_length) #define hypre_AuxParCSRMatrixRowSpace(matrix) ((matrix) -> row_space) #define hypre_AuxParCSRMatrixAuxJ(matrix) ((matrix) -> aux_j) #define hypre_AuxParCSRMatrixAuxData(matrix) ((matrix) -> aux_data) #define hypre_AuxParCSRMatrixIndxDiag(matrix) ((matrix) -> indx_diag) #define hypre_AuxParCSRMatrixIndxOffd(matrix) ((matrix) -> indx_offd) #define hypre_AuxParCSRMatrixMaxOffProcElmts(matrix) ((matrix) -> max_off_proc_elmts) #define hypre_AuxParCSRMatrixCurrentNumElmts(matrix) ((matrix) -> current_num_elmts) #define hypre_AuxParCSRMatrixOffProcIIndx(matrix) ((matrix) -> off_proc_i_indx) #define hypre_AuxParCSRMatrixOffProcI(matrix) ((matrix) -> off_proc_i) #define hypre_AuxParCSRMatrixOffProcJ(matrix) ((matrix) -> off_proc_j) #define hypre_AuxParCSRMatrixOffProcData(matrix) ((matrix) -> off_proc_data) #define hypre_AuxParCSRMatrixCancelIndx(matrix) ((matrix) -> cancel_indx) #endif /****************************************************************************** * * Header info for Auxiliary Parallel Vector data structures * * Note: this vector currently uses 0-based indexing. * *****************************************************************************/ #ifndef hypre_AUX_PAR_VECTOR_HEADER #define hypre_AUX_PAR_VECTOR_HEADER /*-------------------------------------------------------------------------- * Auxiliary Parallel Vector *--------------------------------------------------------------------------*/ typedef struct { HYPRE_Int max_off_proc_elmts; /* length of off processor stash for SetValues and AddToValues*/ HYPRE_Int current_num_elmts; /* current no. of elements stored in stash */ HYPRE_Int *off_proc_i; /* contains column indices */ HYPRE_Complex *off_proc_data; /* contains corresponding data */ HYPRE_Int cancel_indx; /* number of elements that have to be deleted due to setting values from another processor */ } hypre_AuxParVector; /*-------------------------------------------------------------------------- * Accessor functions for the Parallel Vector structure *--------------------------------------------------------------------------*/ #define hypre_AuxParVectorMaxOffProcElmts(matrix) ((matrix) -> max_off_proc_elmts) #define hypre_AuxParVectorCurrentNumElmts(matrix) ((matrix) -> current_num_elmts) #define hypre_AuxParVectorOffProcI(matrix) ((matrix) -> off_proc_i) #define hypre_AuxParVectorOffProcData(matrix) ((matrix) -> off_proc_data) #define hypre_AuxParVectorCancelIndx(matrix) ((matrix) -> cancel_indx) #endif /****************************************************************************** * * Header info for the hypre_IJMatrix structures * *****************************************************************************/ #ifndef hypre_IJ_MATRIX_HEADER #define hypre_IJ_MATRIX_HEADER /*-------------------------------------------------------------------------- * hypre_IJMatrix: *--------------------------------------------------------------------------*/ typedef struct hypre_IJMatrix_struct { MPI_Comm comm; HYPRE_Int *row_partitioning; /* distribution of rows across processors */ HYPRE_Int *col_partitioning; /* distribution of columns */ HYPRE_Int object_type; /* Indicates the type of "object" */ void *object; /* Structure for storing local portion */ void *translator; /* optional storage_type specfic structure for holding additional local info */ void *assumed_part; /* IJMatrix assumed partition */ HYPRE_Int assemble_flag; /* indicates whether matrix has been assembled */ HYPRE_Int global_first_row; /* these for data items are necessary */ HYPRE_Int global_first_col; /* to be able to avoid using the */ HYPRE_Int global_num_rows; /* global partition */ HYPRE_Int global_num_cols; HYPRE_Int omp_flag; HYPRE_Int print_level; } hypre_IJMatrix; /*-------------------------------------------------------------------------- * Accessor macros: hypre_IJMatrix *--------------------------------------------------------------------------*/ #define hypre_IJMatrixComm(matrix) ((matrix) -> comm) #define hypre_IJMatrixRowPartitioning(matrix) ((matrix) -> row_partitioning) #define hypre_IJMatrixColPartitioning(matrix) ((matrix) -> col_partitioning) #define hypre_IJMatrixObjectType(matrix) ((matrix) -> object_type) #define hypre_IJMatrixObject(matrix) ((matrix) -> object) #define hypre_IJMatrixTranslator(matrix) ((matrix) -> translator) #define hypre_IJMatrixAssumedPart(matrix) ((matrix) -> assumed_part) #define hypre_IJMatrixAssembleFlag(matrix) ((matrix) -> assemble_flag) #define hypre_IJMatrixGlobalFirstRow(matrix) ((matrix) -> global_first_row) #define hypre_IJMatrixGlobalFirstCol(matrix) ((matrix) -> global_first_col) #define hypre_IJMatrixGlobalNumRows(matrix) ((matrix) -> global_num_rows) #define hypre_IJMatrixGlobalNumCols(matrix) ((matrix) -> global_num_cols) #define hypre_IJMatrixOMPFlag(matrix) ((matrix) -> omp_flag) #define hypre_IJMatrixPrintLevel(matrix) ((matrix) -> print_level) #endif /****************************************************************************** * * Header info for the hypre_IJMatrix structures * *****************************************************************************/ #ifndef hypre_IJ_VECTOR_HEADER #define hypre_IJ_VECTOR_HEADER /*-------------------------------------------------------------------------- * hypre_IJVector: *--------------------------------------------------------------------------*/ typedef struct hypre_IJVector_struct { MPI_Comm comm; HYPRE_Int *partitioning; /* Indicates partitioning over tasks */ HYPRE_Int object_type; /* Indicates the type of "local storage" */ void *object; /* Structure for storing local portion */ void *translator; /* Structure for storing off processor information */ void *assumed_part; /* IJ Vector assumed partition */ HYPRE_Int global_first_row; /* these for data items are necessary */ HYPRE_Int global_num_rows; /* to be able to avoid using the global */ /* global partition */ HYPRE_Int print_level; } hypre_IJVector; /*-------------------------------------------------------------------------- * Accessor macros: hypre_IJVector *--------------------------------------------------------------------------*/ #define hypre_IJVectorComm(vector) ((vector) -> comm) #define hypre_IJVectorPartitioning(vector) ((vector) -> partitioning) #define hypre_IJVectorObjectType(vector) ((vector) -> object_type) #define hypre_IJVectorObject(vector) ((vector) -> object) #define hypre_IJVectorTranslator(vector) ((vector) -> translator) #define hypre_IJVectorAssumedPart(vector) ((vector) -> assumed_part) #define hypre_IJVectorGlobalFirstRow(vector) ((vector) -> global_first_row) #define hypre_IJVectorGlobalNumRows(vector) ((vector) -> global_num_rows) #define hypre_IJVectorPrintLevel(vector) ((vector) -> print_level) /*-------------------------------------------------------------------------- * prototypes for operations on local objects *--------------------------------------------------------------------------*/ /* #include "./internal_protos.h" */ #endif /* aux_parcsr_matrix.c */ HYPRE_Int hypre_AuxParCSRMatrixCreate ( hypre_AuxParCSRMatrix **aux_matrix , HYPRE_Int local_num_rows , HYPRE_Int local_num_cols , HYPRE_Int *sizes ); HYPRE_Int hypre_AuxParCSRMatrixDestroy ( hypre_AuxParCSRMatrix *matrix ); HYPRE_Int hypre_AuxParCSRMatrixInitialize ( hypre_AuxParCSRMatrix *matrix ); HYPRE_Int hypre_AuxParCSRMatrixSetMaxOffPRocElmts ( hypre_AuxParCSRMatrix *matrix , HYPRE_Int max_off_proc_elmts ); /* aux_par_vector.c */ HYPRE_Int hypre_AuxParVectorCreate ( hypre_AuxParVector **aux_vector ); HYPRE_Int hypre_AuxParVectorDestroy ( hypre_AuxParVector *vector ); HYPRE_Int hypre_AuxParVectorInitialize ( hypre_AuxParVector *vector ); HYPRE_Int hypre_AuxParVectorSetMaxOffPRocElmts ( hypre_AuxParVector *vector , HYPRE_Int max_off_proc_elmts ); /* IJ_assumed_part.c */ HYPRE_Int hypre_IJMatrixCreateAssumedPartition ( hypre_IJMatrix *matrix ); HYPRE_Int hypre_IJVectorCreateAssumedPartition ( hypre_IJVector *vector ); /* IJMatrix.c */ HYPRE_Int hypre_IJMatrixGetRowPartitioning ( HYPRE_IJMatrix matrix , HYPRE_Int **row_partitioning ); HYPRE_Int hypre_IJMatrixGetColPartitioning ( HYPRE_IJMatrix matrix , HYPRE_Int **col_partitioning ); HYPRE_Int hypre_IJMatrixSetObject ( HYPRE_IJMatrix matrix , void *object ); /* IJMatrix_parcsr.c */ HYPRE_Int hypre_IJMatrixCreateParCSR ( hypre_IJMatrix *matrix ); HYPRE_Int hypre_IJMatrixSetRowSizesParCSR ( hypre_IJMatrix *matrix , const HYPRE_Int *sizes ); HYPRE_Int hypre_IJMatrixSetDiagOffdSizesParCSR ( hypre_IJMatrix *matrix , const HYPRE_Int *diag_sizes , const HYPRE_Int *offdiag_sizes ); HYPRE_Int hypre_IJMatrixSetMaxOffProcElmtsParCSR ( hypre_IJMatrix *matrix , HYPRE_Int max_off_proc_elmts ); HYPRE_Int hypre_IJMatrixInitializeParCSR ( hypre_IJMatrix *matrix ); HYPRE_Int hypre_IJMatrixGetRowCountsParCSR ( hypre_IJMatrix *matrix , HYPRE_Int nrows , HYPRE_Int *rows , HYPRE_Int *ncols ); HYPRE_Int hypre_IJMatrixGetValuesParCSR ( hypre_IJMatrix *matrix , HYPRE_Int nrows , HYPRE_Int *ncols , HYPRE_Int *rows , HYPRE_Int *cols , HYPRE_Complex *values ); HYPRE_Int hypre_IJMatrixSetValuesParCSR ( hypre_IJMatrix *matrix , HYPRE_Int nrows , HYPRE_Int *ncols , const HYPRE_Int *rows , const HYPRE_Int *cols , const HYPRE_Complex *values ); HYPRE_Int hypre_IJMatrixAddToValuesParCSR ( hypre_IJMatrix *matrix , HYPRE_Int nrows , HYPRE_Int *ncols , const HYPRE_Int *rows , const HYPRE_Int *cols , const HYPRE_Complex *values ); HYPRE_Int hypre_IJMatrixDestroyParCSR ( hypre_IJMatrix *matrix ); HYPRE_Int hypre_IJMatrixAssembleOffProcValsParCSR ( hypre_IJMatrix *matrix , HYPRE_Int off_proc_i_indx , HYPRE_Int max_off_proc_elmts , HYPRE_Int current_num_elmts , HYPRE_Int *off_proc_i , HYPRE_Int *off_proc_j , HYPRE_Complex *off_proc_data ); HYPRE_Int hypre_FillResponseIJOffProcVals ( void *p_recv_contact_buf , HYPRE_Int contact_size , HYPRE_Int contact_proc , void *ro , MPI_Comm comm , void **p_send_response_buf , HYPRE_Int *response_message_size ); HYPRE_Int hypre_FindProc ( HYPRE_Int *list , HYPRE_Int value , HYPRE_Int list_length ); HYPRE_Int hypre_IJMatrixAssembleParCSR ( hypre_IJMatrix *matrix ); HYPRE_Int hypre_IJMatrixSetValuesOMPParCSR ( hypre_IJMatrix *matrix , HYPRE_Int nrows , HYPRE_Int *ncols , const HYPRE_Int *rows , const HYPRE_Int *cols , const HYPRE_Complex *values ); HYPRE_Int hypre_IJMatrixAddToValuesOMPParCSR ( hypre_IJMatrix *matrix , HYPRE_Int nrows , HYPRE_Int *ncols , const HYPRE_Int *rows , const HYPRE_Int *cols , const HYPRE_Complex *values ); /* IJVector.c */ HYPRE_Int hypre_IJVectorDistribute ( HYPRE_IJVector vector , const HYPRE_Int *vec_starts ); HYPRE_Int hypre_IJVectorZeroValues ( HYPRE_IJVector vector ); /* IJVector_parcsr.c */ HYPRE_Int hypre_IJVectorCreatePar ( hypre_IJVector *vector , HYPRE_Int *IJpartitioning ); HYPRE_Int hypre_IJVectorDestroyPar ( hypre_IJVector *vector ); HYPRE_Int hypre_IJVectorInitializePar ( hypre_IJVector *vector ); HYPRE_Int hypre_IJVectorSetMaxOffProcElmtsPar ( hypre_IJVector *vector , HYPRE_Int max_off_proc_elmts ); HYPRE_Int hypre_IJVectorDistributePar ( hypre_IJVector *vector , const HYPRE_Int *vec_starts ); HYPRE_Int hypre_IJVectorZeroValuesPar ( hypre_IJVector *vector ); HYPRE_Int hypre_IJVectorSetValuesPar ( hypre_IJVector *vector , HYPRE_Int num_values , const HYPRE_Int *indices , const HYPRE_Complex *values ); HYPRE_Int hypre_IJVectorAddToValuesPar ( hypre_IJVector *vector , HYPRE_Int num_values , const HYPRE_Int *indices , const HYPRE_Complex *values ); HYPRE_Int hypre_IJVectorAssemblePar ( hypre_IJVector *vector ); HYPRE_Int hypre_IJVectorGetValuesPar ( hypre_IJVector *vector , HYPRE_Int num_values , const HYPRE_Int *indices , HYPRE_Complex *values ); HYPRE_Int hypre_IJVectorAssembleOffProcValsPar ( hypre_IJVector *vector , HYPRE_Int max_off_proc_elmts , HYPRE_Int current_num_elmts , HYPRE_Int *off_proc_i , HYPRE_Complex *off_proc_data ); /* HYPRE_IJMatrix.c */ HYPRE_Int HYPRE_IJMatrixCreate ( MPI_Comm comm , HYPRE_Int ilower , HYPRE_Int iupper , HYPRE_Int jlower , HYPRE_Int jupper , HYPRE_IJMatrix *matrix ); HYPRE_Int HYPRE_IJMatrixDestroy ( HYPRE_IJMatrix matrix ); HYPRE_Int HYPRE_IJMatrixInitialize ( HYPRE_IJMatrix matrix ); HYPRE_Int HYPRE_IJMatrixSetPrintLevel ( HYPRE_IJMatrix matrix , HYPRE_Int print_level ); HYPRE_Int HYPRE_IJMatrixSetValues ( HYPRE_IJMatrix matrix , HYPRE_Int nrows , HYPRE_Int *ncols , const HYPRE_Int *rows , const HYPRE_Int *cols , const HYPRE_Complex *values ); HYPRE_Int HYPRE_IJMatrixAddToValues ( HYPRE_IJMatrix matrix , HYPRE_Int nrows , HYPRE_Int *ncols , const HYPRE_Int *rows , const HYPRE_Int *cols , const HYPRE_Complex *values ); HYPRE_Int HYPRE_IJMatrixAssemble ( HYPRE_IJMatrix matrix ); HYPRE_Int HYPRE_IJMatrixGetRowCounts ( HYPRE_IJMatrix matrix , HYPRE_Int nrows , HYPRE_Int *rows , HYPRE_Int *ncols ); HYPRE_Int HYPRE_IJMatrixGetValues ( HYPRE_IJMatrix matrix , HYPRE_Int nrows , HYPRE_Int *ncols , HYPRE_Int *rows , HYPRE_Int *cols , HYPRE_Complex *values ); HYPRE_Int HYPRE_IJMatrixSetObjectType ( HYPRE_IJMatrix matrix , HYPRE_Int type ); HYPRE_Int HYPRE_IJMatrixGetObjectType ( HYPRE_IJMatrix matrix , HYPRE_Int *type ); HYPRE_Int HYPRE_IJMatrixGetLocalRange ( HYPRE_IJMatrix matrix , HYPRE_Int *ilower , HYPRE_Int *iupper , HYPRE_Int *jlower , HYPRE_Int *jupper ); HYPRE_Int HYPRE_IJMatrixGetObject ( HYPRE_IJMatrix matrix , void **object ); HYPRE_Int HYPRE_IJMatrixSetRowSizes ( HYPRE_IJMatrix matrix , const HYPRE_Int *sizes ); HYPRE_Int HYPRE_IJMatrixSetDiagOffdSizes ( HYPRE_IJMatrix matrix , const HYPRE_Int *diag_sizes , const HYPRE_Int *offdiag_sizes ); HYPRE_Int HYPRE_IJMatrixSetMaxOffProcElmts ( HYPRE_IJMatrix matrix , HYPRE_Int max_off_proc_elmts ); HYPRE_Int HYPRE_IJMatrixRead ( const char *filename , MPI_Comm comm , HYPRE_Int type , HYPRE_IJMatrix *matrix_ptr ); HYPRE_Int HYPRE_IJMatrixPrint ( HYPRE_IJMatrix matrix , const char *filename ); HYPRE_Int HYPRE_IJMatrixSetOMPFlag ( HYPRE_IJMatrix matrix , HYPRE_Int omp_flag ); /* HYPRE_IJVector.c */ HYPRE_Int HYPRE_IJVectorCreate ( MPI_Comm comm , HYPRE_Int jlower , HYPRE_Int jupper , HYPRE_IJVector *vector ); HYPRE_Int HYPRE_IJVectorDestroy ( HYPRE_IJVector vector ); HYPRE_Int HYPRE_IJVectorInitialize ( HYPRE_IJVector vector ); HYPRE_Int HYPRE_IJVectorSetPrintLevel ( HYPRE_IJVector vector , HYPRE_Int print_level ); HYPRE_Int HYPRE_IJVectorSetValues ( HYPRE_IJVector vector , HYPRE_Int nvalues , const HYPRE_Int *indices , const HYPRE_Complex *values ); HYPRE_Int HYPRE_IJVectorAddToValues ( HYPRE_IJVector vector , HYPRE_Int nvalues , const HYPRE_Int *indices , const HYPRE_Complex *values ); HYPRE_Int HYPRE_IJVectorAssemble ( HYPRE_IJVector vector ); HYPRE_Int HYPRE_IJVectorGetValues ( HYPRE_IJVector vector , HYPRE_Int nvalues , const HYPRE_Int *indices , HYPRE_Complex *values ); HYPRE_Int HYPRE_IJVectorSetMaxOffProcElmts ( HYPRE_IJVector vector , HYPRE_Int max_off_proc_elmts ); HYPRE_Int HYPRE_IJVectorSetObjectType ( HYPRE_IJVector vector , HYPRE_Int type ); HYPRE_Int HYPRE_IJVectorGetObjectType ( HYPRE_IJVector vector , HYPRE_Int *type ); HYPRE_Int HYPRE_IJVectorGetLocalRange ( HYPRE_IJVector vector , HYPRE_Int *jlower , HYPRE_Int *jupper ); HYPRE_Int HYPRE_IJVectorGetObject ( HYPRE_IJVector vector , void **object ); HYPRE_Int HYPRE_IJVectorRead ( const char *filename , MPI_Comm comm , HYPRE_Int type , HYPRE_IJVector *vector_ptr ); HYPRE_Int HYPRE_IJVectorPrint ( HYPRE_IJVector vector , const char *filename ); #ifdef __cplusplus } #endif #endif
20,542
53.203166
245
h
AMG
AMG-master/IJ_mv/aux_par_vector.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header info for Auxiliary Parallel Vector data structures * * Note: this vector currently uses 0-based indexing. * *****************************************************************************/ #ifndef hypre_AUX_PAR_VECTOR_HEADER #define hypre_AUX_PAR_VECTOR_HEADER /*-------------------------------------------------------------------------- * Auxiliary Parallel Vector *--------------------------------------------------------------------------*/ typedef struct { HYPRE_Int max_off_proc_elmts; /* length of off processor stash for SetValues and AddToValues*/ HYPRE_Int current_num_elmts; /* current no. of elements stored in stash */ HYPRE_Int *off_proc_i; /* contains column indices */ HYPRE_Complex *off_proc_data; /* contains corresponding data */ HYPRE_Int cancel_indx; /* number of elements that have to be deleted due to setting values from another processor */ } hypre_AuxParVector; /*-------------------------------------------------------------------------- * Accessor functions for the Parallel Vector structure *--------------------------------------------------------------------------*/ #define hypre_AuxParVectorMaxOffProcElmts(matrix) ((matrix) -> max_off_proc_elmts) #define hypre_AuxParVectorCurrentNumElmts(matrix) ((matrix) -> current_num_elmts) #define hypre_AuxParVectorOffProcI(matrix) ((matrix) -> off_proc_i) #define hypre_AuxParVectorOffProcData(matrix) ((matrix) -> off_proc_data) #define hypre_AuxParVectorCancelIndx(matrix) ((matrix) -> cancel_indx) #endif
2,631
46.854545
83
h
AMG
AMG-master/IJ_mv/aux_parcsr_matrix.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header info for Auxiliary Parallel CSR Matrix data structures * * Note: this matrix currently uses 0-based indexing. * *****************************************************************************/ #ifndef hypre_AUX_PARCSR_MATRIX_HEADER #define hypre_AUX_PARCSR_MATRIX_HEADER /*-------------------------------------------------------------------------- * Auxiliary Parallel CSR Matrix *--------------------------------------------------------------------------*/ typedef struct { HYPRE_Int local_num_rows; /* defines number of rows on this processors */ HYPRE_Int local_num_cols; /* defines number of cols of diag */ HYPRE_Int need_aux; /* if need_aux = 1, aux_j, aux_data are used to generate the parcsr matrix (default), for need_aux = 0, data is put directly into parcsr structure (requires the knowledge of offd_i and diag_i ) */ HYPRE_Int *row_length; /* row_length_diag[i] contains number of stored elements in i-th row */ HYPRE_Int *row_space; /* row_space_diag[i] contains space allocated to i-th row */ HYPRE_Int **aux_j; /* contains collected column indices */ HYPRE_Complex **aux_data; /* contains collected data */ HYPRE_Int *indx_diag; /* indx_diag[i] points to first empty space of portion in diag_j , diag_data assigned to row i */ HYPRE_Int *indx_offd; /* indx_offd[i] points to first empty space of portion in offd_j , offd_data assigned to row i */ HYPRE_Int max_off_proc_elmts; /* length of off processor stash set for SetValues and AddTOValues */ HYPRE_Int current_num_elmts; /* current no. of elements stored in stash */ HYPRE_Int off_proc_i_indx; /* pointer to first empty space in set_off_proc_i_set */ HYPRE_Int *off_proc_i; /* length 2*num_off_procs_elmts, contains info pairs (code, no. of elmts) where code contains global row no. if SetValues, and (-global row no. -1) if AddToValues*/ HYPRE_Int *off_proc_j; /* contains column indices */ HYPRE_Complex *off_proc_data; /* contains corresponding data */ HYPRE_Int cancel_indx; /* number of elements that have to be deleted due to setting values from another processor */ } hypre_AuxParCSRMatrix; /*-------------------------------------------------------------------------- * Accessor functions for the Parallel CSR Matrix structure *--------------------------------------------------------------------------*/ #define hypre_AuxParCSRMatrixLocalNumRows(matrix) ((matrix) -> local_num_rows) #define hypre_AuxParCSRMatrixLocalNumCols(matrix) ((matrix) -> local_num_cols) #define hypre_AuxParCSRMatrixNeedAux(matrix) ((matrix) -> need_aux) #define hypre_AuxParCSRMatrixRowLength(matrix) ((matrix) -> row_length) #define hypre_AuxParCSRMatrixRowSpace(matrix) ((matrix) -> row_space) #define hypre_AuxParCSRMatrixAuxJ(matrix) ((matrix) -> aux_j) #define hypre_AuxParCSRMatrixAuxData(matrix) ((matrix) -> aux_data) #define hypre_AuxParCSRMatrixIndxDiag(matrix) ((matrix) -> indx_diag) #define hypre_AuxParCSRMatrixIndxOffd(matrix) ((matrix) -> indx_offd) #define hypre_AuxParCSRMatrixMaxOffProcElmts(matrix) ((matrix) -> max_off_proc_elmts) #define hypre_AuxParCSRMatrixCurrentNumElmts(matrix) ((matrix) -> current_num_elmts) #define hypre_AuxParCSRMatrixOffProcIIndx(matrix) ((matrix) -> off_proc_i_indx) #define hypre_AuxParCSRMatrixOffProcI(matrix) ((matrix) -> off_proc_i) #define hypre_AuxParCSRMatrixOffProcJ(matrix) ((matrix) -> off_proc_j) #define hypre_AuxParCSRMatrixOffProcData(matrix) ((matrix) -> off_proc_data) #define hypre_AuxParCSRMatrixCancelIndx(matrix) ((matrix) -> cancel_indx) #endif
5,131
53.021053
86
h
AMG
AMG-master/IJ_mv/headers.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #include <stdlib.h> #include <stdio.h> #include <math.h> #include "_hypre_IJ_mv.h" #include "HYPRE_IJ_mv.h"
1,038
36.107143
81
h
AMG
AMG-master/krylov/HYPRE_MatvecFunctions.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef HYPRE_MATVEC_FUNCTIONS #define HYPRE_MATVEC_FUNCTIONS typedef struct { void* (*MatvecCreate) ( void *A, void *x ); HYPRE_Int (*Matvec) ( void *matvec_data, HYPRE_Complex alpha, void *A, void *x, HYPRE_Complex beta, void *y ); HYPRE_Int (*MatvecDestroy) ( void *matvec_data ); void* (*MatMultiVecCreate) ( void *A, void *x ); HYPRE_Int (*MatMultiVec) ( void *data, HYPRE_Complex alpha, void *A, void *x, HYPRE_Complex beta, void *y ); HYPRE_Int (*MatMultiVecDestroy) ( void *data ); } HYPRE_MatvecFunctions; #endif
1,565
42.5
81
h
AMG
AMG-master/krylov/HYPRE_krylov.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef HYPRE_KRYLOV_HEADER #define HYPRE_KRYLOV_HEADER #include "HYPRE_utilities.h" #ifdef __cplusplus extern "C" { #endif /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name Krylov Solvers * * These solvers support many of the matrix/vector storage schemes in hypre. * They should be used in conjunction with the storage-specific interfaces, * particularly the specific Create() and Destroy() functions. * * @memo A basic interface for Krylov solvers **/ /*@{*/ /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name Krylov Solvers **/ /*@{*/ #ifndef HYPRE_SOLVER_STRUCT #define HYPRE_SOLVER_STRUCT struct hypre_Solver_struct; /** * The solver object. **/ typedef struct hypre_Solver_struct *HYPRE_Solver; #endif #ifndef HYPRE_MATRIX_STRUCT #define HYPRE_MATRIX_STRUCT struct hypre_Matrix_struct; /** * The matrix object. **/ typedef struct hypre_Matrix_struct *HYPRE_Matrix; #endif #ifndef HYPRE_VECTOR_STRUCT #define HYPRE_VECTOR_STRUCT struct hypre_Vector_struct; /** * The vector object. **/ typedef struct hypre_Vector_struct *HYPRE_Vector; #endif typedef HYPRE_Int (*HYPRE_PtrToSolverFcn)(HYPRE_Solver, HYPRE_Matrix, HYPRE_Vector, HYPRE_Vector); #ifndef HYPRE_MODIFYPC #define HYPRE_MODIFYPC typedef HYPRE_Int (*HYPRE_PtrToModifyPCFcn)(HYPRE_Solver, HYPRE_Int, HYPRE_Real); #endif /*@}*/ /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name PCG Solver **/ /*@{*/ /** * Prepare to solve the system. The coefficient data in {\tt b} and {\tt x} is * ignored here, but information about the layout of the data may be used. **/ HYPRE_Int HYPRE_PCGSetup(HYPRE_Solver solver, HYPRE_Matrix A, HYPRE_Vector b, HYPRE_Vector x); /** * Solve the system. **/ HYPRE_Int HYPRE_PCGSolve(HYPRE_Solver solver, HYPRE_Matrix A, HYPRE_Vector b, HYPRE_Vector x); /** * (Optional) Set the relative convergence tolerance. **/ HYPRE_Int HYPRE_PCGSetTol(HYPRE_Solver solver, HYPRE_Real tol); /** * (Optional) Set the absolute convergence tolerance (default is * 0). If one desires the convergence test to check the absolute * convergence tolerance {\it only}, then set the relative convergence * tolerance to 0.0. (The default convergence test is $ <C*r,r> \leq$ * max(relative$\_$tolerance$^{2} \ast <C*b, b>$, absolute$\_$tolerance$^2$).) **/ HYPRE_Int HYPRE_PCGSetAbsoluteTol(HYPRE_Solver solver, HYPRE_Real a_tol); /** * (Optional) Set a residual-based convergence tolerance which checks if * $\|r_{old}-r_{new}\| < rtol \|b\|$. This is useful when trying to converge to * very low relative and/or absolute tolerances, in order to bail-out before * roundoff errors affect the approximation. **/ HYPRE_Int HYPRE_PCGSetResidualTol(HYPRE_Solver solver, HYPRE_Real rtol); /* * RE-VISIT **/ HYPRE_Int HYPRE_PCGSetAbsoluteTolFactor(HYPRE_Solver solver, HYPRE_Real abstolf); /* * RE-VISIT **/ HYPRE_Int HYPRE_PCGSetConvergenceFactorTol(HYPRE_Solver solver, HYPRE_Real cf_tol); /* * RE-VISIT **/ HYPRE_Int HYPRE_PCGSetStopCrit(HYPRE_Solver solver, HYPRE_Int stop_crit); /** * (Optional) Set maximum number of iterations. **/ HYPRE_Int HYPRE_PCGSetMaxIter(HYPRE_Solver solver, HYPRE_Int max_iter); /** * (Optional) Use the two-norm in stopping criteria. **/ HYPRE_Int HYPRE_PCGSetTwoNorm(HYPRE_Solver solver, HYPRE_Int two_norm); /** * (Optional) Additionally require that the relative difference in * successive iterates be small. **/ HYPRE_Int HYPRE_PCGSetRelChange(HYPRE_Solver solver, HYPRE_Int rel_change); /** * (Optional) Recompute the residual at the end to double-check convergence. **/ HYPRE_Int HYPRE_PCGSetRecomputeResidual(HYPRE_Solver solver, HYPRE_Int recompute_residual); /** * (Optional) Periodically recompute the residual while iterating. **/ HYPRE_Int HYPRE_PCGSetRecomputeResidualP(HYPRE_Solver solver, HYPRE_Int recompute_residual_p); /** * (Optional) Set the preconditioner to use. **/ HYPRE_Int HYPRE_PCGSetPrecond(HYPRE_Solver solver, HYPRE_PtrToSolverFcn precond, HYPRE_PtrToSolverFcn precond_setup, HYPRE_Solver precond_solver); /** * (Optional) Set the amount of logging to do. **/ HYPRE_Int HYPRE_PCGSetLogging(HYPRE_Solver solver, HYPRE_Int logging); /** * (Optional) Set the amount of printing to do to the screen. **/ HYPRE_Int HYPRE_PCGSetPrintLevel(HYPRE_Solver solver, HYPRE_Int level); /** * Return the number of iterations taken. **/ HYPRE_Int HYPRE_PCGGetNumIterations(HYPRE_Solver solver, HYPRE_Int *num_iterations); /** * Return the norm of the final relative residual. **/ HYPRE_Int HYPRE_PCGGetFinalRelativeResidualNorm(HYPRE_Solver solver, HYPRE_Real *norm); /** * Return the residual. **/ HYPRE_Int HYPRE_PCGGetResidual(HYPRE_Solver solver, void **residual); /** **/ HYPRE_Int HYPRE_PCGGetTol(HYPRE_Solver solver, HYPRE_Real *tol); /** **/ HYPRE_Int HYPRE_PCGGetResidualTol(HYPRE_Solver solver, HYPRE_Real *rtol); /* * RE-VISIT **/ HYPRE_Int HYPRE_PCGGetAbsoluteTolFactor(HYPRE_Solver solver, HYPRE_Real *abstolf); /* * RE-VISIT **/ HYPRE_Int HYPRE_PCGGetConvergenceFactorTol(HYPRE_Solver solver, HYPRE_Real *cf_tol); /* * RE-VISIT **/ HYPRE_Int HYPRE_PCGGetStopCrit(HYPRE_Solver solver, HYPRE_Int *stop_crit); /** **/ HYPRE_Int HYPRE_PCGGetMaxIter(HYPRE_Solver solver, HYPRE_Int *max_iter); /** **/ HYPRE_Int HYPRE_PCGGetTwoNorm(HYPRE_Solver solver, HYPRE_Int *two_norm); /** **/ HYPRE_Int HYPRE_PCGGetRelChange(HYPRE_Solver solver, HYPRE_Int *rel_change); /** **/ HYPRE_Int HYPRE_GMRESGetSkipRealResidualCheck(HYPRE_Solver solver, HYPRE_Int *skip_real_r_check); /** **/ HYPRE_Int HYPRE_PCGGetPrecond(HYPRE_Solver solver, HYPRE_Solver *precond_data_ptr); /** **/ HYPRE_Int HYPRE_PCGGetLogging(HYPRE_Solver solver, HYPRE_Int *level); /** **/ HYPRE_Int HYPRE_PCGGetPrintLevel(HYPRE_Solver solver, HYPRE_Int *level); /** **/ HYPRE_Int HYPRE_PCGGetConverged(HYPRE_Solver solver, HYPRE_Int *converged); /*@}*/ /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name GMRES Solver **/ /*@{*/ /** * Prepare to solve the system. The coefficient data in {\tt b} and {\tt x} is * ignored here, but information about the layout of the data may be used. **/ HYPRE_Int HYPRE_GMRESSetup(HYPRE_Solver solver, HYPRE_Matrix A, HYPRE_Vector b, HYPRE_Vector x); /** * Solve the system. **/ HYPRE_Int HYPRE_GMRESSolve(HYPRE_Solver solver, HYPRE_Matrix A, HYPRE_Vector b, HYPRE_Vector x); /** * (Optional) Set the relative convergence tolerance. **/ HYPRE_Int HYPRE_GMRESSetTol(HYPRE_Solver solver, HYPRE_Real tol); /** * (Optional) Set the absolute convergence tolerance (default is 0). * If one desires * the convergence test to check the absolute convergence tolerance {\it only}, then * set the relative convergence tolerance to 0.0. (The convergence test is * $\|r\| \leq$ max(relative$\_$tolerance$\ast \|b\|$, absolute$\_$tolerance).) * **/ HYPRE_Int HYPRE_GMRESSetAbsoluteTol(HYPRE_Solver solver, HYPRE_Real a_tol); /* * RE-VISIT **/ HYPRE_Int HYPRE_GMRESSetConvergenceFactorTol(HYPRE_Solver solver, HYPRE_Real cf_tol); /* * RE-VISIT **/ HYPRE_Int HYPRE_GMRESSetStopCrit(HYPRE_Solver solver, HYPRE_Int stop_crit); /* * RE-VISIT **/ HYPRE_Int HYPRE_GMRESSetMinIter(HYPRE_Solver solver, HYPRE_Int min_iter); /** * (Optional) Set maximum number of iterations. **/ HYPRE_Int HYPRE_GMRESSetMaxIter(HYPRE_Solver solver, HYPRE_Int max_iter); /** * (Optional) Set the maximum size of the Krylov space. **/ HYPRE_Int HYPRE_GMRESSetKDim(HYPRE_Solver solver, HYPRE_Int k_dim); /** * (Optional) Additionally require that the relative difference in * successive iterates be small. **/ HYPRE_Int HYPRE_GMRESSetRelChange(HYPRE_Solver solver, HYPRE_Int rel_change); /** * (Optional) By default, hypre checks for convergence by evaluating the actual * residual before returnig from GMRES (with restart if the true residual does * not indicate convergence). This option allows users to skip the evaluation * and the check of the actual residual for badly conditioned problems where * restart is not expected to be beneficial. **/ HYPRE_Int HYPRE_GMRESSetSkipRealResidualCheck(HYPRE_Solver solver, HYPRE_Int skip_real_r_check); /** * (Optional) Set the preconditioner to use. **/ HYPRE_Int HYPRE_GMRESSetPrecond(HYPRE_Solver solver, HYPRE_PtrToSolverFcn precond, HYPRE_PtrToSolverFcn precond_setup, HYPRE_Solver precond_solver); /** * (Optional) Set the amount of logging to do. **/ HYPRE_Int HYPRE_GMRESSetLogging(HYPRE_Solver solver, HYPRE_Int logging); /** * (Optional) Set the amount of printing to do to the screen. **/ HYPRE_Int HYPRE_GMRESSetPrintLevel(HYPRE_Solver solver, HYPRE_Int level); /** * Return the number of iterations taken. **/ HYPRE_Int HYPRE_GMRESGetNumIterations(HYPRE_Solver solver, HYPRE_Int *num_iterations); /** * Return the norm of the final relative residual. **/ HYPRE_Int HYPRE_GMRESGetFinalRelativeResidualNorm(HYPRE_Solver solver, HYPRE_Real *norm); /** * Return the residual. **/ HYPRE_Int HYPRE_GMRESGetResidual(HYPRE_Solver solver, void **residual); /** **/ HYPRE_Int HYPRE_GMRESGetTol(HYPRE_Solver solver, HYPRE_Real *tol); /** **/ HYPRE_Int HYPRE_GMRESGetAbsoluteTol(HYPRE_Solver solver, HYPRE_Real *tol); /* * RE-VISIT **/ HYPRE_Int HYPRE_GMRESGetConvergenceFactorTol(HYPRE_Solver solver, HYPRE_Real *cf_tol); /* * OBSOLETE **/ HYPRE_Int HYPRE_GMRESGetStopCrit(HYPRE_Solver solver, HYPRE_Int *stop_crit); /* * RE-VISIT **/ HYPRE_Int HYPRE_GMRESGetMinIter(HYPRE_Solver solver, HYPRE_Int *min_iter); /** **/ HYPRE_Int HYPRE_GMRESGetMaxIter(HYPRE_Solver solver, HYPRE_Int *max_iter); /** **/ HYPRE_Int HYPRE_GMRESGetKDim(HYPRE_Solver solver, HYPRE_Int *k_dim); /** **/ HYPRE_Int HYPRE_GMRESGetRelChange(HYPRE_Solver solver, HYPRE_Int *rel_change); /** **/ HYPRE_Int HYPRE_GMRESGetPrecond(HYPRE_Solver solver, HYPRE_Solver *precond_data_ptr); /** **/ HYPRE_Int HYPRE_GMRESGetLogging(HYPRE_Solver solver, HYPRE_Int *level); /** **/ HYPRE_Int HYPRE_GMRESGetPrintLevel(HYPRE_Solver solver, HYPRE_Int *level); /** **/ HYPRE_Int HYPRE_GMRESGetConverged(HYPRE_Solver solver, HYPRE_Int *converged); /*@}*/ /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /*@}*/ #ifdef __cplusplus } #endif #endif
13,743
27.279835
86
h
AMG
AMG-master/krylov/gmres.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * GMRES gmres * *****************************************************************************/ #ifndef hypre_KRYLOV_GMRES_HEADER #define hypre_KRYLOV_GMRES_HEADER /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name Generic GMRES Interface * * A general description of the interface goes here... * * @memo A generic GMRES linear solver interface * @version 0.1 * @author Jeffrey F. Painter **/ /*@{*/ /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------- * hypre_GMRESData and hypre_GMRESFunctions *--------------------------------------------------------------------------*/ /** * @name GMRES structs * * Description... **/ /*@{*/ /** * The {\tt hypre\_GMRESFunctions} object ... **/ typedef struct { char * (*CAlloc) ( size_t count, size_t elt_size ); HYPRE_Int (*Free) ( char *ptr ); HYPRE_Int (*CommInfo) ( void *A, HYPRE_Int *my_id, HYPRE_Int *num_procs ); void * (*CreateVector) ( void *vector ); void * (*CreateVectorArray) ( HYPRE_Int size, void *vectors ); HYPRE_Int (*DestroyVector) ( void *vector ); void * (*MatvecCreate) ( void *A, void *x ); HYPRE_Int (*Matvec) ( void *matvec_data, HYPRE_Complex alpha, void *A, void *x, HYPRE_Complex beta, void *y ); HYPRE_Int (*MatvecDestroy) ( void *matvec_data ); HYPRE_Real (*InnerProd) ( void *x, void *y ); HYPRE_Int (*CopyVector) ( void *x, void *y ); HYPRE_Int (*ClearVector) ( void *x ); HYPRE_Int (*ScaleVector) ( HYPRE_Complex alpha, void *x ); HYPRE_Int (*Axpy) ( HYPRE_Complex alpha, void *x, void *y ); HYPRE_Int (*precond) (); HYPRE_Int (*precond_setup) (); } hypre_GMRESFunctions; /** * The {\tt hypre\_GMRESData} object ... **/ typedef struct { HYPRE_Int k_dim; HYPRE_Int min_iter; HYPRE_Int max_iter; HYPRE_Int rel_change; HYPRE_Int skip_real_r_check; HYPRE_Int stop_crit; HYPRE_Int converged; HYPRE_Real tol; HYPRE_Real cf_tol; HYPRE_Real a_tol; HYPRE_Real rel_residual_norm; void *A; void *r; void *w; void *w_2; void **p; void *matvec_data; void *precond_data; hypre_GMRESFunctions * functions; /* log info (always logged) */ HYPRE_Int num_iterations; HYPRE_Int print_level; /* printing when print_level>0 */ HYPRE_Int logging; /* extra computations for logging when logging>0 */ HYPRE_Real *norms; char *log_file_name; } hypre_GMRESData; #ifdef __cplusplus extern "C" { #endif /** * @name generic GMRES Solver * * Description... **/ /*@{*/ /** * Description... * * @param param [IN] ... **/ hypre_GMRESFunctions * hypre_GMRESFunctionsCreate( char * (*CAlloc) ( size_t count, size_t elt_size ), HYPRE_Int (*Free) ( char *ptr ), HYPRE_Int (*CommInfo) ( void *A, HYPRE_Int *my_id, HYPRE_Int *num_procs ), void * (*CreateVector) ( void *vector ), void * (*CreateVectorArray) ( HYPRE_Int size, void *vectors ), HYPRE_Int (*DestroyVector) ( void *vector ), void * (*MatvecCreate) ( void *A, void *x ), HYPRE_Int (*Matvec) ( void *matvec_data, HYPRE_Complex alpha, void *A, void *x, HYPRE_Complex beta, void *y ), HYPRE_Int (*MatvecDestroy) ( void *matvec_data ), HYPRE_Real (*InnerProd) ( void *x, void *y ), HYPRE_Int (*CopyVector) ( void *x, void *y ), HYPRE_Int (*ClearVector) ( void *x ), HYPRE_Int (*ScaleVector) ( HYPRE_Complex alpha, void *x ), HYPRE_Int (*Axpy) ( HYPRE_Complex alpha, void *x, void *y ), HYPRE_Int (*PrecondSetup) ( void *vdata, void *A, void *b, void *x ), HYPRE_Int (*Precond) ( void *vdata, void *A, void *b, void *x ) ); /** * Description... * * @param param [IN] ... **/ void * hypre_GMRESCreate( hypre_GMRESFunctions *gmres_functions ); #ifdef __cplusplus } #endif #endif
5,459
30.37931
83
h
AMG
AMG-master/krylov/krylov.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #include "HYPRE_krylov.h" #ifndef hypre_KRYLOV_HEADER #define hypre_KRYLOV_HEADER #include <stdlib.h> #include <stdio.h> #include <math.h> #include "_hypre_utilities.h" #define hypre_CTAllocF(type, count, funcs) ( (type *)(*(funcs->CAlloc))((size_t)(count), (size_t)sizeof(type)) ) #define hypre_TFreeF( ptr, funcs ) ( (*(funcs->Free))((char *)ptr), ptr = NULL ) #ifdef __cplusplus extern "C" { #endif /****************************************************************************** * * GMRES gmres * *****************************************************************************/ #ifndef hypre_KRYLOV_GMRES_HEADER #define hypre_KRYLOV_GMRES_HEADER /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name Generic GMRES Interface * * A general description of the interface goes here... * * @memo A generic GMRES linear solver interface * @version 0.1 * @author Jeffrey F. Painter **/ /*@{*/ /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------- * hypre_GMRESData and hypre_GMRESFunctions *--------------------------------------------------------------------------*/ /** * @name GMRES structs * * Description... **/ /*@{*/ /** * The {\tt hypre\_GMRESFunctions} object ... **/ typedef struct { char * (*CAlloc) ( size_t count, size_t elt_size ); HYPRE_Int (*Free) ( char *ptr ); HYPRE_Int (*CommInfo) ( void *A, HYPRE_Int *my_id, HYPRE_Int *num_procs ); void * (*CreateVector) ( void *vector ); void * (*CreateVectorArray) ( HYPRE_Int size, void *vectors ); HYPRE_Int (*DestroyVector) ( void *vector ); void * (*MatvecCreate) ( void *A, void *x ); HYPRE_Int (*Matvec) ( void *matvec_data, HYPRE_Complex alpha, void *A, void *x, HYPRE_Complex beta, void *y ); HYPRE_Int (*MatvecDestroy) ( void *matvec_data ); HYPRE_Real (*InnerProd) ( void *x, void *y ); HYPRE_Int (*CopyVector) ( void *x, void *y ); HYPRE_Int (*ClearVector) ( void *x ); HYPRE_Int (*ScaleVector) ( HYPRE_Complex alpha, void *x ); HYPRE_Int (*Axpy) ( HYPRE_Complex alpha, void *x, void *y ); HYPRE_Int (*precond) (void *vdata , void *A , void *b , void *x); HYPRE_Int (*precond_setup) (void *vdata , void *A , void *b , void *x); } hypre_GMRESFunctions; /** * The {\tt hypre\_GMRESData} object ... **/ typedef struct { HYPRE_Int k_dim; HYPRE_Int min_iter; HYPRE_Int max_iter; HYPRE_Int rel_change; HYPRE_Int skip_real_r_check; HYPRE_Int stop_crit; HYPRE_Int converged; HYPRE_Real tol; HYPRE_Real cf_tol; HYPRE_Real a_tol; HYPRE_Real rel_residual_norm; void *A; void *r; void *w; void *w_2; void **p; void *matvec_data; void *precond_data; hypre_GMRESFunctions * functions; /* log info (always logged) */ HYPRE_Int num_iterations; HYPRE_Int print_level; /* printing when print_level>0 */ HYPRE_Int logging; /* extra computations for logging when logging>0 */ HYPRE_Real *norms; char *log_file_name; } hypre_GMRESData; #ifdef __cplusplus extern "C" { #endif /** * @name generic GMRES Solver * * Description... **/ /*@{*/ /** * Description... * * @param param [IN] ... **/ hypre_GMRESFunctions * hypre_GMRESFunctionsCreate( char * (*CAlloc) ( size_t count, size_t elt_size ), HYPRE_Int (*Free) ( char *ptr ), HYPRE_Int (*CommInfo) ( void *A, HYPRE_Int *my_id, HYPRE_Int *num_procs ), void * (*CreateVector) ( void *vector ), void * (*CreateVectorArray) ( HYPRE_Int size, void *vectors ), HYPRE_Int (*DestroyVector) ( void *vector ), void * (*MatvecCreate) ( void *A, void *x ), HYPRE_Int (*Matvec) ( void *matvec_data, HYPRE_Complex alpha, void *A, void *x, HYPRE_Complex beta, void *y ), HYPRE_Int (*MatvecDestroy) ( void *matvec_data ), HYPRE_Real (*InnerProd) ( void *x, void *y ), HYPRE_Int (*CopyVector) ( void *x, void *y ), HYPRE_Int (*ClearVector) ( void *x ), HYPRE_Int (*ScaleVector) ( HYPRE_Complex alpha, void *x ), HYPRE_Int (*Axpy) ( HYPRE_Complex alpha, void *x, void *y ), HYPRE_Int (*PrecondSetup) ( void *vdata, void *A, void *b, void *x ), HYPRE_Int (*Precond) ( void *vdata, void *A, void *b, void *x ) ); /** * Description... * * @param param [IN] ... **/ void * hypre_GMRESCreate( hypre_GMRESFunctions *gmres_functions ); #ifdef __cplusplus } #endif #endif /****************************************************************************** * * Preconditioned conjugate gradient (Omin) headers * *****************************************************************************/ #ifndef hypre_KRYLOV_PCG_HEADER #define hypre_KRYLOV_PCG_HEADER /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name Generic PCG Interface * * A general description of the interface goes here... * * @memo A generic PCG linear solver interface * @version 0.1 * @author Jeffrey F. Painter **/ /*@{*/ /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------- * hypre_PCGData and hypre_PCGFunctions *--------------------------------------------------------------------------*/ /** * @name PCG structs * * Description... **/ /*@{*/ /** * The {\tt hypre\_PCGSFunctions} object ... **/ typedef struct { char * (*CAlloc) ( size_t count, size_t elt_size ); HYPRE_Int (*Free) ( char *ptr ); HYPRE_Int (*CommInfo) ( void *A, HYPRE_Int *my_id, HYPRE_Int *num_procs ); void * (*CreateVector) ( void *vector ); HYPRE_Int (*DestroyVector) ( void *vector ); void * (*MatvecCreate) ( void *A, void *x ); HYPRE_Int (*Matvec) ( void *matvec_data, HYPRE_Complex alpha, void *A, void *x, HYPRE_Complex beta, void *y ); HYPRE_Int (*MatvecDestroy) ( void *matvec_data ); HYPRE_Real (*InnerProd) ( void *x, void *y ); HYPRE_Int (*CopyVector) ( void *x, void *y ); HYPRE_Int (*ClearVector) ( void *x ); HYPRE_Int (*ScaleVector) ( HYPRE_Complex alpha, void *x ); HYPRE_Int (*Axpy) ( HYPRE_Complex alpha, void *x, void *y ); HYPRE_Int (*precond)(void *vdata , void *A , void *b , void *x); HYPRE_Int (*precond_setup)(void *vdata , void *A , void *b , void *x); } hypre_PCGFunctions; /** * The {\tt hypre\_PCGData} object ... **/ /* Summary of Parameters to Control Stopping Test: - Standard (default) error tolerance: |delta-residual|/|right-hand-side|<tol where the norm is an energy norm wrt preconditioner, |r|=sqrt(<Cr,r>). - two_norm!=0 means: the norm is the L2 norm, |r|=sqrt(<r,r>) - rel_change!=0 means: if pass the other stopping criteria, also check the relative change in the solution x. Pass iff this relative change is small. - tol = relative error tolerance, as above -a_tol = absolute convergence tolerance (default is 0.0) If one desires the convergence test to check the absolute convergence tolerance *only*, then set the relative convergence tolerance to 0.0. (The default convergence test is <C*r,r> <= max(relative_tolerance^2 * <C*b, b>, absolute_tolerance^2) - cf_tol = convergence factor tolerance; if >0 used for special test for slow convergence - stop_crit!=0 means (TO BE PHASED OUT): pure absolute error tolerance rather than a pure relative error tolerance on the residual. Never applies if rel_change!=0 or atolf!=0. - atolf = absolute error tolerance factor to be used _together_ with the relative error tolerance, |delta-residual| / ( atolf + |right-hand-side| ) < tol (To BE PHASED OUT) - recompute_residual means: when the iteration seems to be converged, recompute the residual from scratch (r=b-Ax) and use this new residual to repeat the convergence test. This can be expensive, use this only if you have seen a problem with the regular residual computation. - recompute_residual_p means: recompute the residual from scratch (r=b-Ax) every "recompute_residual_p" iterations. This can be expensive and degrade the convergence. Use it only if you have seen a problem with the regular residual computation. */ typedef struct { HYPRE_Real tol; HYPRE_Real atolf; HYPRE_Real cf_tol; HYPRE_Real a_tol; HYPRE_Real rtol; HYPRE_Int max_iter; HYPRE_Int two_norm; HYPRE_Int rel_change; HYPRE_Int recompute_residual; HYPRE_Int recompute_residual_p; HYPRE_Int stop_crit; HYPRE_Int converged; void *A; void *p; void *s; void *r; /* ...contains the residual. This is currently kept permanently. If that is ever changed, it still must be kept if logging>1 */ HYPRE_Int owns_matvec_data; /* normally 1; if 0, don't delete it */ void *matvec_data; void *precond_data; hypre_PCGFunctions * functions; /* log info (always logged) */ HYPRE_Int num_iterations; HYPRE_Real rel_residual_norm; HYPRE_Int print_level; /* printing when print_level>0 */ HYPRE_Int logging; /* extra computations for logging when logging>0 */ HYPRE_Real *norms; HYPRE_Real *rel_norms; } hypre_PCGData; #define hypre_PCGDataOwnsMatvecData(pcgdata) ((pcgdata) -> owns_matvec_data) #ifdef __cplusplus extern "C" { #endif /** * @name generic PCG Solver * * Description... **/ /*@{*/ /** * Description... * * @param param [IN] ... **/ hypre_PCGFunctions * hypre_PCGFunctionsCreate( char * (*CAlloc) ( size_t count, size_t elt_size ), HYPRE_Int (*Free) ( char *ptr ), HYPRE_Int (*CommInfo) ( void *A, HYPRE_Int *my_id, HYPRE_Int *num_procs ), void * (*CreateVector) ( void *vector ), HYPRE_Int (*DestroyVector) ( void *vector ), void * (*MatvecCreate) ( void *A, void *x ), HYPRE_Int (*Matvec) ( void *matvec_data, HYPRE_Complex alpha, void *A, void *x, HYPRE_Complex beta, void *y ), HYPRE_Int (*MatvecDestroy) ( void *matvec_data ), HYPRE_Real (*InnerProd) ( void *x, void *y ), HYPRE_Int (*CopyVector) ( void *x, void *y ), HYPRE_Int (*ClearVector) ( void *x ), HYPRE_Int (*ScaleVector) ( HYPRE_Complex alpha, void *x ), HYPRE_Int (*Axpy) ( HYPRE_Complex alpha, void *x, void *y ), HYPRE_Int (*PrecondSetup) ( void *vdata, void *A, void *b, void *x ), HYPRE_Int (*Precond) ( void *vdata, void *A, void *b, void *x ) ); /** * Description... * * @param param [IN] ... **/ void * hypre_PCGCreate( hypre_PCGFunctions *pcg_functions ); #ifdef __cplusplus } #endif #endif /* gmres.c */ void *hypre_GMRESCreate ( hypre_GMRESFunctions *gmres_functions ); HYPRE_Int hypre_GMRESDestroy ( void *gmres_vdata ); HYPRE_Int hypre_GMRESGetResidual ( void *gmres_vdata , void **residual ); HYPRE_Int hypre_GMRESSetup ( void *gmres_vdata , void *A , void *b , void *x ); HYPRE_Int hypre_GMRESSolve ( void *gmres_vdata , void *A , void *b , void *x ); HYPRE_Int hypre_GMRESSetKDim ( void *gmres_vdata , HYPRE_Int k_dim ); HYPRE_Int hypre_GMRESGetKDim ( void *gmres_vdata , HYPRE_Int *k_dim ); HYPRE_Int hypre_GMRESSetTol ( void *gmres_vdata , HYPRE_Real tol ); HYPRE_Int hypre_GMRESGetTol ( void *gmres_vdata , HYPRE_Real *tol ); HYPRE_Int hypre_GMRESSetAbsoluteTol ( void *gmres_vdata , HYPRE_Real a_tol ); HYPRE_Int hypre_GMRESGetAbsoluteTol ( void *gmres_vdata , HYPRE_Real *a_tol ); HYPRE_Int hypre_GMRESSetConvergenceFactorTol ( void *gmres_vdata , HYPRE_Real cf_tol ); HYPRE_Int hypre_GMRESGetConvergenceFactorTol ( void *gmres_vdata , HYPRE_Real *cf_tol ); HYPRE_Int hypre_GMRESSetMinIter ( void *gmres_vdata , HYPRE_Int min_iter ); HYPRE_Int hypre_GMRESGetMinIter ( void *gmres_vdata , HYPRE_Int *min_iter ); HYPRE_Int hypre_GMRESSetMaxIter ( void *gmres_vdata , HYPRE_Int max_iter ); HYPRE_Int hypre_GMRESGetMaxIter ( void *gmres_vdata , HYPRE_Int *max_iter ); HYPRE_Int hypre_GMRESSetRelChange ( void *gmres_vdata , HYPRE_Int rel_change ); HYPRE_Int hypre_GMRESGetRelChange ( void *gmres_vdata , HYPRE_Int *rel_change ); HYPRE_Int hypre_GMRESSetSkipRealResidualCheck ( void *gmres_vdata , HYPRE_Int skip_real_r_check ); HYPRE_Int hypre_GMRESGetSkipRealResidualCheck ( void *gmres_vdata , HYPRE_Int *skip_real_r_check ); HYPRE_Int hypre_GMRESSetStopCrit ( void *gmres_vdata , HYPRE_Int stop_crit ); HYPRE_Int hypre_GMRESGetStopCrit ( void *gmres_vdata , HYPRE_Int *stop_crit ); HYPRE_Int hypre_GMRESSetPrecond ( void *gmres_vdata , HYPRE_Int (*precond )(void*,void*,void*,void*), HYPRE_Int (*precond_setup )(void*,void*,void*,void*), void *precond_data ); HYPRE_Int hypre_GMRESGetPrecond ( void *gmres_vdata , HYPRE_Solver *precond_data_ptr ); HYPRE_Int hypre_GMRESSetPrintLevel ( void *gmres_vdata , HYPRE_Int level ); HYPRE_Int hypre_GMRESGetPrintLevel ( void *gmres_vdata , HYPRE_Int *level ); HYPRE_Int hypre_GMRESSetLogging ( void *gmres_vdata , HYPRE_Int level ); HYPRE_Int hypre_GMRESGetLogging ( void *gmres_vdata , HYPRE_Int *level ); HYPRE_Int hypre_GMRESGetNumIterations ( void *gmres_vdata , HYPRE_Int *num_iterations ); HYPRE_Int hypre_GMRESGetConverged ( void *gmres_vdata , HYPRE_Int *converged ); HYPRE_Int hypre_GMRESGetFinalRelativeResidualNorm ( void *gmres_vdata , HYPRE_Real *relative_residual_norm ); /* HYPRE_gmres.c */ HYPRE_Int HYPRE_GMRESSetup ( HYPRE_Solver solver , HYPRE_Matrix A , HYPRE_Vector b , HYPRE_Vector x ); HYPRE_Int HYPRE_GMRESSolve ( HYPRE_Solver solver , HYPRE_Matrix A , HYPRE_Vector b , HYPRE_Vector x ); HYPRE_Int HYPRE_GMRESSetKDim ( HYPRE_Solver solver , HYPRE_Int k_dim ); HYPRE_Int HYPRE_GMRESGetKDim ( HYPRE_Solver solver , HYPRE_Int *k_dim ); HYPRE_Int HYPRE_GMRESSetTol ( HYPRE_Solver solver , HYPRE_Real tol ); HYPRE_Int HYPRE_GMRESGetTol ( HYPRE_Solver solver , HYPRE_Real *tol ); HYPRE_Int HYPRE_GMRESSetAbsoluteTol ( HYPRE_Solver solver , HYPRE_Real a_tol ); HYPRE_Int HYPRE_GMRESGetAbsoluteTol ( HYPRE_Solver solver , HYPRE_Real *a_tol ); HYPRE_Int HYPRE_GMRESSetConvergenceFactorTol ( HYPRE_Solver solver , HYPRE_Real cf_tol ); HYPRE_Int HYPRE_GMRESGetConvergenceFactorTol ( HYPRE_Solver solver , HYPRE_Real *cf_tol ); HYPRE_Int HYPRE_GMRESSetMinIter ( HYPRE_Solver solver , HYPRE_Int min_iter ); HYPRE_Int HYPRE_GMRESGetMinIter ( HYPRE_Solver solver , HYPRE_Int *min_iter ); HYPRE_Int HYPRE_GMRESSetMaxIter ( HYPRE_Solver solver , HYPRE_Int max_iter ); HYPRE_Int HYPRE_GMRESGetMaxIter ( HYPRE_Solver solver , HYPRE_Int *max_iter ); HYPRE_Int HYPRE_GMRESSetStopCrit ( HYPRE_Solver solver , HYPRE_Int stop_crit ); HYPRE_Int HYPRE_GMRESGetStopCrit ( HYPRE_Solver solver , HYPRE_Int *stop_crit ); HYPRE_Int HYPRE_GMRESSetRelChange ( HYPRE_Solver solver , HYPRE_Int rel_change ); HYPRE_Int HYPRE_GMRESGetRelChange ( HYPRE_Solver solver , HYPRE_Int *rel_change ); HYPRE_Int HYPRE_GMRESSetSkipRealResidualCheck ( HYPRE_Solver solver , HYPRE_Int skip_real_r_check ); HYPRE_Int HYPRE_GMRESGetSkipRealResidualCheck ( HYPRE_Solver solver , HYPRE_Int *skip_real_r_check ); HYPRE_Int HYPRE_GMRESSetPrecond ( HYPRE_Solver solver , HYPRE_PtrToSolverFcn precond , HYPRE_PtrToSolverFcn precond_setup , HYPRE_Solver precond_solver ); HYPRE_Int HYPRE_GMRESGetPrecond ( HYPRE_Solver solver , HYPRE_Solver *precond_data_ptr ); HYPRE_Int HYPRE_GMRESSetPrintLevel ( HYPRE_Solver solver , HYPRE_Int level ); HYPRE_Int HYPRE_GMRESGetPrintLevel ( HYPRE_Solver solver , HYPRE_Int *level ); HYPRE_Int HYPRE_GMRESSetLogging ( HYPRE_Solver solver , HYPRE_Int level ); HYPRE_Int HYPRE_GMRESGetLogging ( HYPRE_Solver solver , HYPRE_Int *level ); HYPRE_Int HYPRE_GMRESGetNumIterations ( HYPRE_Solver solver , HYPRE_Int *num_iterations ); HYPRE_Int HYPRE_GMRESGetConverged ( HYPRE_Solver solver , HYPRE_Int *converged ); HYPRE_Int HYPRE_GMRESGetFinalRelativeResidualNorm ( HYPRE_Solver solver , HYPRE_Real *norm ); HYPRE_Int HYPRE_GMRESGetResidual ( HYPRE_Solver solver , void **residual ); /* HYPRE_pcg.c */ HYPRE_Int HYPRE_PCGSetup ( HYPRE_Solver solver , HYPRE_Matrix A , HYPRE_Vector b , HYPRE_Vector x ); HYPRE_Int HYPRE_PCGSolve ( HYPRE_Solver solver , HYPRE_Matrix A , HYPRE_Vector b , HYPRE_Vector x ); HYPRE_Int HYPRE_PCGSetTol ( HYPRE_Solver solver , HYPRE_Real tol ); HYPRE_Int HYPRE_PCGGetTol ( HYPRE_Solver solver , HYPRE_Real *tol ); HYPRE_Int HYPRE_PCGSetAbsoluteTol ( HYPRE_Solver solver , HYPRE_Real a_tol ); HYPRE_Int HYPRE_PCGGetAbsoluteTol ( HYPRE_Solver solver , HYPRE_Real *a_tol ); HYPRE_Int HYPRE_PCGSetAbsoluteTolFactor ( HYPRE_Solver solver , HYPRE_Real abstolf ); HYPRE_Int HYPRE_PCGGetAbsoluteTolFactor ( HYPRE_Solver solver , HYPRE_Real *abstolf ); HYPRE_Int HYPRE_PCGSetResidualTol ( HYPRE_Solver solver , HYPRE_Real rtol ); HYPRE_Int HYPRE_PCGGetResidualTol ( HYPRE_Solver solver , HYPRE_Real *rtol ); HYPRE_Int HYPRE_PCGSetConvergenceFactorTol ( HYPRE_Solver solver , HYPRE_Real cf_tol ); HYPRE_Int HYPRE_PCGGetConvergenceFactorTol ( HYPRE_Solver solver , HYPRE_Real *cf_tol ); HYPRE_Int HYPRE_PCGSetMaxIter ( HYPRE_Solver solver , HYPRE_Int max_iter ); HYPRE_Int HYPRE_PCGGetMaxIter ( HYPRE_Solver solver , HYPRE_Int *max_iter ); HYPRE_Int HYPRE_PCGSetStopCrit ( HYPRE_Solver solver , HYPRE_Int stop_crit ); HYPRE_Int HYPRE_PCGGetStopCrit ( HYPRE_Solver solver , HYPRE_Int *stop_crit ); HYPRE_Int HYPRE_PCGSetTwoNorm ( HYPRE_Solver solver , HYPRE_Int two_norm ); HYPRE_Int HYPRE_PCGGetTwoNorm ( HYPRE_Solver solver , HYPRE_Int *two_norm ); HYPRE_Int HYPRE_PCGSetRelChange ( HYPRE_Solver solver , HYPRE_Int rel_change ); HYPRE_Int HYPRE_PCGGetRelChange ( HYPRE_Solver solver , HYPRE_Int *rel_change ); HYPRE_Int HYPRE_PCGSetRecomputeResidual ( HYPRE_Solver solver , HYPRE_Int recompute_residual ); HYPRE_Int HYPRE_PCGGetRecomputeResidual ( HYPRE_Solver solver , HYPRE_Int *recompute_residual ); HYPRE_Int HYPRE_PCGSetRecomputeResidualP ( HYPRE_Solver solver , HYPRE_Int recompute_residual_p ); HYPRE_Int HYPRE_PCGGetRecomputeResidualP ( HYPRE_Solver solver , HYPRE_Int *recompute_residual_p ); HYPRE_Int HYPRE_PCGSetPrecond ( HYPRE_Solver solver , HYPRE_PtrToSolverFcn precond , HYPRE_PtrToSolverFcn precond_setup , HYPRE_Solver precond_solver ); HYPRE_Int HYPRE_PCGGetPrecond ( HYPRE_Solver solver , HYPRE_Solver *precond_data_ptr ); HYPRE_Int HYPRE_PCGSetLogging ( HYPRE_Solver solver , HYPRE_Int level ); HYPRE_Int HYPRE_PCGGetLogging ( HYPRE_Solver solver , HYPRE_Int *level ); HYPRE_Int HYPRE_PCGSetPrintLevel ( HYPRE_Solver solver , HYPRE_Int level ); HYPRE_Int HYPRE_PCGGetPrintLevel ( HYPRE_Solver solver , HYPRE_Int *level ); HYPRE_Int HYPRE_PCGGetNumIterations ( HYPRE_Solver solver , HYPRE_Int *num_iterations ); HYPRE_Int HYPRE_PCGGetConverged ( HYPRE_Solver solver , HYPRE_Int *converged ); HYPRE_Int HYPRE_PCGGetFinalRelativeResidualNorm ( HYPRE_Solver solver , HYPRE_Real *norm ); HYPRE_Int HYPRE_PCGGetResidual ( HYPRE_Solver solver , void **residual ); /* pcg.c */ void *hypre_PCGCreate ( hypre_PCGFunctions *pcg_functions ); HYPRE_Int hypre_PCGDestroy ( void *pcg_vdata ); HYPRE_Int hypre_PCGGetResidual ( void *pcg_vdata , void **residual ); HYPRE_Int hypre_PCGSetup ( void *pcg_vdata , void *A , void *b , void *x ); HYPRE_Int hypre_PCGSolve ( void *pcg_vdata , void *A , void *b , void *x ); HYPRE_Int hypre_PCGSetTol ( void *pcg_vdata , HYPRE_Real tol ); HYPRE_Int hypre_PCGGetTol ( void *pcg_vdata , HYPRE_Real *tol ); HYPRE_Int hypre_PCGSetAbsoluteTol ( void *pcg_vdata , HYPRE_Real a_tol ); HYPRE_Int hypre_PCGGetAbsoluteTol ( void *pcg_vdata , HYPRE_Real *a_tol ); HYPRE_Int hypre_PCGSetAbsoluteTolFactor ( void *pcg_vdata , HYPRE_Real atolf ); HYPRE_Int hypre_PCGGetAbsoluteTolFactor ( void *pcg_vdata , HYPRE_Real *atolf ); HYPRE_Int hypre_PCGSetResidualTol ( void *pcg_vdata , HYPRE_Real rtol ); HYPRE_Int hypre_PCGGetResidualTol ( void *pcg_vdata , HYPRE_Real *rtol ); HYPRE_Int hypre_PCGSetConvergenceFactorTol ( void *pcg_vdata , HYPRE_Real cf_tol ); HYPRE_Int hypre_PCGGetConvergenceFactorTol ( void *pcg_vdata , HYPRE_Real *cf_tol ); HYPRE_Int hypre_PCGSetMaxIter ( void *pcg_vdata , HYPRE_Int max_iter ); HYPRE_Int hypre_PCGGetMaxIter ( void *pcg_vdata , HYPRE_Int *max_iter ); HYPRE_Int hypre_PCGSetTwoNorm ( void *pcg_vdata , HYPRE_Int two_norm ); HYPRE_Int hypre_PCGGetTwoNorm ( void *pcg_vdata , HYPRE_Int *two_norm ); HYPRE_Int hypre_PCGSetRelChange ( void *pcg_vdata , HYPRE_Int rel_change ); HYPRE_Int hypre_PCGGetRelChange ( void *pcg_vdata , HYPRE_Int *rel_change ); HYPRE_Int hypre_PCGSetRecomputeResidual ( void *pcg_vdata , HYPRE_Int recompute_residual ); HYPRE_Int hypre_PCGGetRecomputeResidual ( void *pcg_vdata , HYPRE_Int *recompute_residual ); HYPRE_Int hypre_PCGSetRecomputeResidualP ( void *pcg_vdata , HYPRE_Int recompute_residual_p ); HYPRE_Int hypre_PCGGetRecomputeResidualP ( void *pcg_vdata , HYPRE_Int *recompute_residual_p ); HYPRE_Int hypre_PCGSetStopCrit ( void *pcg_vdata , HYPRE_Int stop_crit ); HYPRE_Int hypre_PCGGetStopCrit ( void *pcg_vdata , HYPRE_Int *stop_crit ); HYPRE_Int hypre_PCGGetPrecond ( void *pcg_vdata , HYPRE_Solver *precond_data_ptr ); HYPRE_Int hypre_PCGSetPrecond ( void *pcg_vdata , HYPRE_Int (*precond )(void*,void*,void*,void*), HYPRE_Int (*precond_setup )(void*,void*,void*,void*), void *precond_data ); HYPRE_Int hypre_PCGSetPrintLevel ( void *pcg_vdata , HYPRE_Int level ); HYPRE_Int hypre_PCGGetPrintLevel ( void *pcg_vdata , HYPRE_Int *level ); HYPRE_Int hypre_PCGSetLogging ( void *pcg_vdata , HYPRE_Int level ); HYPRE_Int hypre_PCGGetLogging ( void *pcg_vdata , HYPRE_Int *level ); HYPRE_Int hypre_PCGGetNumIterations ( void *pcg_vdata , HYPRE_Int *num_iterations ); HYPRE_Int hypre_PCGGetConverged ( void *pcg_vdata , HYPRE_Int *converged ); HYPRE_Int hypre_PCGPrintLogging ( void *pcg_vdata , HYPRE_Int myid ); HYPRE_Int hypre_PCGGetFinalRelativeResidualNorm ( void *pcg_vdata , HYPRE_Real *relative_residual_norm ); #ifdef __cplusplus } #endif #endif
23,667
43.322097
178
h
AMG
AMG-master/krylov/pcg.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Preconditioned conjugate gradient (Omin) headers * *****************************************************************************/ #ifndef hypre_KRYLOV_PCG_HEADER #define hypre_KRYLOV_PCG_HEADER /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name Generic PCG Interface * * A general description of the interface goes here... * * @memo A generic PCG linear solver interface * @version 0.1 * @author Jeffrey F. Painter **/ /*@{*/ /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------- * hypre_PCGData and hypre_PCGFunctions *--------------------------------------------------------------------------*/ /** * @name PCG structs * * Description... **/ /*@{*/ /** * The {\tt hypre\_PCGSFunctions} object ... **/ typedef struct { char * (*CAlloc) ( size_t count, size_t elt_size ); HYPRE_Int (*Free) ( char *ptr ); HYPRE_Int (*CommInfo) ( void *A, HYPRE_Int *my_id, HYPRE_Int *num_procs ); void * (*CreateVector) ( void *vector ); HYPRE_Int (*DestroyVector) ( void *vector ); void * (*MatvecCreate) ( void *A, void *x ); HYPRE_Int (*Matvec) ( void *matvec_data, HYPRE_Complex alpha, void *A, void *x, HYPRE_Complex beta, void *y ); HYPRE_Int (*MatvecDestroy) ( void *matvec_data ); HYPRE_Real (*InnerProd) ( void *x, void *y ); HYPRE_Int (*CopyVector) ( void *x, void *y ); HYPRE_Int (*ClearVector) ( void *x ); HYPRE_Int (*ScaleVector) ( HYPRE_Complex alpha, void *x ); HYPRE_Int (*Axpy) ( HYPRE_Complex alpha, void *x, void *y ); HYPRE_Int (*precond)(); HYPRE_Int (*precond_setup)(); } hypre_PCGFunctions; /** * The {\tt hypre\_PCGData} object ... **/ /* Summary of Parameters to Control Stopping Test: - Standard (default) error tolerance: |delta-residual|/|right-hand-side|<tol where the norm is an energy norm wrt preconditioner, |r|=sqrt(<Cr,r>). - two_norm!=0 means: the norm is the L2 norm, |r|=sqrt(<r,r>) - rel_change!=0 means: if pass the other stopping criteria, also check the relative change in the solution x. Pass iff this relative change is small. - tol = relative error tolerance, as above -a_tol = absolute convergence tolerance (default is 0.0) If one desires the convergence test to check the absolute convergence tolerance *only*, then set the relative convergence tolerance to 0.0. (The default convergence test is <C*r,r> <= max(relative_tolerance^2 * <C*b, b>, absolute_tolerance^2) - cf_tol = convergence factor tolerance; if >0 used for special test for slow convergence - stop_crit!=0 means (TO BE PHASED OUT): pure absolute error tolerance rather than a pure relative error tolerance on the residual. Never applies if rel_change!=0 or atolf!=0. - atolf = absolute error tolerance factor to be used _together_ with the relative error tolerance, |delta-residual| / ( atolf + |right-hand-side| ) < tol (To BE PHASED OUT) - recompute_residual means: when the iteration seems to be converged, recompute the residual from scratch (r=b-Ax) and use this new residual to repeat the convergence test. This can be expensive, use this only if you have seen a problem with the regular residual computation. - recompute_residual_p means: recompute the residual from scratch (r=b-Ax) every "recompute_residual_p" iterations. This can be expensive and degrade the convergence. Use it only if you have seen a problem with the regular residual computation. */ typedef struct { HYPRE_Real tol; HYPRE_Real atolf; HYPRE_Real cf_tol; HYPRE_Real a_tol; HYPRE_Real rtol; HYPRE_Int max_iter; HYPRE_Int two_norm; HYPRE_Int rel_change; HYPRE_Int recompute_residual; HYPRE_Int recompute_residual_p; HYPRE_Int stop_crit; HYPRE_Int converged; void *A; void *p; void *s; void *r; /* ...contains the residual. This is currently kept permanently. If that is ever changed, it still must be kept if logging>1 */ HYPRE_Int owns_matvec_data; /* normally 1; if 0, don't delete it */ void *matvec_data; void *precond_data; hypre_PCGFunctions * functions; /* log info (always logged) */ HYPRE_Int num_iterations; HYPRE_Real rel_residual_norm; HYPRE_Int print_level; /* printing when print_level>0 */ HYPRE_Int logging; /* extra computations for logging when logging>0 */ HYPRE_Real *norms; HYPRE_Real *rel_norms; } hypre_PCGData; #define hypre_PCGDataOwnsMatvecData(pcgdata) ((pcgdata) -> owns_matvec_data) #ifdef __cplusplus extern "C" { #endif /** * @name generic PCG Solver * * Description... **/ /*@{*/ /** * Description... * * @param param [IN] ... **/ hypre_PCGFunctions * hypre_PCGFunctionsCreate( char * (*CAlloc) ( size_t count, size_t elt_size ), HYPRE_Int (*Free) ( char *ptr ), HYPRE_Int (*CommInfo) ( void *A, HYPRE_Int *my_id, HYPRE_Int *num_procs ), void * (*CreateVector) ( void *vector ), HYPRE_Int (*DestroyVector) ( void *vector ), void * (*MatvecCreate) ( void *A, void *x ), HYPRE_Int (*Matvec) ( void *matvec_data, HYPRE_Complex alpha, void *A, void *x, HYPRE_Complex beta, void *y ), HYPRE_Int (*MatvecDestroy) ( void *matvec_data ), HYPRE_Real (*InnerProd) ( void *x, void *y ), HYPRE_Int (*CopyVector) ( void *x, void *y ), HYPRE_Int (*ClearVector) ( void *x ), HYPRE_Int (*ScaleVector) ( HYPRE_Complex alpha, void *x ), HYPRE_Int (*Axpy) ( HYPRE_Complex alpha, void *x, void *y ), HYPRE_Int (*PrecondSetup) ( void *vdata, void *A, void *b, void *x ), HYPRE_Int (*Precond) ( void *vdata, void *A, void *b, void *x ) ); /** * Description... * * @param param [IN] ... **/ void * hypre_PCGCreate( hypre_PCGFunctions *pcg_functions ); #ifdef __cplusplus } #endif #endif
7,406
34.440191
89
h
AMG
AMG-master/parcsr_ls/HYPRE_parcsr_ls.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef HYPRE_PARCSR_LS_HEADER #define HYPRE_PARCSR_LS_HEADER #include "HYPRE.h" #include "HYPRE_utilities.h" #include "HYPRE_seq_mv.h" #include "HYPRE_parcsr_mv.h" #include "HYPRE_IJ_mv.h" #ifdef __cplusplus extern "C" { #endif /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name ParCSR Solvers * * These solvers use matrix/vector storage schemes that are taylored * for general sparse matrix systems. * * @memo Linear solvers for sparse matrix systems **/ /*@{*/ /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name ParCSR Solvers **/ /*@{*/ struct hypre_Solver_struct; /** * The solver object. **/ #ifndef HYPRE_SOLVER_STRUCT #define HYPRE_SOLVER_STRUCT struct hypre_Solver_struct; typedef struct hypre_Solver_struct *HYPRE_Solver; #endif typedef HYPRE_Int (*HYPRE_PtrToParSolverFcn)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector); #ifndef HYPRE_MODIFYPC #define HYPRE_MODIFYPC typedef HYPRE_Int (*HYPRE_PtrToModifyPCFcn)(HYPRE_Solver, HYPRE_Int, HYPRE_Real); #endif /*@}*/ /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name ParCSR BoomerAMG Solver and Preconditioner * * Parallel unstructured algebraic multigrid solver and preconditioner **/ /*@{*/ /** * Create a solver object. **/ HYPRE_Int HYPRE_BoomerAMGCreate(HYPRE_Solver *solver); /** * Destroy a solver object. **/ HYPRE_Int HYPRE_BoomerAMGDestroy(HYPRE_Solver solver); /** * Set up the BoomerAMG solver or preconditioner. * If used as a preconditioner, this function should be passed * to the iterative solver {\tt SetPrecond} function. * * @param solver [IN] object to be set up. * @param A [IN] ParCSR matrix used to construct the solver/preconditioner. * @param b Ignored by this function. * @param x Ignored by this function. **/ HYPRE_Int HYPRE_BoomerAMGSetup(HYPRE_Solver solver, HYPRE_ParCSRMatrix A, HYPRE_ParVector b, HYPRE_ParVector x); /** * Solve the system or apply AMG as a preconditioner. * If used as a preconditioner, this function should be passed * to the iterative solver {\tt SetPrecond} function. * * @param solver [IN] solver or preconditioner object to be applied. * @param A [IN] ParCSR matrix, matrix of the linear system to be solved * @param b [IN] right hand side of the linear system to be solved * @param x [OUT] approximated solution of the linear system to be solved **/ HYPRE_Int HYPRE_BoomerAMGSolve(HYPRE_Solver solver, HYPRE_ParCSRMatrix A, HYPRE_ParVector b, HYPRE_ParVector x); /** * Solve the transpose system $A^T x = b$ or apply AMG as a preconditioner * to the transpose system . Note that this function should only be used * when preconditioning CGNR with BoomerAMG. It can only be used with * Jacobi smoothing (relax_type 0 or 7) and without CF smoothing, * i.e relax_order needs to be set to 0. * If used as a preconditioner, this function should be passed * to the iterative solver {\tt SetPrecond} function. * * @param solver [IN] solver or preconditioner object to be applied. * @param A [IN] ParCSR matrix * @param b [IN] right hand side of the linear system to be solved * @param x [OUT] approximated solution of the linear system to be solved **/ HYPRE_Int HYPRE_BoomerAMGSolveT(HYPRE_Solver solver, HYPRE_ParCSRMatrix A, HYPRE_ParVector b, HYPRE_ParVector x); /** * Recovers old default for coarsening and interpolation, i.e Falgout * coarsening and untruncated modified classical interpolation. * This option might be preferred for 2 dimensional problems. **/ HYPRE_Int HYPRE_BoomerAMGSetOldDefault(HYPRE_Solver solver); /** * Returns the residual. **/ HYPRE_Int HYPRE_BoomerAMGGetResidual(HYPRE_Solver solver, HYPRE_ParVector *residual); /** * Returns the number of iterations taken. **/ HYPRE_Int HYPRE_BoomerAMGGetNumIterations(HYPRE_Solver solver, HYPRE_Int *num_iterations); /** * Returns the norm of the final relative residual. **/ HYPRE_Int HYPRE_BoomerAMGGetFinalRelativeResidualNorm(HYPRE_Solver solver, HYPRE_Real *rel_resid_norm); /** * (Optional) Sets the size of the system of PDEs, if using the systems version. * The default is 1, i.e. a scalar system. **/ HYPRE_Int HYPRE_BoomerAMGSetNumFunctions(HYPRE_Solver solver, HYPRE_Int num_functions); /** * (Optional) Sets the mapping that assigns the function to each variable, * if using the systems version. If no assignment is made and the number of * functions is k > 1, the mapping generated is (0,1,...,k-1,0,1,...,k-1,...). **/ HYPRE_Int HYPRE_BoomerAMGSetDofFunc(HYPRE_Solver solver, HYPRE_Int *dof_func); /** * (Optional) Set the convergence tolerance, if BoomerAMG is used * as a solver. If it is used as a preconditioner, it should be set to 0. * The default is 1.e-7. **/ HYPRE_Int HYPRE_BoomerAMGSetTol(HYPRE_Solver solver, HYPRE_Real tol); /** * (Optional) Sets maximum number of iterations, if BoomerAMG is used * as a solver. If it is used as a preconditioner, it should be set to 1. * The default is 20. **/ HYPRE_Int HYPRE_BoomerAMGSetMaxIter(HYPRE_Solver solver, HYPRE_Int max_iter); /** * (Optional) **/ HYPRE_Int HYPRE_BoomerAMGSetMinIter(HYPRE_Solver solver, HYPRE_Int min_iter); /** * (Optional) Sets maximum size of coarsest grid. * The default is 9. **/ HYPRE_Int HYPRE_BoomerAMGSetMaxCoarseSize(HYPRE_Solver solver, HYPRE_Int max_coarse_size); /** * (Optional) Sets minimum size of coarsest grid. * The default is 1. **/ HYPRE_Int HYPRE_BoomerAMGSetMinCoarseSize(HYPRE_Solver solver, HYPRE_Int min_coarse_size); /** * (Optional) Sets maximum number of multigrid levels. * The default is 25. **/ HYPRE_Int HYPRE_BoomerAMGSetMaxLevels(HYPRE_Solver solver, HYPRE_Int max_levels); /** * (Optional) Sets AMG strength threshold. The default is 0.25. * For 2d Laplace operators, 0.25 is a good value, for 3d Laplace * operators, 0.5 or 0.6 is a better value. For elasticity problems, * a large strength threshold, such as 0.9, is often better. **/ HYPRE_Int HYPRE_BoomerAMGSetStrongThreshold(HYPRE_Solver solver, HYPRE_Real strong_threshold); /** * (Optional) Defines the largest strength threshold for which * the strength matrix S uses the communication package of the operator A. * If the strength threshold is larger than this values, * a communication package is generated for S. This can save * memory and decrease the amount of data that needs to be communicated, * if S is substantially sparser than A. * The default is 1.0. **/ HYPRE_Int HYPRE_BoomerAMGSetSCommPkgSwitch(HYPRE_Solver solver, HYPRE_Real S_commpkg_switch); /** * (Optional) Sets a parameter to modify the definition of strength for * diagonal dominant portions of the matrix. The default is 0.9. * If max\_row\_sum is 1, no checking for diagonally dominant rows is * performed. **/ HYPRE_Int HYPRE_BoomerAMGSetMaxRowSum(HYPRE_Solver solver, HYPRE_Real max_row_sum); /** * (Optional) Defines which parallel coarsening algorithm is used. * There are the following options for coarsen\_type: * * \begin{tabular}{|c|l|} \hline * 0 & CLJP-coarsening (a parallel coarsening algorithm using independent sets. \\ * 1 & classical Ruge-Stueben coarsening on each processor, no boundary treatment (not recommended!) \\ * 3 & classical Ruge-Stueben coarsening on each processor, followed by a third pass, which adds coarse \\ * & points on the boundaries \\ * 6 & Falgout coarsening (uses 1 first, followed by CLJP using the interior coarse points \\ * & generated by 1 as its first independent set) \\ * 7 & CLJP-coarsening (using a fixed random vector, for debugging purposes only) \\ * 8 & PMIS-coarsening (a parallel coarsening algorithm using independent sets, generating \\ * & lower complexities than CLJP, might also lead to slower convergence) \\ * 9 & PMIS-coarsening (using a fixed random vector, for debugging purposes only) \\ * 10 & HMIS-coarsening (uses one pass Ruge-Stueben on each processor independently, followed \\ * & by PMIS using the interior C-points generated as its first independent set) \\ * 11 & one-pass Ruge-Stueben coarsening on each processor, no boundary treatment (not recommended!) \\ * 21 & CGC coarsening by M. Griebel, B. Metsch and A. Schweitzer \\ * 22 & CGC-E coarsening by M. Griebel, B. Metsch and A.Schweitzer \\ * \hline * \end{tabular} * * The default is 6. **/ HYPRE_Int HYPRE_BoomerAMGSetCoarsenType(HYPRE_Solver solver, HYPRE_Int coarsen_type); /** * (Optional) Defines the non-Galerkin drop-tolerance * for sparsifying coarse grid operators and thus reducing communication. * Value specified here is set on all levels. * This routine should be used before HYPRE_BoomerAMGSetLevelNonGalerkinTol, which * then can be used to change individual levels if desired **/ HYPRE_Int HYPRE_BoomerAMGSetNonGalerkinTol (HYPRE_Solver solver, HYPRE_Real nongalerkin_tol); /** * (Optional) Defines the level specific non-Galerkin drop-tolerances * for sparsifying coarse grid operators and thus reducing communication. * A drop-tolerance of 0.0 means to skip doing non-Galerkin on that * level. The maximum drop tolerance for a level is 1.0, although * much smaller values such as 0.03 or 0.01 are recommended. * * Note that if the user wants to set a specific tolerance on all levels, * HYPRE_BooemrAMGSetNonGalerkinTol should be used. Individual levels * can then be changed using this routine. * * In general, it is safer to drop more aggressively on coarser levels. * For instance, one could use 0.0 on the finest level, 0.01 on the second level and * then using 0.05 on all remaining levels. The best way to achieve this is * to set 0.05 on all levels with HYPRE_BoomerAMGSetNonGalerkinTol and then * change the tolerance on level 0 to 0.0 and the tolerance on level 1 to 0.01 * with HYPRE_BoomerAMGSetLevelNonGalerkinTol. * Like many AMG parameters, these drop tolerances can be tuned. It is also common * to delay the start of the non-Galerkin process further to a later level than * level 1. * * @param solver [IN] solver or preconditioner object to be applied. * @param nongalerkin_tol [IN] level specific drop tolerance * @param level [IN] level on which drop tolerance is used **/ HYPRE_Int HYPRE_BoomerAMGSetLevelNonGalerkinTol (HYPRE_Solver solver, HYPRE_Real nongalerkin_tol, HYPRE_Int level); /* * (Optional) Defines the non-Galerkin drop-tolerance (old version) **/ HYPRE_Int HYPRE_BoomerAMGSetNonGalerkTol (HYPRE_Solver solver, HYPRE_Int nongalerk_num_tol, HYPRE_Real *nongalerk_tol); /** * (Optional) Defines whether local or global measures are used. **/ HYPRE_Int HYPRE_BoomerAMGSetMeasureType(HYPRE_Solver solver, HYPRE_Int measure_type); /** * (Optional) Defines the number of levels of aggressive coarsening. * The default is 0, i.e. no aggressive coarsening. **/ HYPRE_Int HYPRE_BoomerAMGSetAggNumLevels(HYPRE_Solver solver, HYPRE_Int agg_num_levels); /** * (Optional) Defines the degree of aggressive coarsening. * The default is 1. Larger numbers lead to less aggressive * coarsening. **/ HYPRE_Int HYPRE_BoomerAMGSetNumPaths(HYPRE_Solver solver, HYPRE_Int num_paths); /** * (optional) Defines the number of pathes for CGC-coarsening. **/ HYPRE_Int HYPRE_BoomerAMGSetCGCIts (HYPRE_Solver solver, HYPRE_Int its); /** * (Optional) Sets whether to use the nodal systems coarsening. * Should be used for linear systems generated from systems of PDEs. * The default is 0 (unknown-based coarsening, * only coarsens within same function). * For the remaining options a nodal matrix is generated by * applying a norm to the nodal blocks and applying the coarsening * algorithm to this matrix. * \begin{tabular}{|c|l|} \hline * 1 & Frobenius norm \\ * 2 & sum of absolute values of elements in each block \\ * 3 & largest element in each block (not absolute value)\\ * 4 & row-sum norm \\ * 6 & sum of all values in each block \\ * \hline * \end{tabular} **/ HYPRE_Int HYPRE_BoomerAMGSetNodal(HYPRE_Solver solver, HYPRE_Int nodal); /** * (Optional) Sets whether to give special treatment to diagonal elements in * the nodal systems version. * The default is 0. * If set to 1, the diagonal entry is set to the negative sum of all off * diagonal entries. * If set to 2, the signs of all diagonal entries are inverted. */ HYPRE_Int HYPRE_BoomerAMGSetNodalDiag(HYPRE_Solver solver, HYPRE_Int nodal_diag); /** * (Optional) Defines which parallel interpolation operator is used. * There are the following options for interp\_type: * * \begin{tabular}{|c|l|} \hline * 0 & classical modified interpolation \\ * 1 & LS interpolation (for use with GSMG) \\ * 2 & classical modified interpolation for hyperbolic PDEs \\ * 3 & direct interpolation (with separation of weights) \\ * 4 & multipass interpolation \\ * 5 & multipass interpolation (with separation of weights) \\ * 6 & extended+i interpolation \\ * 7 & extended+i (if no common C neighbor) interpolation \\ * 8 & standard interpolation \\ * 9 & standard interpolation (with separation of weights) \\ * 10 & classical block interpolation (for use with nodal systems version only) \\ * 11 & classical block interpolation (for use with nodal systems version only) \\ * & with diagonalized diagonal blocks \\ * 12 & FF interpolation \\ * 13 & FF1 interpolation \\ * 14 & extended interpolation \\ * \hline * \end{tabular} * * The default is 0. **/ HYPRE_Int HYPRE_BoomerAMGSetInterpType(HYPRE_Solver solver, HYPRE_Int interp_type); /** * (Optional) Defines a truncation factor for the interpolation. * The default is 0. **/ HYPRE_Int HYPRE_BoomerAMGSetTruncFactor(HYPRE_Solver solver, HYPRE_Real trunc_factor); /** * (Optional) Defines the maximal number of elements per row for the interpolation. * The default is 0. **/ HYPRE_Int HYPRE_BoomerAMGSetPMaxElmts(HYPRE_Solver solver, HYPRE_Int P_max_elmts); /** * (Optional) Defines whether separation of weights is used * when defining strength for standard interpolation or * multipass interpolation. * Default: 0, i.e. no separation of weights used. **/ HYPRE_Int HYPRE_BoomerAMGSetSepWeight(HYPRE_Solver solver, HYPRE_Int sep_weight); /** * (Optional) Defines the interpolation used on levels of aggressive coarsening * The default is 4, i.e. multipass interpolation. * The following options exist: * * \begin{tabular}{|c|l|} \hline * 1 & 2-stage extended+i interpolation \\ * 2 & 2-stage standard interpolation \\ * 3 & 2-stage extended interpolation \\ * 4 & multipass interpolation \\ * \hline * \end{tabular} **/ HYPRE_Int HYPRE_BoomerAMGSetAggInterpType(HYPRE_Solver solver, HYPRE_Int agg_interp_type); /** * (Optional) Defines the truncation factor for the * interpolation used for aggressive coarsening. * The default is 0. **/ HYPRE_Int HYPRE_BoomerAMGSetAggTruncFactor(HYPRE_Solver solver, HYPRE_Real agg_trunc_factor); /** * (Optional) Defines the truncation factor for the * matrices P1 and P2 which are used to build 2-stage interpolation. * The default is 0. **/ HYPRE_Int HYPRE_BoomerAMGSetAggP12TruncFactor(HYPRE_Solver solver, HYPRE_Real agg_P12_trunc_factor); /** * (Optional) Defines the maximal number of elements per row for the * interpolation used for aggressive coarsening. * The default is 0. **/ HYPRE_Int HYPRE_BoomerAMGSetAggPMaxElmts(HYPRE_Solver solver, HYPRE_Int agg_P_max_elmts); /** * (Optional) Defines the maximal number of elements per row for the * matrices P1 and P2 which are used to build 2-stage interpolation. * The default is 0. **/ HYPRE_Int HYPRE_BoomerAMGSetAggP12MaxElmts(HYPRE_Solver solver, HYPRE_Int agg_P12_max_elmts); /** * (Optional) Allows the user to incorporate additional vectors * into the interpolation for systems AMG, e.g. rigid body modes for * linear elasticity problems. * This can only be used in context with nodal coarsening and still * requires the user to choose an interpolation. **/ HYPRE_Int HYPRE_BoomerAMGSetInterpVectors (HYPRE_Solver solver , HYPRE_Int num_vectors , HYPRE_ParVector *interp_vectors ); /** * (Optional) Defines the interpolation variant used for * HYPRE_BoomerAMGSetInterpVectors: * \begin{tabular}{|c|l|} \hline * 1 & GM approach 1 \\ * 2 & GM approach 2 (to be preferred over 1) \\ * 3 & LN approach \\ * \hline * \end{tabular} **/ HYPRE_Int HYPRE_BoomerAMGSetInterpVecVariant (HYPRE_Solver solver, HYPRE_Int var ); /** * (Optional) Defines the maximal elements per row for Q, the additional * columns added to the original interpolation matrix P, to reduce complexity. * The default is no truncation. **/ HYPRE_Int HYPRE_BoomerAMGSetInterpVecQMax (HYPRE_Solver solver, HYPRE_Int q_max ); /** * (Optional) Defines a truncation factor for Q, the additional * columns added to the original interpolation matrix P, to reduce complexity. * The default is no truncation. **/ HYPRE_Int HYPRE_BoomerAMGSetInterpVecAbsQTrunc (HYPRE_Solver solver, HYPRE_Real q_trunc ); /** * (Optional) Specifies the use of GSMG - geometrically smooth * coarsening and interpolation. Currently any nonzero value for * gsmg will lead to the use of GSMG. * The default is 0, i.e. (GSMG is not used) **/ HYPRE_Int HYPRE_BoomerAMGSetGSMG(HYPRE_Solver solver, HYPRE_Int gsmg); /** * (Optional) Defines the number of sample vectors used in GSMG * or LS interpolation. **/ HYPRE_Int HYPRE_BoomerAMGSetNumSamples(HYPRE_Solver solver, HYPRE_Int num_samples); /** * (Optional) Defines the type of cycle. * For a V-cycle, set cycle\_type to 1, for a W-cycle * set cycle\_type to 2. The default is 1. **/ HYPRE_Int HYPRE_BoomerAMGSetCycleType(HYPRE_Solver solver, HYPRE_Int cycle_type); /** * (Optional) Defines use of an additive V(1,1)-cycle using the * classical additive method starting at level 'addlvl'. * The multiplicative approach is used on levels 0, ...'addlvl+1'. * 'addlvl' needs to be > -1 for this to have an effect. * Can only be used with weighted Jacobi and l1-Jacobi(default). * * Can only be used when AMG is used as a preconditioner !!! **/ HYPRE_Int HYPRE_BoomerAMGSetAdditive(HYPRE_Solver solver, HYPRE_Int addlvl); /** * (Optional) Defines use of an additive V(1,1)-cycle using the * mult-additive method starting at level 'addlvl'. * The multiplicative approach is used on levels 0, ...'addlvl+1'. * 'addlvl' needs to be > -1 for this to have an effect. * Can only be used with weighted Jacobi and l1-Jacobi(default). * * Can only be used when AMG is used as a preconditioner !!! **/ HYPRE_Int HYPRE_BoomerAMGSetMultAdditive(HYPRE_Solver solver, HYPRE_Int addlvl); /** * (Optional) Defines use of an additive V(1,1)-cycle using the * simplified mult-additive method starting at level 'addlvl'. * The multiplicative approach is used on levels 0, ...'addlvl+1'. * 'addlvl' needs to be > -1 for this to have an effect. * Can only be used with weighted Jacobi and l1-Jacobi(default). * * Can only be used when AMG is used as a preconditioner !!! **/ HYPRE_Int HYPRE_BoomerAMGSetSimple(HYPRE_Solver solver, HYPRE_Int addlvl); /** * (Optional) Defines last level where additive, mult-additive * or simple cycle is used. * The multiplicative approach is used on levels > add_last_lvl. * * Can only be used when AMG is used as a preconditioner !!! **/ HYPRE_Int HYPRE_BoomerAMGSetAddLastLvl(HYPRE_Solver solver, HYPRE_Int add_last_lvl); /** * (Optional) Defines the truncation factor for the * smoothed interpolation used for mult-additive or simple method. * The default is 0. **/ HYPRE_Int HYPRE_BoomerAMGSetMultAddTruncFactor(HYPRE_Solver solver, HYPRE_Real add_trunc_factor); /** * (Optional) Defines the maximal number of elements per row for the * smoothed interpolation used for mult-additive or simple method. * The default is 0. **/ HYPRE_Int HYPRE_BoomerAMGSetMultAddPMaxElmts(HYPRE_Solver solver, HYPRE_Int add_P_max_elmts); /** * (Optional) Defines the relaxation type used in the (mult)additive cycle * portion (also affects simple method.) * The default is 18 (L1-Jacobi). * Currently the only other option allowed is 0 (Jacobi) which should be **/ HYPRE_Int HYPRE_BoomerAMGSetAddRelaxType(HYPRE_Solver solver, HYPRE_Int add_rlx_type); /** * (Optional) Defines the relaxation weight used for Jacobi within the * (mult)additive or simple cycle portion. * The default is 1. * The weight only affects the Jacobi method, and has no effect on L1-Jacobi **/ HYPRE_Int HYPRE_BoomerAMGSetAddRelaxWt(HYPRE_Solver solver, HYPRE_Real add_rlx_wt); /** * (Optional) Sets maximal size for agglomeration or redundant coarse grid solve. * When the system is smaller than this threshold, sequential AMG is used * on process 0 or on all remaining active processes (if redundant = 1 ). **/ HYPRE_Int HYPRE_BoomerAMGSetSeqThreshold(HYPRE_Solver solver, HYPRE_Int seq_threshold); /** * (Optional) operates switch for redundancy. Needs to be used with * HYPRE_BoomerAMGSetSeqThreshold. Default is 0, i.e. no redundancy. **/ HYPRE_Int HYPRE_BoomerAMGSetRedundant(HYPRE_Solver solver, HYPRE_Int redundant); /* * (Optional) Defines the number of sweeps for the fine and coarse grid, * the up and down cycle. * * Note: This routine will be phased out!!!! * Use HYPRE\_BoomerAMGSetNumSweeps or HYPRE\_BoomerAMGSetCycleNumSweeps instead. **/ HYPRE_Int HYPRE_BoomerAMGSetNumGridSweeps(HYPRE_Solver solver, HYPRE_Int *num_grid_sweeps); /** * (Optional) Sets the number of sweeps. On the finest level, the up and * the down cycle the number of sweeps are set to num\_sweeps and on the * coarsest level to 1. The default is 1. **/ HYPRE_Int HYPRE_BoomerAMGSetNumSweeps(HYPRE_Solver solver, HYPRE_Int num_sweeps); /** * (Optional) Sets the number of sweeps at a specified cycle. * There are the following options for k: * * \begin{tabular}{|l|l|} \hline * the down cycle & if k=1 \\ * the up cycle & if k=2 \\ * the coarsest level & if k=3.\\ * \hline * \end{tabular} **/ HYPRE_Int HYPRE_BoomerAMGSetCycleNumSweeps(HYPRE_Solver solver, HYPRE_Int num_sweeps, HYPRE_Int k); /** * (Optional) Defines which smoother is used on the fine and coarse grid, * the up and down cycle. * * Note: This routine will be phased out!!!! * Use HYPRE\_BoomerAMGSetRelaxType or HYPRE\_BoomerAMGSetCycleRelaxType instead. **/ HYPRE_Int HYPRE_BoomerAMGSetGridRelaxType(HYPRE_Solver solver, HYPRE_Int *grid_relax_type); /** * (Optional) Defines the smoother to be used. It uses the given * smoother on the fine grid, the up and * the down cycle and sets the solver on the coarsest level to Gaussian * elimination (9). The default is Gauss-Seidel (3). * * There are the following options for relax\_type: * * \begin{tabular}{|c|l|} \hline * 0 & Jacobi \\ * 1 & Gauss-Seidel, sequential (very slow!) \\ * 2 & Gauss-Seidel, interior points in parallel, boundary sequential (slow!) \\ * 3 & hybrid Gauss-Seidel or SOR, forward solve \\ * 4 & hybrid Gauss-Seidel or SOR, backward solve \\ * 5 & hybrid chaotic Gauss-Seidel (works only with OpenMP) \\ * 6 & hybrid symmetric Gauss-Seidel or SSOR \\ * 8 & $\ell_1$-scaled hybrid symmetric Gauss-Seidel\\ * 9 & Gaussian elimination (only on coarsest level) \\ * 15 & CG (warning - not a fixed smoother - may require FGMRES)\\ * 16 & Chebyshev\\ * 17 & FCF-Jacobi\\ * 18 & $\ell_1$-scaled jacobi\\ * \hline * \end{tabular} **/ HYPRE_Int HYPRE_BoomerAMGSetRelaxType(HYPRE_Solver solver, HYPRE_Int relax_type); /** * (Optional) Defines the smoother at a given cycle. * For options of relax\_type see * description of HYPRE\_BoomerAMGSetRelaxType). Options for k are * * \begin{tabular}{|l|l|} \hline * the down cycle & if k=1 \\ * the up cycle & if k=2 \\ * the coarsest level & if k=3. \\ * \hline * \end{tabular} **/ HYPRE_Int HYPRE_BoomerAMGSetCycleRelaxType(HYPRE_Solver solver, HYPRE_Int relax_type, HYPRE_Int k); /** * (Optional) Defines in which order the points are relaxed. There are * the following options for * relax\_order: * * \begin{tabular}{|c|l|} \hline * 0 & the points are relaxed in natural or lexicographic * order on each processor \\ * 1 & CF-relaxation is used, i.e on the fine grid and the down * cycle the coarse points are relaxed first, \\ * & followed by the fine points; on the up cycle the F-points are relaxed * first, followed by the C-points. \\ * & On the coarsest level, if an iterative scheme is used, * the points are relaxed in lexicographic order. \\ * \hline * \end{tabular} * * The default is 1 (CF-relaxation). **/ HYPRE_Int HYPRE_BoomerAMGSetRelaxOrder(HYPRE_Solver solver, HYPRE_Int relax_order); /* * (Optional) Defines in which order the points are relaxed. * * Note: This routine will be phased out!!!! * Use HYPRE\_BoomerAMGSetRelaxOrder instead. **/ HYPRE_Int HYPRE_BoomerAMGSetGridRelaxPoints(HYPRE_Solver solver, HYPRE_Int **grid_relax_points); /* * (Optional) Defines the relaxation weight for smoothed Jacobi and hybrid SOR. * * Note: This routine will be phased out!!!! * Use HYPRE\_BoomerAMGSetRelaxWt or HYPRE\_BoomerAMGSetLevelRelaxWt instead. **/ HYPRE_Int HYPRE_BoomerAMGSetRelaxWeight(HYPRE_Solver solver, HYPRE_Real *relax_weight); /** * (Optional) Defines the relaxation weight for smoothed Jacobi and hybrid SOR * on all levels. * * \begin{tabular}{|l|l|} \hline * relax\_weight > 0 & this assigns the given relaxation weight on all levels \\ * relax\_weight = 0 & the weight is determined on each level * with the estimate $3 \over {4\|D^{-1/2}AD^{-1/2}\|}$,\\ * & where $D$ is the diagonal matrix of $A$ (this should only be used with Jacobi) \\ * relax\_weight = -k & the relaxation weight is determined with at most k CG steps * on each level \\ * & this should only be used for symmetric positive definite problems) \\ * \hline * \end{tabular} * * The default is 1. **/ HYPRE_Int HYPRE_BoomerAMGSetRelaxWt(HYPRE_Solver solver, HYPRE_Real relax_weight); /** * (Optional) Defines the relaxation weight for smoothed Jacobi and hybrid SOR * on the user defined level. Note that the finest level is denoted 0, the * next coarser level 1, etc. For nonpositive relax\_weight, the parameter is * determined on the given level as described for HYPRE\_BoomerAMGSetRelaxWt. * The default is 1. **/ HYPRE_Int HYPRE_BoomerAMGSetLevelRelaxWt(HYPRE_Solver solver, HYPRE_Real relax_weight, HYPRE_Int level); /** * (Optional) Defines the outer relaxation weight for hybrid SOR. * Note: This routine will be phased out!!!! * Use HYPRE\_BoomerAMGSetOuterWt or HYPRE\_BoomerAMGSetLevelOuterWt instead. **/ HYPRE_Int HYPRE_BoomerAMGSetOmega(HYPRE_Solver solver, HYPRE_Real *omega); /** * (Optional) Defines the outer relaxation weight for hybrid SOR and SSOR * on all levels. * * \begin{tabular}{|l|l|} \hline * omega > 0 & this assigns the same outer relaxation weight omega on each level\\ * omega = -k & an outer relaxation weight is determined with at most k CG * steps on each level \\ * & (this only makes sense for symmetric * positive definite problems and smoothers, e.g. SSOR) \\ * \hline * \end{tabular} * * The default is 1. **/ HYPRE_Int HYPRE_BoomerAMGSetOuterWt(HYPRE_Solver solver, HYPRE_Real omega); /** * (Optional) Defines the outer relaxation weight for hybrid SOR or SSOR * on the user defined level. Note that the finest level is denoted 0, the * next coarser level 1, etc. For nonpositive omega, the parameter is * determined on the given level as described for HYPRE\_BoomerAMGSetOuterWt. * The default is 1. **/ HYPRE_Int HYPRE_BoomerAMGSetLevelOuterWt(HYPRE_Solver solver, HYPRE_Real omega, HYPRE_Int level); /** * (Optional) Defines the Order for Chebyshev smoother. * The default is 2 (valid options are 1-4). **/ HYPRE_Int HYPRE_BoomerAMGSetChebyOrder(HYPRE_Solver solver, HYPRE_Int order); /** * (Optional) Fraction of the spectrum to use for the Chebyshev smoother. * The default is .3 (i.e., damp on upper 30% of the spectrum). **/ HYPRE_Int HYPRE_BoomerAMGSetChebyFraction (HYPRE_Solver solver, HYPRE_Real ratio); /* * (Optional) Defines whether matrix should be scaled. * The default is 1 (i.e., scaled). **/ HYPRE_Int HYPRE_BoomerAMGSetChebyScale (HYPRE_Solver solver, HYPRE_Int scale); /* * (Optional) Defines which polynomial variant should be used. * The default is 0 (i.e., scaled). **/ HYPRE_Int HYPRE_BoomerAMGSetChebyVariant (HYPRE_Solver solver, HYPRE_Int variant); /* * (Optional) Defines how to estimate eigenvalues. * The default is 10 (i.e., 10 CG iterations are used to find extreme * eigenvalues.) If eig_est=0, the largest eigenvalue is estimated * using Gershgorin, the smallest is set to 0. * If eig_est is a positive number n, n iterations of CG are used to * determine the smallest and largest eigenvalue. **/ HYPRE_Int HYPRE_BoomerAMGSetChebyEigEst (HYPRE_Solver solver, HYPRE_Int eig_est); /** * (Optional) Enables the use of more complex smoothers. * The following options exist for smooth\_type: * * \begin{tabular}{|c|l|l|} \hline * value & smoother & routines needed to set smoother parameters \\ * 6 & Schwarz smoothers & HYPRE\_BoomerAMGSetDomainType, HYPRE\_BoomerAMGSetOverlap, \\ * & & HYPRE\_BoomerAMGSetVariant, HYPRE\_BoomerAMGSetSchwarzRlxWeight \\ * 7 & Pilut & HYPRE\_BoomerAMGSetDropTol, HYPRE\_BoomerAMGSetMaxNzPerRow \\ * 8 & ParaSails & HYPRE\_BoomerAMGSetSym, HYPRE\_BoomerAMGSetLevel, \\ * & & HYPRE\_BoomerAMGSetFilter, HYPRE\_BoomerAMGSetThreshold \\ * 9 & Euclid & HYPRE\_BoomerAMGSetEuclidFile \\ * \hline * \end{tabular} * * The default is 6. Also, if no smoother parameters are set via the routines mentioned in the table above, * default values are used. **/ HYPRE_Int HYPRE_BoomerAMGSetSmoothType(HYPRE_Solver solver, HYPRE_Int smooth_type); /** * (Optional) Sets the number of levels for more complex smoothers. * The smoothers, * as defined by HYPRE\_BoomerAMGSetSmoothType, will be used * on level 0 (the finest level) through level smooth\_num\_levels-1. * The default is 0, i.e. no complex smoothers are used. **/ HYPRE_Int HYPRE_BoomerAMGSetSmoothNumLevels(HYPRE_Solver solver, HYPRE_Int smooth_num_levels); /** * (Optional) Sets the number of sweeps for more complex smoothers. * The default is 1. **/ HYPRE_Int HYPRE_BoomerAMGSetSmoothNumSweeps(HYPRE_Solver solver, HYPRE_Int smooth_num_sweeps); /** * (Optional) Defines which variant of the Schwarz method is used. * The following options exist for variant: * * \begin{tabular}{|c|l|} \hline * 0 & hybrid multiplicative Schwarz method (no overlap across processor * boundaries) \\ * 1 & hybrid additive Schwarz method (no overlap across processor * boundaries) \\ * 2 & additive Schwarz method \\ * 3 & hybrid multiplicative Schwarz method (with overlap across processor * boundaries) \\ * \hline * \end{tabular} * * The default is 0. **/ HYPRE_Int HYPRE_BoomerAMGSetVariant(HYPRE_Solver solver, HYPRE_Int variant); /** * (Optional) Defines the overlap for the Schwarz method. * The following options exist for overlap: * * \begin{tabular}{|c|l|} \hline * 0 & no overlap \\ * 1 & minimal overlap (default) \\ * 2 & overlap generated by including all neighbors of domain boundaries \\ * \hline * \end{tabular} **/ HYPRE_Int HYPRE_BoomerAMGSetOverlap(HYPRE_Solver solver, HYPRE_Int overlap); /** * (Optional) Defines the type of domain used for the Schwarz method. * The following options exist for domain\_type: * * \begin{tabular}{|c|l|} \hline * 0 & each point is a domain \\ * 1 & each node is a domain (only of interest in "systems" AMG) \\ * 2 & each domain is generated by agglomeration (default) \\ * \hline * \end{tabular} **/ HYPRE_Int HYPRE_BoomerAMGSetDomainType(HYPRE_Solver solver, HYPRE_Int domain_type); /** * (Optional) Defines a smoothing parameter for the additive Schwarz method. **/ HYPRE_Int HYPRE_BoomerAMGSetSchwarzRlxWeight(HYPRE_Solver solver, HYPRE_Real schwarz_rlx_weight); /** * (Optional) Indicates that the aggregates may not be SPD for the Schwarz method. * The following options exist for use\_nonsymm: * * \begin{tabular}{|c|l|} \hline * 0 & assume SPD (default) \\ * 1 & assume non-symmetric \\ * \hline * \end{tabular} **/ HYPRE_Int HYPRE_BoomerAMGSetSchwarzUseNonSymm(HYPRE_Solver solver, HYPRE_Int use_nonsymm); /** * (Optional) Defines symmetry for ParaSAILS. * For further explanation see description of ParaSAILS. **/ HYPRE_Int HYPRE_BoomerAMGSetSym(HYPRE_Solver solver, HYPRE_Int sym); /** * (Optional) Defines number of levels for ParaSAILS. * For further explanation see description of ParaSAILS. **/ HYPRE_Int HYPRE_BoomerAMGSetLevel(HYPRE_Solver solver, HYPRE_Int level); /** * (Optional) Defines threshold for ParaSAILS. * For further explanation see description of ParaSAILS. **/ HYPRE_Int HYPRE_BoomerAMGSetThreshold(HYPRE_Solver solver, HYPRE_Real threshold); /** * (Optional) Defines filter for ParaSAILS. * For further explanation see description of ParaSAILS. **/ HYPRE_Int HYPRE_BoomerAMGSetFilter(HYPRE_Solver solver, HYPRE_Real filter); /** * (Optional) Defines drop tolerance for PILUT. * For further explanation see description of PILUT. **/ HYPRE_Int HYPRE_BoomerAMGSetDropTol(HYPRE_Solver solver, HYPRE_Real drop_tol); /** * (Optional) Defines maximal number of nonzeros for PILUT. * For further explanation see description of PILUT. **/ HYPRE_Int HYPRE_BoomerAMGSetMaxNzPerRow(HYPRE_Solver solver, HYPRE_Int max_nz_per_row); /** * (Optional) Defines name of an input file for Euclid parameters. * For further explanation see description of Euclid. **/ HYPRE_Int HYPRE_BoomerAMGSetEuclidFile(HYPRE_Solver solver, char *euclidfile); /** * (Optional) Defines number of levels for ILU(k) in Euclid. * For further explanation see description of Euclid. **/ HYPRE_Int HYPRE_BoomerAMGSetEuLevel(HYPRE_Solver solver, HYPRE_Int eu_level); /** * (Optional) Defines filter for ILU(k) for Euclid. * For further explanation see description of Euclid. **/ HYPRE_Int HYPRE_BoomerAMGSetEuSparseA(HYPRE_Solver solver, HYPRE_Real eu_sparse_A); /** * (Optional) Defines use of block jacobi ILUT for Euclid. * For further explanation see description of Euclid. **/ HYPRE_Int HYPRE_BoomerAMGSetEuBJ(HYPRE_Solver solver, HYPRE_Int eu_bj); /* * (Optional) **/ HYPRE_Int HYPRE_BoomerAMGSetRestriction(HYPRE_Solver solver, HYPRE_Int restr_par); /* * (Optional) Name of file to which BoomerAMG will print; * cf HYPRE\_BoomerAMGSetPrintLevel. (Presently this is ignored). **/ HYPRE_Int HYPRE_BoomerAMGSetPrintFileName(HYPRE_Solver solver, const char *print_file_name); /** * (Optional) Requests automatic printing of setup and solve information. * * \begin{tabular}{|c|l|} \hline * 0 & no printout (default) \\ * 1 & print setup information \\ * 2 & print solve information \\ * 3 & print both setup and solve information \\ * \hline * \end{tabular} * * Note, that if one desires to print information and uses BoomerAMG as a * preconditioner, suggested print$\_$level is 1 to avoid excessive output, * and use print$\_$level of solver for solve phase information. **/ HYPRE_Int HYPRE_BoomerAMGSetPrintLevel(HYPRE_Solver solver, HYPRE_Int print_level); /** * (Optional) Requests additional computations for diagnostic and similar * data to be logged by the user. Default to 0 for do nothing. The latest * residual will be available if logging > 1. **/ HYPRE_Int HYPRE_BoomerAMGSetLogging(HYPRE_Solver solver, HYPRE_Int logging); /** * (Optional) **/ HYPRE_Int HYPRE_BoomerAMGSetDebugFlag(HYPRE_Solver solver, HYPRE_Int debug_flag); /** * (Optional) This routine will be eliminated in the future. **/ HYPRE_Int HYPRE_BoomerAMGInitGridRelaxation(HYPRE_Int **num_grid_sweeps_ptr, HYPRE_Int **grid_relax_type_ptr, HYPRE_Int ***grid_relax_points_ptr, HYPRE_Int coarsen_type, HYPRE_Real **relax_weights_ptr, HYPRE_Int max_levels); /** * (Optional) If rap2 not equal 0, the triple matrix product RAP is * replaced by two matrix products. **/ HYPRE_Int HYPRE_BoomerAMGSetRAP2(HYPRE_Solver solver, HYPRE_Int rap2); /** * (Optional) If set to 1, the local interpolation transposes will * be saved to use more efficient matvecs instead of matvecTs **/ HYPRE_Int HYPRE_BoomerAMGSetKeepTranspose(HYPRE_Solver solver, HYPRE_Int keepTranspose); /*@}*/ /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name ParCSR PCG Solver * * These routines should be used in conjunction with the generic interface in * \Ref{PCG Solver}. **/ /*@{*/ /** * Create a solver object. **/ HYPRE_Int HYPRE_ParCSRPCGCreate(MPI_Comm comm, HYPRE_Solver *solver); /** * Destroy a solver object. **/ HYPRE_Int HYPRE_ParCSRPCGDestroy(HYPRE_Solver solver); HYPRE_Int HYPRE_ParCSRPCGSetup(HYPRE_Solver solver, HYPRE_ParCSRMatrix A, HYPRE_ParVector b, HYPRE_ParVector x); HYPRE_Int HYPRE_ParCSRPCGSolve(HYPRE_Solver solver, HYPRE_ParCSRMatrix A, HYPRE_ParVector b, HYPRE_ParVector x); HYPRE_Int HYPRE_ParCSRPCGSetTol(HYPRE_Solver solver, HYPRE_Real tol); HYPRE_Int HYPRE_ParCSRPCGSetAbsoluteTol(HYPRE_Solver solver, HYPRE_Real tol); HYPRE_Int HYPRE_ParCSRPCGSetMaxIter(HYPRE_Solver solver, HYPRE_Int max_iter); /* * RE-VISIT **/ HYPRE_Int HYPRE_ParCSRPCGSetStopCrit(HYPRE_Solver solver, HYPRE_Int stop_crit); HYPRE_Int HYPRE_ParCSRPCGSetTwoNorm(HYPRE_Solver solver, HYPRE_Int two_norm); HYPRE_Int HYPRE_ParCSRPCGSetRelChange(HYPRE_Solver solver, HYPRE_Int rel_change); HYPRE_Int HYPRE_ParCSRPCGSetPrecond(HYPRE_Solver solver, HYPRE_PtrToParSolverFcn precond, HYPRE_PtrToParSolverFcn precond_setup, HYPRE_Solver precond_solver); HYPRE_Int HYPRE_ParCSRPCGGetPrecond(HYPRE_Solver solver, HYPRE_Solver *precond_data); HYPRE_Int HYPRE_ParCSRPCGSetLogging(HYPRE_Solver solver, HYPRE_Int logging); HYPRE_Int HYPRE_ParCSRPCGSetPrintLevel(HYPRE_Solver solver, HYPRE_Int print_level); HYPRE_Int HYPRE_ParCSRPCGGetNumIterations(HYPRE_Solver solver, HYPRE_Int *num_iterations); HYPRE_Int HYPRE_ParCSRPCGGetFinalRelativeResidualNorm(HYPRE_Solver solver, HYPRE_Real *norm); /** * Setup routine for diagonal preconditioning. **/ HYPRE_Int HYPRE_ParCSRDiagScaleSetup(HYPRE_Solver solver, HYPRE_ParCSRMatrix A, HYPRE_ParVector y, HYPRE_ParVector x); /** * Solve routine for diagonal preconditioning. **/ HYPRE_Int HYPRE_ParCSRDiagScale(HYPRE_Solver solver, HYPRE_ParCSRMatrix HA, HYPRE_ParVector Hy, HYPRE_ParVector Hx); /*@}*/ /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /** * @name ParCSR GMRES Solver * * These routines should be used in conjunction with the generic interface in * \Ref{GMRES Solver}. **/ /*@{*/ /** * Create a solver object. **/ HYPRE_Int HYPRE_ParCSRGMRESCreate(MPI_Comm comm, HYPRE_Solver *solver); /** * Destroy a solver object. **/ HYPRE_Int HYPRE_ParCSRGMRESDestroy(HYPRE_Solver solver); HYPRE_Int HYPRE_ParCSRGMRESSetup(HYPRE_Solver solver, HYPRE_ParCSRMatrix A, HYPRE_ParVector b, HYPRE_ParVector x); HYPRE_Int HYPRE_ParCSRGMRESSolve(HYPRE_Solver solver, HYPRE_ParCSRMatrix A, HYPRE_ParVector b, HYPRE_ParVector x); HYPRE_Int HYPRE_ParCSRGMRESSetKDim(HYPRE_Solver solver, HYPRE_Int k_dim); HYPRE_Int HYPRE_ParCSRGMRESSetTol(HYPRE_Solver solver, HYPRE_Real tol); HYPRE_Int HYPRE_ParCSRGMRESSetAbsoluteTol(HYPRE_Solver solver, HYPRE_Real a_tol); /* * RE-VISIT **/ HYPRE_Int HYPRE_ParCSRGMRESSetMinIter(HYPRE_Solver solver, HYPRE_Int min_iter); HYPRE_Int HYPRE_ParCSRGMRESSetMaxIter(HYPRE_Solver solver, HYPRE_Int max_iter); /* * Obsolete **/ HYPRE_Int HYPRE_ParCSRGMRESSetStopCrit(HYPRE_Solver solver, HYPRE_Int stop_crit); HYPRE_Int HYPRE_ParCSRGMRESSetPrecond(HYPRE_Solver solver, HYPRE_PtrToParSolverFcn precond, HYPRE_PtrToParSolverFcn precond_setup, HYPRE_Solver precond_solver); HYPRE_Int HYPRE_ParCSRGMRESGetPrecond(HYPRE_Solver solver, HYPRE_Solver *precond_data); HYPRE_Int HYPRE_ParCSRGMRESSetLogging(HYPRE_Solver solver, HYPRE_Int logging); HYPRE_Int HYPRE_ParCSRGMRESSetPrintLevel(HYPRE_Solver solver, HYPRE_Int print_level); HYPRE_Int HYPRE_ParCSRGMRESGetNumIterations(HYPRE_Solver solver, HYPRE_Int *num_iterations); HYPRE_Int HYPRE_ParCSRGMRESGetFinalRelativeResidualNorm(HYPRE_Solver solver, HYPRE_Real *norm); /*@}*/ /*-------------------------------------------------------------------------- * Miscellaneous: These probably do not belong in the interface. *--------------------------------------------------------------------------*/ HYPRE_ParCSRMatrix GenerateLaplacian(MPI_Comm comm, HYPRE_Int nx, HYPRE_Int ny, HYPRE_Int nz, HYPRE_Int P, HYPRE_Int Q, HYPRE_Int R, HYPRE_Int p, HYPRE_Int q, HYPRE_Int r, HYPRE_Real *value); HYPRE_ParCSRMatrix GenerateLaplacian27pt(MPI_Comm comm, HYPRE_Int nx, HYPRE_Int ny, HYPRE_Int nz, HYPRE_Int P, HYPRE_Int Q, HYPRE_Int R, HYPRE_Int p, HYPRE_Int q, HYPRE_Int r, HYPRE_Real *value); HYPRE_ParCSRMatrix GenerateLaplacian9pt(MPI_Comm comm, HYPRE_Int nx, HYPRE_Int ny, HYPRE_Int P, HYPRE_Int Q, HYPRE_Int p, HYPRE_Int q, HYPRE_Real *value); HYPRE_ParCSRMatrix GenerateDifConv(MPI_Comm comm, HYPRE_Int nx, HYPRE_Int ny, HYPRE_Int nz, HYPRE_Int P, HYPRE_Int Q, HYPRE_Int R, HYPRE_Int p, HYPRE_Int q, HYPRE_Int r, HYPRE_Real *value); HYPRE_ParCSRMatrix GenerateRotate7pt(MPI_Comm comm, HYPRE_Int nx, HYPRE_Int ny, HYPRE_Int P, HYPRE_Int Q, HYPRE_Int p, HYPRE_Int q, HYPRE_Real alpha, HYPRE_Real eps ); HYPRE_ParCSRMatrix GenerateVarDifConv(MPI_Comm comm, HYPRE_Int nx, HYPRE_Int ny, HYPRE_Int nz, HYPRE_Int P, HYPRE_Int Q, HYPRE_Int R, HYPRE_Int p, HYPRE_Int q, HYPRE_Int r, HYPRE_Real eps, HYPRE_ParVector *rhs_ptr); /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /* * (Optional) Switches on use of Jacobi interpolation after computing * an original interpolation **/ HYPRE_Int HYPRE_BoomerAMGSetPostInterpType(HYPRE_Solver solver, HYPRE_Int post_interp_type); /* * (Optional) Sets a truncation threshold for Jacobi interpolation. **/ HYPRE_Int HYPRE_BoomerAMGSetJacobiTruncThreshold(HYPRE_Solver solver, HYPRE_Real jacobi_trunc_threshold); /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ /*@}*/ #ifdef __cplusplus } #endif #endif
52,977
36.895565
107
h
AMG
AMG-master/parcsr_ls/_hypre_parcsr_ls.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #include "HYPRE_parcsr_ls.h" #ifndef hypre_PARCSR_LS_HEADER #define hypre_PARCSR_LS_HEADER #include "_hypre_utilities.h" #include "krylov.h" #include "seq_mv.h" #include "_hypre_parcsr_mv.h" #ifdef __cplusplus extern "C" { #endif typedef struct { HYPRE_Int prev; HYPRE_Int next; } Link; #ifndef hypre_ParAMG_DATA_HEADER #define hypre_ParAMG_DATA_HEADER #define CUMNUMIT /*-------------------------------------------------------------------------- * hypre_ParAMGData *--------------------------------------------------------------------------*/ typedef struct { /* setup params */ HYPRE_Int max_levels; HYPRE_Real strong_threshold; HYPRE_Real max_row_sum; HYPRE_Real trunc_factor; HYPRE_Real agg_trunc_factor; HYPRE_Real agg_P12_trunc_factor; HYPRE_Real jacobi_trunc_threshold; HYPRE_Real S_commpkg_switch; HYPRE_Int measure_type; HYPRE_Int setup_type; HYPRE_Int coarsen_type; HYPRE_Int P_max_elmts; HYPRE_Int interp_type; HYPRE_Int sep_weight; HYPRE_Int agg_interp_type; HYPRE_Int agg_P_max_elmts; HYPRE_Int agg_P12_max_elmts; HYPRE_Int restr_par; HYPRE_Int agg_num_levels; HYPRE_Int num_paths; HYPRE_Int post_interp_type; HYPRE_Int max_coarse_size; HYPRE_Int min_coarse_size; HYPRE_Int seq_threshold; HYPRE_Int redundant; HYPRE_Int participate; /* solve params */ HYPRE_Int max_iter; HYPRE_Int min_iter; HYPRE_Int cycle_type; HYPRE_Int *num_grid_sweeps; HYPRE_Int *grid_relax_type; HYPRE_Int **grid_relax_points; HYPRE_Int relax_order; HYPRE_Int user_coarse_relax_type; HYPRE_Int user_relax_type; HYPRE_Int user_num_sweeps; HYPRE_Real user_relax_weight; HYPRE_Real outer_wt; HYPRE_Real *relax_weight; HYPRE_Real *omega; HYPRE_Real tol; /* problem data */ hypre_ParCSRMatrix *A; HYPRE_Int num_variables; HYPRE_Int num_functions; HYPRE_Int nodal; HYPRE_Int nodal_levels; HYPRE_Int nodal_diag; HYPRE_Int num_points; HYPRE_Int *dof_func; HYPRE_Int *dof_point; HYPRE_Int *point_dof_map; /* data generated in the setup phase */ hypre_ParCSRMatrix **A_array; hypre_ParVector **F_array; hypre_ParVector **U_array; hypre_ParCSRMatrix **P_array; hypre_ParCSRMatrix **R_array; HYPRE_Int **CF_marker_array; HYPRE_Int **dof_func_array; HYPRE_Int **dof_point_array; HYPRE_Int **point_dof_map_array; HYPRE_Int num_levels; HYPRE_Real **l1_norms; HYPRE_Int block_mode; /* data for more complex smoothers */ HYPRE_Real *max_eig_est; HYPRE_Real *min_eig_est; HYPRE_Int cheby_eig_est; HYPRE_Int cheby_order; HYPRE_Int cheby_variant; HYPRE_Int cheby_scale; HYPRE_Real cheby_fraction; HYPRE_Real **cheby_ds; HYPRE_Real **cheby_coefs; /* data needed for non-Galerkin option */ HYPRE_Int nongalerk_num_tol; HYPRE_Real *nongalerk_tol; HYPRE_Real nongalerkin_tol; HYPRE_Real *nongal_tol_array; /* data generated in the solve phase */ hypre_ParVector *Vtemp; hypre_Vector *Vtemp_local; HYPRE_Real *Vtemp_local_data; HYPRE_Real cycle_op_count; hypre_ParVector *Rtemp; hypre_ParVector *Ptemp; hypre_ParVector *Ztemp; /* log info */ HYPRE_Int logging; HYPRE_Int num_iterations; #ifdef CUMNUMIT HYPRE_Int cum_num_iterations; #endif HYPRE_Real rel_resid_norm; hypre_ParVector *residual; /* available if logging>1 */ /* output params */ HYPRE_Int print_level; char log_file_name[256]; HYPRE_Int debug_flag; HYPRE_Real cum_nnz_AP; /* enable redundant coarse grid solve */ HYPRE_Solver coarse_solver; hypre_ParCSRMatrix *A_coarse; hypre_ParVector *f_coarse; hypre_ParVector *u_coarse; MPI_Comm new_comm; /* store matrix, vector and communication info for Gaussian elimination */ HYPRE_Real *A_mat; HYPRE_Real *b_vec; HYPRE_Int *comm_info; /* information for multiplication with Lambda - additive AMG */ HYPRE_Int additive; HYPRE_Int mult_additive; HYPRE_Int simple; HYPRE_Int add_last_lvl; HYPRE_Int add_P_max_elmts; HYPRE_Real add_trunc_factor; HYPRE_Int add_rlx_type; HYPRE_Real add_rlx_wt; hypre_ParCSRMatrix *Lambda; hypre_ParCSRMatrix *Atilde; hypre_ParVector *Rtilde; hypre_ParVector *Xtilde; HYPRE_Real *D_inv; HYPRE_Int rap2; HYPRE_Int keepTranspose; } hypre_ParAMGData; /*-------------------------------------------------------------------------- * Accessor functions for the hypre_AMGData structure *--------------------------------------------------------------------------*/ /* setup params */ #define hypre_ParAMGDataRestriction(amg_data) ((amg_data)->restr_par) #define hypre_ParAMGDataMaxLevels(amg_data) ((amg_data)->max_levels) #define hypre_ParAMGDataStrongThreshold(amg_data) \ ((amg_data)->strong_threshold) #define hypre_ParAMGDataMaxRowSum(amg_data) ((amg_data)->max_row_sum) #define hypre_ParAMGDataTruncFactor(amg_data) ((amg_data)->trunc_factor) #define hypre_ParAMGDataAggTruncFactor(amg_data) ((amg_data)->agg_trunc_factor) #define hypre_ParAMGDataAggP12TruncFactor(amg_data) ((amg_data)->agg_P12_trunc_factor) #define hypre_ParAMGDataJacobiTruncThreshold(amg_data) ((amg_data)->jacobi_trunc_threshold) #define hypre_ParAMGDataSCommPkgSwitch(amg_data) ((amg_data)->S_commpkg_switch) #define hypre_ParAMGDataInterpType(amg_data) ((amg_data)->interp_type) #define hypre_ParAMGDataSepWeight(amg_data) ((amg_data)->sep_weight) #define hypre_ParAMGDataAggInterpType(amg_data) ((amg_data)->agg_interp_type) #define hypre_ParAMGDataCoarsenType(amg_data) ((amg_data)->coarsen_type) #define hypre_ParAMGDataMeasureType(amg_data) ((amg_data)->measure_type) #define hypre_ParAMGDataSetupType(amg_data) ((amg_data)->setup_type) #define hypre_ParAMGDataPMaxElmts(amg_data) ((amg_data)->P_max_elmts) #define hypre_ParAMGDataAggPMaxElmts(amg_data) ((amg_data)->agg_P_max_elmts) #define hypre_ParAMGDataAggP12MaxElmts(amg_data) ((amg_data)->agg_P12_max_elmts) #define hypre_ParAMGDataNumPaths(amg_data) ((amg_data)->num_paths) #define hypre_ParAMGDataAggNumLevels(amg_data) ((amg_data)->agg_num_levels) #define hypre_ParAMGDataPostInterpType(amg_data) ((amg_data)->post_interp_type) #define hypre_ParAMGDataL1Norms(amg_data) ((amg_data)->l1_norms) #define hypre_ParAMGDataMaxCoarseSize(amg_data) ((amg_data)->max_coarse_size) #define hypre_ParAMGDataMinCoarseSize(amg_data) ((amg_data)->min_coarse_size) #define hypre_ParAMGDataSeqThreshold(amg_data) ((amg_data)->seq_threshold) /* solve params */ #define hypre_ParAMGDataMinIter(amg_data) ((amg_data)->min_iter) #define hypre_ParAMGDataMaxIter(amg_data) ((amg_data)->max_iter) #define hypre_ParAMGDataCycleType(amg_data) ((amg_data)->cycle_type) #define hypre_ParAMGDataTol(amg_data) ((amg_data)->tol) #define hypre_ParAMGDataNumGridSweeps(amg_data) ((amg_data)->num_grid_sweeps) #define hypre_ParAMGDataUserCoarseRelaxType(amg_data) ((amg_data)->user_coarse_relax_type) #define hypre_ParAMGDataUserRelaxType(amg_data) ((amg_data)->user_relax_type) #define hypre_ParAMGDataUserRelaxWeight(amg_data) ((amg_data)->user_relax_weight) #define hypre_ParAMGDataUserNumSweeps(amg_data) ((amg_data)->user_num_sweeps) #define hypre_ParAMGDataGridRelaxType(amg_data) ((amg_data)->grid_relax_type) #define hypre_ParAMGDataGridRelaxPoints(amg_data) \ ((amg_data)->grid_relax_points) #define hypre_ParAMGDataRelaxOrder(amg_data) ((amg_data)->relax_order) #define hypre_ParAMGDataRelaxWeight(amg_data) ((amg_data)->relax_weight) #define hypre_ParAMGDataOmega(amg_data) ((amg_data)->omega) #define hypre_ParAMGDataOuterWt(amg_data) ((amg_data)->outer_wt) /* problem data parameters */ #define hypre_ParAMGDataNumVariables(amg_data) ((amg_data)->num_variables) #define hypre_ParAMGDataNumFunctions(amg_data) ((amg_data)->num_functions) #define hypre_ParAMGDataNodal(amg_data) ((amg_data)->nodal) #define hypre_ParAMGDataNodalLevels(amg_data) ((amg_data)->nodal_levels) #define hypre_ParAMGDataNodalDiag(amg_data) ((amg_data)->nodal_diag) #define hypre_ParAMGDataNumPoints(amg_data) ((amg_data)->num_points) #define hypre_ParAMGDataDofFunc(amg_data) ((amg_data)->dof_func) #define hypre_ParAMGDataDofPoint(amg_data) ((amg_data)->dof_point) #define hypre_ParAMGDataPointDofMap(amg_data) ((amg_data)->point_dof_map) /* data generated by the setup phase */ #define hypre_ParAMGDataCFMarkerArray(amg_data) ((amg_data)-> CF_marker_array) #define hypre_ParAMGDataAArray(amg_data) ((amg_data)->A_array) #define hypre_ParAMGDataFArray(amg_data) ((amg_data)->F_array) #define hypre_ParAMGDataUArray(amg_data) ((amg_data)->U_array) #define hypre_ParAMGDataPArray(amg_data) ((amg_data)->P_array) #define hypre_ParAMGDataRArray(amg_data) ((amg_data)->R_array) #define hypre_ParAMGDataDofFuncArray(amg_data) ((amg_data)->dof_func_array) #define hypre_ParAMGDataDofPointArray(amg_data) ((amg_data)->dof_point_array) #define hypre_ParAMGDataPointDofMapArray(amg_data) \ ((amg_data)->point_dof_map_array) #define hypre_ParAMGDataNumLevels(amg_data) ((amg_data)->num_levels) #define hypre_ParAMGDataMaxEigEst(amg_data) ((amg_data)->max_eig_est) #define hypre_ParAMGDataMinEigEst(amg_data) ((amg_data)->min_eig_est) #define hypre_ParAMGDataChebyOrder(amg_data) ((amg_data)->cheby_order) #define hypre_ParAMGDataChebyFraction(amg_data) ((amg_data)->cheby_fraction) #define hypre_ParAMGDataChebyEigEst(amg_data) ((amg_data)->cheby_eig_est) #define hypre_ParAMGDataChebyVariant(amg_data) ((amg_data)->cheby_variant) #define hypre_ParAMGDataChebyScale(amg_data) ((amg_data)->cheby_scale) #define hypre_ParAMGDataChebyDS(amg_data) ((amg_data)->cheby_ds) #define hypre_ParAMGDataChebyCoefs(amg_data) ((amg_data)->cheby_coefs) #define hypre_ParAMGDataBlockMode(amg_data) ((amg_data)->block_mode) /* data generated in the solve phase */ #define hypre_ParAMGDataVtemp(amg_data) ((amg_data)->Vtemp) #define hypre_ParAMGDataVtempLocal(amg_data) ((amg_data)->Vtemp_local) #define hypre_ParAMGDataVtemplocalData(amg_data) ((amg_data)->Vtemp_local_data) #define hypre_ParAMGDataCycleOpCount(amg_data) ((amg_data)->cycle_op_count) #define hypre_ParAMGDataRtemp(amg_data) ((amg_data)->Rtemp) #define hypre_ParAMGDataPtemp(amg_data) ((amg_data)->Ptemp) #define hypre_ParAMGDataZtemp(amg_data) ((amg_data)->Ztemp) /* log info data */ #define hypre_ParAMGDataLogging(amg_data) ((amg_data)->logging) #define hypre_ParAMGDataNumIterations(amg_data) ((amg_data)->num_iterations) #ifdef CUMNUMIT #define hypre_ParAMGDataCumNumIterations(amg_data) ((amg_data)->cum_num_iterations) #endif #define hypre_ParAMGDataRelativeResidualNorm(amg_data) ((amg_data)->rel_resid_norm) #define hypre_ParAMGDataResidual(amg_data) ((amg_data)->residual) /* output parameters */ #define hypre_ParAMGDataPrintLevel(amg_data) ((amg_data)->print_level) #define hypre_ParAMGDataLogFileName(amg_data) ((amg_data)->log_file_name) #define hypre_ParAMGDataDebugFlag(amg_data) ((amg_data)->debug_flag) #define hypre_ParAMGDataCumNnzAP(amg_data) ((amg_data)->cum_nnz_AP) #define hypre_ParAMGDataCoarseSolver(amg_data) ((amg_data)->coarse_solver) #define hypre_ParAMGDataACoarse(amg_data) ((amg_data)->A_coarse) #define hypre_ParAMGDataFCoarse(amg_data) ((amg_data)->f_coarse) #define hypre_ParAMGDataUCoarse(amg_data) ((amg_data)->u_coarse) #define hypre_ParAMGDataNewComm(amg_data) ((amg_data)->new_comm) #define hypre_ParAMGDataRedundant(amg_data) ((amg_data)->redundant) #define hypre_ParAMGDataParticipate(amg_data) ((amg_data)->participate) #define hypre_ParAMGDataAMat(amg_data) ((amg_data)->A_mat) #define hypre_ParAMGDataBVec(amg_data) ((amg_data)->b_vec) #define hypre_ParAMGDataCommInfo(amg_data) ((amg_data)->comm_info) /* additive AMG parameters */ #define hypre_ParAMGDataAdditive(amg_data) ((amg_data)->additive) #define hypre_ParAMGDataMultAdditive(amg_data) ((amg_data)->mult_additive) #define hypre_ParAMGDataSimple(amg_data) ((amg_data)->simple) #define hypre_ParAMGDataAddLastLvl(amg_data) ((amg_data)->add_last_lvl) #define hypre_ParAMGDataMultAddPMaxElmts(amg_data) ((amg_data)->add_P_max_elmts) #define hypre_ParAMGDataMultAddTruncFactor(amg_data) ((amg_data)->add_trunc_factor) #define hypre_ParAMGDataAddRelaxType(amg_data) ((amg_data)->add_rlx_type) #define hypre_ParAMGDataAddRelaxWt(amg_data) ((amg_data)->add_rlx_wt) #define hypre_ParAMGDataLambda(amg_data) ((amg_data)->Lambda) #define hypre_ParAMGDataAtilde(amg_data) ((amg_data)->Atilde) #define hypre_ParAMGDataRtilde(amg_data) ((amg_data)->Rtilde) #define hypre_ParAMGDataXtilde(amg_data) ((amg_data)->Xtilde) #define hypre_ParAMGDataDinv(amg_data) ((amg_data)->D_inv) /* non-Galerkin parameters */ #define hypre_ParAMGDataNonGalerkNumTol(amg_data) ((amg_data)->nongalerk_num_tol) #define hypre_ParAMGDataNonGalerkTol(amg_data) ((amg_data)->nongalerk_tol) #define hypre_ParAMGDataNonGalerkinTol(amg_data) ((amg_data)->nongalerkin_tol) #define hypre_ParAMGDataNonGalTolArray(amg_data) ((amg_data)->nongal_tol_array) #define hypre_ParAMGDataRAP2(amg_data) ((amg_data)->rap2) #define hypre_ParAMGDataKeepTranspose(amg_data) ((amg_data)->keepTranspose) #endif /* ams.c */ HYPRE_Int hypre_ParCSRRelax ( hypre_ParCSRMatrix *A , hypre_ParVector *f , HYPRE_Int relax_type , HYPRE_Int relax_times , HYPRE_Real *l1_norms , HYPRE_Real relax_weight , HYPRE_Real omega , HYPRE_Real max_eig_est , HYPRE_Real min_eig_est , HYPRE_Int cheby_order , HYPRE_Real cheby_fraction , hypre_ParVector *u , hypre_ParVector *v , hypre_ParVector *z ); hypre_ParVector *hypre_ParVectorInRangeOf ( hypre_ParCSRMatrix *A ); hypre_ParVector *hypre_ParVectorInDomainOf ( hypre_ParCSRMatrix *A ); HYPRE_Int hypre_ParVectorBlockSplit ( hypre_ParVector *x , hypre_ParVector *x_ [3 ], HYPRE_Int dim ); HYPRE_Int hypre_ParVectorBlockGather ( hypre_ParVector *x , hypre_ParVector *x_ [3 ], HYPRE_Int dim ); HYPRE_Int hypre_BoomerAMGBlockSolve ( void *B , hypre_ParCSRMatrix *A , hypre_ParVector *b , hypre_ParVector *x ); HYPRE_Int hypre_ParCSRMatrixFixZeroRows ( hypre_ParCSRMatrix *A ); HYPRE_Int hypre_ParCSRComputeL1Norms ( hypre_ParCSRMatrix *A , HYPRE_Int option , HYPRE_Int *cf_marker , HYPRE_Real **l1_norm_ptr ); HYPRE_Int hypre_ParCSRMatrixSetDiagRows ( hypre_ParCSRMatrix *A , HYPRE_Real d ); void *hypre_AMSCreate ( void ); HYPRE_Int hypre_AMSDestroy ( void *solver ); HYPRE_Int hypre_AMSSetDimension ( void *solver , HYPRE_Int dim ); HYPRE_Int hypre_AMSSetDiscreteGradient ( void *solver , hypre_ParCSRMatrix *G ); HYPRE_Int hypre_AMSSetCoordinateVectors ( void *solver , hypre_ParVector *x , hypre_ParVector *y , hypre_ParVector *z ); HYPRE_Int hypre_AMSSetEdgeConstantVectors ( void *solver , hypre_ParVector *Gx , hypre_ParVector *Gy , hypre_ParVector *Gz ); HYPRE_Int hypre_AMSSetInterpolations ( void *solver , hypre_ParCSRMatrix *Pi , hypre_ParCSRMatrix *Pix , hypre_ParCSRMatrix *Piy , hypre_ParCSRMatrix *Piz ); HYPRE_Int hypre_AMSSetAlphaPoissonMatrix ( void *solver , hypre_ParCSRMatrix *A_Pi ); HYPRE_Int hypre_AMSSetBetaPoissonMatrix ( void *solver , hypre_ParCSRMatrix *A_G ); HYPRE_Int hypre_AMSSetInteriorNodes ( void *solver , hypre_ParVector *interior_nodes ); HYPRE_Int hypre_AMSSetProjectionFrequency ( void *solver , HYPRE_Int projection_frequency ); HYPRE_Int hypre_AMSSetMaxIter ( void *solver , HYPRE_Int maxit ); HYPRE_Int hypre_AMSSetTol ( void *solver , HYPRE_Real tol ); HYPRE_Int hypre_AMSSetCycleType ( void *solver , HYPRE_Int cycle_type ); HYPRE_Int hypre_AMSSetPrintLevel ( void *solver , HYPRE_Int print_level ); HYPRE_Int hypre_AMSSetSmoothingOptions ( void *solver , HYPRE_Int A_relax_type , HYPRE_Int A_relax_times , HYPRE_Real A_relax_weight , HYPRE_Real A_omega ); HYPRE_Int hypre_AMSSetChebySmoothingOptions ( void *solver , HYPRE_Int A_cheby_order , HYPRE_Int A_cheby_fraction ); HYPRE_Int hypre_AMSSetAlphaAMGOptions ( void *solver , HYPRE_Int B_Pi_coarsen_type , HYPRE_Int B_Pi_agg_levels , HYPRE_Int B_Pi_relax_type , HYPRE_Real B_Pi_theta , HYPRE_Int B_Pi_interp_type , HYPRE_Int B_Pi_Pmax ); HYPRE_Int hypre_AMSSetAlphaAMGCoarseRelaxType ( void *solver , HYPRE_Int B_Pi_coarse_relax_type ); HYPRE_Int hypre_AMSSetBetaAMGOptions ( void *solver , HYPRE_Int B_G_coarsen_type , HYPRE_Int B_G_agg_levels , HYPRE_Int B_G_relax_type , HYPRE_Real B_G_theta , HYPRE_Int B_G_interp_type , HYPRE_Int B_G_Pmax ); HYPRE_Int hypre_AMSSetBetaAMGCoarseRelaxType ( void *solver , HYPRE_Int B_G_coarse_relax_type ); HYPRE_Int hypre_AMSComputePi ( hypre_ParCSRMatrix *A , hypre_ParCSRMatrix *G , hypre_ParVector *Gx , hypre_ParVector *Gy , hypre_ParVector *Gz , HYPRE_Int dim , hypre_ParCSRMatrix **Pi_ptr ); HYPRE_Int hypre_AMSComputePixyz ( hypre_ParCSRMatrix *A , hypre_ParCSRMatrix *G , hypre_ParVector *Gx , hypre_ParVector *Gy , hypre_ParVector *Gz , HYPRE_Int dim , hypre_ParCSRMatrix **Pix_ptr , hypre_ParCSRMatrix **Piy_ptr , hypre_ParCSRMatrix **Piz_ptr ); HYPRE_Int hypre_AMSComputeGPi ( hypre_ParCSRMatrix *A , hypre_ParCSRMatrix *G , hypre_ParVector *Gx , hypre_ParVector *Gy , hypre_ParVector *Gz , HYPRE_Int dim , hypre_ParCSRMatrix **GPi_ptr ); HYPRE_Int hypre_AMSSetup ( void *solver , hypre_ParCSRMatrix *A , hypre_ParVector *b , hypre_ParVector *x ); HYPRE_Int hypre_AMSSolve ( void *solver , hypre_ParCSRMatrix *A , hypre_ParVector *b , hypre_ParVector *x ); HYPRE_Int hypre_ParCSRSubspacePrec ( hypre_ParCSRMatrix *A0 , HYPRE_Int A0_relax_type , HYPRE_Int A0_relax_times , HYPRE_Real *A0_l1_norms , HYPRE_Real A0_relax_weight , HYPRE_Real A0_omega , HYPRE_Real A0_max_eig_est , HYPRE_Real A0_min_eig_est , HYPRE_Int A0_cheby_order , HYPRE_Real A0_cheby_fraction , hypre_ParCSRMatrix **A , HYPRE_Solver *B , HYPRE_PtrToSolverFcn *HB , hypre_ParCSRMatrix **P , hypre_ParVector **r , hypre_ParVector **g , hypre_ParVector *x , hypre_ParVector *y , hypre_ParVector *r0 , hypre_ParVector *g0 , char *cycle , hypre_ParVector *z ); HYPRE_Int hypre_AMSGetNumIterations ( void *solver , HYPRE_Int *num_iterations ); HYPRE_Int hypre_AMSGetFinalRelativeResidualNorm ( void *solver , HYPRE_Real *rel_resid_norm ); HYPRE_Int hypre_AMSProjectOutGradients ( void *solver , hypre_ParVector *x ); HYPRE_Int hypre_AMSConstructDiscreteGradient ( hypre_ParCSRMatrix *A , hypre_ParVector *x_coord , HYPRE_Int *edge_vertex , HYPRE_Int edge_orientation , hypre_ParCSRMatrix **G_ptr ); HYPRE_Int hypre_AMSFEISetup ( void *solver , hypre_ParCSRMatrix *A , hypre_ParVector *b , hypre_ParVector *x , HYPRE_Int num_vert , HYPRE_Int num_local_vert , HYPRE_Int *vert_number , HYPRE_Real *vert_coord , HYPRE_Int num_edges , HYPRE_Int *edge_vertex ); HYPRE_Int hypre_AMSFEIDestroy ( void *solver ); HYPRE_Int hypre_ParCSRComputeL1NormsThreads ( hypre_ParCSRMatrix *A , HYPRE_Int option , HYPRE_Int num_threads , HYPRE_Int *cf_marker , HYPRE_Real **l1_norm_ptr ); HYPRE_Int hypre_ParCSRRelaxThreads ( hypre_ParCSRMatrix *A , hypre_ParVector *f , HYPRE_Int relax_type , HYPRE_Int relax_times , HYPRE_Real *l1_norms , HYPRE_Real relax_weight , HYPRE_Real omega , hypre_ParVector *u , hypre_ParVector *Vtemp , hypre_ParVector *z ); /* aux_interp.c */ HYPRE_Int hypre_alt_insert_new_nodes ( hypre_ParCSRCommPkg *comm_pkg , hypre_ParCSRCommPkg *extend_comm_pkg , HYPRE_Int *IN_marker , HYPRE_Int full_off_procNodes , HYPRE_Int *OUT_marker ); HYPRE_Int hypre_ParCSRFindExtendCommPkg ( hypre_ParCSRMatrix *A , HYPRE_Int newoff , HYPRE_Int *found , hypre_ParCSRCommPkg **extend_comm_pkg ); HYPRE_Int hypre_ssort ( HYPRE_Int *data , HYPRE_Int n ); HYPRE_Int hypre_index_of_minimum ( HYPRE_Int *data , HYPRE_Int n ); void hypre_swap_int ( HYPRE_Int *data , HYPRE_Int a , HYPRE_Int b ); void hypre_initialize_vecs ( HYPRE_Int diag_n , HYPRE_Int offd_n , HYPRE_Int *diag_ftc , HYPRE_Int *offd_ftc , HYPRE_Int *diag_pm , HYPRE_Int *offd_pm , HYPRE_Int *tmp_CF ); /*HYPRE_Int hypre_new_offd_nodes(HYPRE_Int **found , HYPRE_Int num_cols_A_offd , HYPRE_Int *A_ext_i , HYPRE_Int *A_ext_j, HYPRE_Int num_cols_S_offd, HYPRE_Int *col_map_offd, HYPRE_Int col_1, HYPRE_Int col_n, HYPRE_Int *Sop_i, HYPRE_Int *Sop_j, HYPRE_Int *CF_marker_offd );*/ HYPRE_Int hypre_exchange_marker(hypre_ParCSRCommPkg *comm_pkg, HYPRE_Int *IN_marker, HYPRE_Int *OUT_marker); HYPRE_Int hypre_exchange_interp_data( HYPRE_Int **CF_marker_offd, HYPRE_Int **dof_func_offd, hypre_CSRMatrix **A_ext, HYPRE_Int *full_off_procNodes, hypre_CSRMatrix **Sop, hypre_ParCSRCommPkg **extend_comm_pkg, hypre_ParCSRMatrix *A, HYPRE_Int *CF_marker, hypre_ParCSRMatrix *S, HYPRE_Int num_functions, HYPRE_Int *dof_func, HYPRE_Int skip_fine_or_same_sign); void hypre_build_interp_colmap(hypre_ParCSRMatrix *P, HYPRE_Int full_off_procNodes, HYPRE_Int *tmp_CF_marker_offd, HYPRE_Int *fine_to_coarse_offd); /* gen_redcs_mat.c */ HYPRE_Int hypre_seqAMGSetup ( hypre_ParAMGData *amg_data , HYPRE_Int p_level , HYPRE_Int coarse_threshold ); HYPRE_Int hypre_seqAMGCycle ( hypre_ParAMGData *amg_data , HYPRE_Int p_level , hypre_ParVector **Par_F_array , hypre_ParVector **Par_U_array ); HYPRE_Int hypre_GenerateSubComm ( MPI_Comm comm , HYPRE_Int participate , MPI_Comm *new_comm_ptr ); void hypre_merge_lists ( HYPRE_Int *list1 , HYPRE_Int *list2 , hypre_int *np1 , hypre_MPI_Datatype *dptr ); /* HYPRE_parcsr_amg.c */ HYPRE_Int HYPRE_BoomerAMGCreate ( HYPRE_Solver *solver ); HYPRE_Int HYPRE_BoomerAMGDestroy ( HYPRE_Solver solver ); HYPRE_Int HYPRE_BoomerAMGSetup ( HYPRE_Solver solver , HYPRE_ParCSRMatrix A , HYPRE_ParVector b , HYPRE_ParVector x ); HYPRE_Int HYPRE_BoomerAMGSolve ( HYPRE_Solver solver , HYPRE_ParCSRMatrix A , HYPRE_ParVector b , HYPRE_ParVector x ); HYPRE_Int HYPRE_BoomerAMGSolveT ( HYPRE_Solver solver , HYPRE_ParCSRMatrix A , HYPRE_ParVector b , HYPRE_ParVector x ); HYPRE_Int HYPRE_BoomerAMGSetRestriction ( HYPRE_Solver solver , HYPRE_Int restr_par ); HYPRE_Int HYPRE_BoomerAMGSetMaxLevels ( HYPRE_Solver solver , HYPRE_Int max_levels ); HYPRE_Int HYPRE_BoomerAMGGetMaxLevels ( HYPRE_Solver solver , HYPRE_Int *max_levels ); HYPRE_Int HYPRE_BoomerAMGSetMaxCoarseSize ( HYPRE_Solver solver , HYPRE_Int max_coarse_size ); HYPRE_Int HYPRE_BoomerAMGGetMaxCoarseSize ( HYPRE_Solver solver , HYPRE_Int *max_coarse_size ); HYPRE_Int HYPRE_BoomerAMGSetMinCoarseSize ( HYPRE_Solver solver , HYPRE_Int min_coarse_size ); HYPRE_Int HYPRE_BoomerAMGGetMinCoarseSize ( HYPRE_Solver solver , HYPRE_Int *min_coarse_size ); HYPRE_Int HYPRE_BoomerAMGSetSeqThreshold ( HYPRE_Solver solver , HYPRE_Int seq_threshold ); HYPRE_Int HYPRE_BoomerAMGGetSeqThreshold ( HYPRE_Solver solver , HYPRE_Int *seq_threshold ); HYPRE_Int HYPRE_BoomerAMGSetRedundant ( HYPRE_Solver solver , HYPRE_Int redundant ); HYPRE_Int HYPRE_BoomerAMGGetRedundant ( HYPRE_Solver solver , HYPRE_Int *redundant ); HYPRE_Int HYPRE_BoomerAMGSetStrongThreshold ( HYPRE_Solver solver , HYPRE_Real strong_threshold ); HYPRE_Int HYPRE_BoomerAMGGetStrongThreshold ( HYPRE_Solver solver , HYPRE_Real *strong_threshold ); HYPRE_Int HYPRE_BoomerAMGSetMaxRowSum ( HYPRE_Solver solver , HYPRE_Real max_row_sum ); HYPRE_Int HYPRE_BoomerAMGGetMaxRowSum ( HYPRE_Solver solver , HYPRE_Real *max_row_sum ); HYPRE_Int HYPRE_BoomerAMGSetTruncFactor ( HYPRE_Solver solver , HYPRE_Real trunc_factor ); HYPRE_Int HYPRE_BoomerAMGGetTruncFactor ( HYPRE_Solver solver , HYPRE_Real *trunc_factor ); HYPRE_Int HYPRE_BoomerAMGSetPMaxElmts ( HYPRE_Solver solver , HYPRE_Int P_max_elmts ); HYPRE_Int HYPRE_BoomerAMGGetPMaxElmts ( HYPRE_Solver solver , HYPRE_Int *P_max_elmts ); HYPRE_Int HYPRE_BoomerAMGSetJacobiTruncThreshold ( HYPRE_Solver solver , HYPRE_Real jacobi_trunc_threshold ); HYPRE_Int HYPRE_BoomerAMGGetJacobiTruncThreshold ( HYPRE_Solver solver , HYPRE_Real *jacobi_trunc_threshold ); HYPRE_Int HYPRE_BoomerAMGSetPostInterpType ( HYPRE_Solver solver , HYPRE_Int post_interp_type ); HYPRE_Int HYPRE_BoomerAMGGetPostInterpType ( HYPRE_Solver solver , HYPRE_Int *post_interp_type ); HYPRE_Int HYPRE_BoomerAMGSetSCommPkgSwitch ( HYPRE_Solver solver , HYPRE_Real S_commpkg_switch ); HYPRE_Int HYPRE_BoomerAMGSetInterpType ( HYPRE_Solver solver , HYPRE_Int interp_type ); HYPRE_Int HYPRE_BoomerAMGSetSepWeight ( HYPRE_Solver solver , HYPRE_Int sep_weight ); HYPRE_Int HYPRE_BoomerAMGSetMinIter ( HYPRE_Solver solver , HYPRE_Int min_iter ); HYPRE_Int HYPRE_BoomerAMGSetMaxIter ( HYPRE_Solver solver , HYPRE_Int max_iter ); HYPRE_Int HYPRE_BoomerAMGGetMaxIter ( HYPRE_Solver solver , HYPRE_Int *max_iter ); HYPRE_Int HYPRE_BoomerAMGSetCoarsenType ( HYPRE_Solver solver , HYPRE_Int coarsen_type ); HYPRE_Int HYPRE_BoomerAMGGetCoarsenType ( HYPRE_Solver solver , HYPRE_Int *coarsen_type ); HYPRE_Int HYPRE_BoomerAMGSetMeasureType ( HYPRE_Solver solver , HYPRE_Int measure_type ); HYPRE_Int HYPRE_BoomerAMGGetMeasureType ( HYPRE_Solver solver , HYPRE_Int *measure_type ); HYPRE_Int HYPRE_BoomerAMGSetSetupType ( HYPRE_Solver solver , HYPRE_Int setup_type ); HYPRE_Int HYPRE_BoomerAMGSetOldDefault ( HYPRE_Solver solver ); HYPRE_Int HYPRE_BoomerAMGSetCycleType ( HYPRE_Solver solver , HYPRE_Int cycle_type ); HYPRE_Int HYPRE_BoomerAMGGetCycleType ( HYPRE_Solver solver , HYPRE_Int *cycle_type ); HYPRE_Int HYPRE_BoomerAMGSetTol ( HYPRE_Solver solver , HYPRE_Real tol ); HYPRE_Int HYPRE_BoomerAMGGetTol ( HYPRE_Solver solver , HYPRE_Real *tol ); HYPRE_Int HYPRE_BoomerAMGSetNumGridSweeps ( HYPRE_Solver solver , HYPRE_Int *num_grid_sweeps ); HYPRE_Int HYPRE_BoomerAMGSetNumSweeps ( HYPRE_Solver solver , HYPRE_Int num_sweeps ); HYPRE_Int HYPRE_BoomerAMGSetCycleNumSweeps ( HYPRE_Solver solver , HYPRE_Int num_sweeps , HYPRE_Int k ); HYPRE_Int HYPRE_BoomerAMGGetCycleNumSweeps ( HYPRE_Solver solver , HYPRE_Int *num_sweeps , HYPRE_Int k ); HYPRE_Int HYPRE_BoomerAMGInitGridRelaxation ( HYPRE_Int **num_grid_sweeps_ptr , HYPRE_Int **grid_relax_type_ptr , HYPRE_Int ***grid_relax_points_ptr , HYPRE_Int coarsen_type , HYPRE_Real **relax_weights_ptr , HYPRE_Int max_levels ); HYPRE_Int HYPRE_BoomerAMGSetGridRelaxType ( HYPRE_Solver solver , HYPRE_Int *grid_relax_type ); HYPRE_Int HYPRE_BoomerAMGSetRelaxType ( HYPRE_Solver solver , HYPRE_Int relax_type ); HYPRE_Int HYPRE_BoomerAMGSetCycleRelaxType ( HYPRE_Solver solver , HYPRE_Int relax_type , HYPRE_Int k ); HYPRE_Int HYPRE_BoomerAMGGetCycleRelaxType ( HYPRE_Solver solver , HYPRE_Int *relax_type , HYPRE_Int k ); HYPRE_Int HYPRE_BoomerAMGSetRelaxOrder ( HYPRE_Solver solver , HYPRE_Int relax_order ); HYPRE_Int HYPRE_BoomerAMGSetGridRelaxPoints ( HYPRE_Solver solver , HYPRE_Int **grid_relax_points ); HYPRE_Int HYPRE_BoomerAMGSetRelaxWeight ( HYPRE_Solver solver , HYPRE_Real *relax_weight ); HYPRE_Int HYPRE_BoomerAMGSetRelaxWt ( HYPRE_Solver solver , HYPRE_Real relax_wt ); HYPRE_Int HYPRE_BoomerAMGSetLevelRelaxWt ( HYPRE_Solver solver , HYPRE_Real relax_wt , HYPRE_Int level ); HYPRE_Int HYPRE_BoomerAMGSetOmega ( HYPRE_Solver solver , HYPRE_Real *omega ); HYPRE_Int HYPRE_BoomerAMGSetOuterWt ( HYPRE_Solver solver , HYPRE_Real outer_wt ); HYPRE_Int HYPRE_BoomerAMGSetLevelOuterWt ( HYPRE_Solver solver , HYPRE_Real outer_wt , HYPRE_Int level ); HYPRE_Int HYPRE_BoomerAMGSetLogging ( HYPRE_Solver solver , HYPRE_Int logging ); HYPRE_Int HYPRE_BoomerAMGGetLogging ( HYPRE_Solver solver , HYPRE_Int *logging ); HYPRE_Int HYPRE_BoomerAMGSetPrintLevel ( HYPRE_Solver solver , HYPRE_Int print_level ); HYPRE_Int HYPRE_BoomerAMGGetPrintLevel ( HYPRE_Solver solver , HYPRE_Int *print_level ); HYPRE_Int HYPRE_BoomerAMGSetPrintFileName ( HYPRE_Solver solver , const char *print_file_name ); HYPRE_Int HYPRE_BoomerAMGSetDebugFlag ( HYPRE_Solver solver , HYPRE_Int debug_flag ); HYPRE_Int HYPRE_BoomerAMGGetDebugFlag ( HYPRE_Solver solver , HYPRE_Int *debug_flag ); HYPRE_Int HYPRE_BoomerAMGGetNumIterations ( HYPRE_Solver solver , HYPRE_Int *num_iterations ); HYPRE_Int HYPRE_BoomerAMGGetCumNumIterations ( HYPRE_Solver solver , HYPRE_Int *cum_num_iterations ); HYPRE_Int HYPRE_BoomerAMGGetCumNnzAP ( HYPRE_Solver solver , HYPRE_Real *cum_nnz_AP ); HYPRE_Int HYPRE_BoomerAMGGetResidual ( HYPRE_Solver solver , HYPRE_ParVector *residual ); HYPRE_Int HYPRE_BoomerAMGGetFinalRelativeResidualNorm ( HYPRE_Solver solver , HYPRE_Real *rel_resid_norm ); HYPRE_Int HYPRE_BoomerAMGSetNumFunctions ( HYPRE_Solver solver , HYPRE_Int num_functions ); HYPRE_Int HYPRE_BoomerAMGGetNumFunctions ( HYPRE_Solver solver , HYPRE_Int *num_functions ); HYPRE_Int HYPRE_BoomerAMGSetNodal ( HYPRE_Solver solver , HYPRE_Int nodal ); HYPRE_Int HYPRE_BoomerAMGSetNodalLevels ( HYPRE_Solver solver , HYPRE_Int nodal_levels ); HYPRE_Int HYPRE_BoomerAMGSetNodalDiag ( HYPRE_Solver solver , HYPRE_Int nodal ); HYPRE_Int HYPRE_BoomerAMGSetDofFunc ( HYPRE_Solver solver , HYPRE_Int *dof_func ); HYPRE_Int HYPRE_BoomerAMGSetNumPaths ( HYPRE_Solver solver , HYPRE_Int num_paths ); HYPRE_Int HYPRE_BoomerAMGSetAggNumLevels ( HYPRE_Solver solver , HYPRE_Int agg_num_levels ); HYPRE_Int HYPRE_BoomerAMGSetAggInterpType ( HYPRE_Solver solver , HYPRE_Int agg_interp_type ); HYPRE_Int HYPRE_BoomerAMGSetAggTruncFactor ( HYPRE_Solver solver , HYPRE_Real agg_trunc_factor ); HYPRE_Int HYPRE_BoomerAMGSetAddTruncFactor ( HYPRE_Solver solver , HYPRE_Real add_trunc_factor ); HYPRE_Int HYPRE_BoomerAMGSetMultAddTruncFactor ( HYPRE_Solver solver , HYPRE_Real add_trunc_factor ); HYPRE_Int HYPRE_BoomerAMGSetAggP12TruncFactor ( HYPRE_Solver solver , HYPRE_Real agg_P12_trunc_factor ); HYPRE_Int HYPRE_BoomerAMGSetAggPMaxElmts ( HYPRE_Solver solver , HYPRE_Int agg_P_max_elmts ); HYPRE_Int HYPRE_BoomerAMGSetAddPMaxElmts ( HYPRE_Solver solver , HYPRE_Int add_P_max_elmts ); HYPRE_Int HYPRE_BoomerAMGSetMultAddPMaxElmts ( HYPRE_Solver solver , HYPRE_Int add_P_max_elmts ); HYPRE_Int HYPRE_BoomerAMGSetAddRelaxType ( HYPRE_Solver solver , HYPRE_Int add_rlx_type ); HYPRE_Int HYPRE_BoomerAMGSetAddRelaxWt ( HYPRE_Solver solver , HYPRE_Real add_rlx_wt ); HYPRE_Int HYPRE_BoomerAMGSetAggP12MaxElmts ( HYPRE_Solver solver , HYPRE_Int agg_P12_max_elmts ); HYPRE_Int HYPRE_BoomerAMGSetChebyOrder ( HYPRE_Solver solver , HYPRE_Int order ); HYPRE_Int HYPRE_BoomerAMGSetChebyFraction ( HYPRE_Solver solver , HYPRE_Real ratio ); HYPRE_Int HYPRE_BoomerAMGSetChebyEigEst ( HYPRE_Solver solver , HYPRE_Int eig_est ); HYPRE_Int HYPRE_BoomerAMGSetChebyVariant ( HYPRE_Solver solver , HYPRE_Int variant ); HYPRE_Int HYPRE_BoomerAMGSetChebyScale ( HYPRE_Solver solver , HYPRE_Int scale ); HYPRE_Int HYPRE_BoomerAMGSetAdditive ( HYPRE_Solver solver , HYPRE_Int additive ); HYPRE_Int HYPRE_BoomerAMGGetAdditive ( HYPRE_Solver solver , HYPRE_Int *additive ); HYPRE_Int HYPRE_BoomerAMGSetMultAdditive ( HYPRE_Solver solver , HYPRE_Int mult_additive ); HYPRE_Int HYPRE_BoomerAMGGetMultAdditive ( HYPRE_Solver solver , HYPRE_Int *mult_additive ); HYPRE_Int HYPRE_BoomerAMGSetSimple ( HYPRE_Solver solver , HYPRE_Int simple ); HYPRE_Int HYPRE_BoomerAMGGetSimple ( HYPRE_Solver solver , HYPRE_Int *simple ); HYPRE_Int HYPRE_BoomerAMGSetAddLastLvl ( HYPRE_Solver solver , HYPRE_Int add_last_lvl ); HYPRE_Int HYPRE_BoomerAMGSetNonGalerkinTol ( HYPRE_Solver solver , HYPRE_Real nongalerkin_tol ); HYPRE_Int HYPRE_BoomerAMGSetLevelNonGalerkinTol ( HYPRE_Solver solver , HYPRE_Real nongalerkin_tol , HYPRE_Int level ); HYPRE_Int HYPRE_BoomerAMGSetNonGalerkTol ( HYPRE_Solver solver , HYPRE_Int nongalerk_num_tol , HYPRE_Real *nongalerk_tol ); HYPRE_Int HYPRE_BoomerAMGSetRAP2 ( HYPRE_Solver solver , HYPRE_Int rap2 ); HYPRE_Int HYPRE_BoomerAMGSetKeepTranspose ( HYPRE_Solver solver , HYPRE_Int keepTranspose ); /* HYPRE_parcsr_gmres.c */ HYPRE_Int HYPRE_ParCSRGMRESCreate ( MPI_Comm comm , HYPRE_Solver *solver ); HYPRE_Int HYPRE_ParCSRGMRESDestroy ( HYPRE_Solver solver ); HYPRE_Int HYPRE_ParCSRGMRESSetup ( HYPRE_Solver solver , HYPRE_ParCSRMatrix A , HYPRE_ParVector b , HYPRE_ParVector x ); HYPRE_Int HYPRE_ParCSRGMRESSolve ( HYPRE_Solver solver , HYPRE_ParCSRMatrix A , HYPRE_ParVector b , HYPRE_ParVector x ); HYPRE_Int HYPRE_ParCSRGMRESSetKDim ( HYPRE_Solver solver , HYPRE_Int k_dim ); HYPRE_Int HYPRE_ParCSRGMRESSetTol ( HYPRE_Solver solver , HYPRE_Real tol ); HYPRE_Int HYPRE_ParCSRGMRESSetAbsoluteTol ( HYPRE_Solver solver , HYPRE_Real a_tol ); HYPRE_Int HYPRE_ParCSRGMRESSetMinIter ( HYPRE_Solver solver , HYPRE_Int min_iter ); HYPRE_Int HYPRE_ParCSRGMRESSetMaxIter ( HYPRE_Solver solver , HYPRE_Int max_iter ); HYPRE_Int HYPRE_ParCSRGMRESSetStopCrit ( HYPRE_Solver solver , HYPRE_Int stop_crit ); HYPRE_Int HYPRE_ParCSRGMRESSetPrecond ( HYPRE_Solver solver , HYPRE_PtrToParSolverFcn precond , HYPRE_PtrToParSolverFcn precond_setup , HYPRE_Solver precond_solver ); HYPRE_Int HYPRE_ParCSRGMRESGetPrecond ( HYPRE_Solver solver , HYPRE_Solver *precond_data_ptr ); HYPRE_Int HYPRE_ParCSRGMRESSetLogging ( HYPRE_Solver solver , HYPRE_Int logging ); HYPRE_Int HYPRE_ParCSRGMRESSetPrintLevel ( HYPRE_Solver solver , HYPRE_Int print_level ); HYPRE_Int HYPRE_ParCSRGMRESGetNumIterations ( HYPRE_Solver solver , HYPRE_Int *num_iterations ); HYPRE_Int HYPRE_ParCSRGMRESGetFinalRelativeResidualNorm ( HYPRE_Solver solver , HYPRE_Real *norm ); /* HYPRE_parcsr_pcg.c */ HYPRE_Int HYPRE_ParCSRPCGCreate ( MPI_Comm comm , HYPRE_Solver *solver ); HYPRE_Int HYPRE_ParCSRPCGDestroy ( HYPRE_Solver solver ); HYPRE_Int HYPRE_ParCSRPCGSetup ( HYPRE_Solver solver , HYPRE_ParCSRMatrix A , HYPRE_ParVector b , HYPRE_ParVector x ); HYPRE_Int HYPRE_ParCSRPCGSolve ( HYPRE_Solver solver , HYPRE_ParCSRMatrix A , HYPRE_ParVector b , HYPRE_ParVector x ); HYPRE_Int HYPRE_ParCSRPCGSetTol ( HYPRE_Solver solver , HYPRE_Real tol ); HYPRE_Int HYPRE_ParCSRPCGSetAbsoluteTol ( HYPRE_Solver solver , HYPRE_Real a_tol ); HYPRE_Int HYPRE_ParCSRPCGSetMaxIter ( HYPRE_Solver solver , HYPRE_Int max_iter ); HYPRE_Int HYPRE_ParCSRPCGSetStopCrit ( HYPRE_Solver solver , HYPRE_Int stop_crit ); HYPRE_Int HYPRE_ParCSRPCGSetTwoNorm ( HYPRE_Solver solver , HYPRE_Int two_norm ); HYPRE_Int HYPRE_ParCSRPCGSetRelChange ( HYPRE_Solver solver , HYPRE_Int rel_change ); HYPRE_Int HYPRE_ParCSRPCGSetPrecond ( HYPRE_Solver solver , HYPRE_PtrToParSolverFcn precond , HYPRE_PtrToParSolverFcn precond_setup , HYPRE_Solver precond_solver ); HYPRE_Int HYPRE_ParCSRPCGGetPrecond ( HYPRE_Solver solver , HYPRE_Solver *precond_data_ptr ); HYPRE_Int HYPRE_ParCSRPCGSetPrintLevel ( HYPRE_Solver solver , HYPRE_Int level ); HYPRE_Int HYPRE_ParCSRPCGSetLogging ( HYPRE_Solver solver , HYPRE_Int level ); HYPRE_Int HYPRE_ParCSRPCGGetNumIterations ( HYPRE_Solver solver , HYPRE_Int *num_iterations ); HYPRE_Int HYPRE_ParCSRPCGGetFinalRelativeResidualNorm ( HYPRE_Solver solver , HYPRE_Real *norm ); HYPRE_Int HYPRE_ParCSRDiagScaleSetup ( HYPRE_Solver solver , HYPRE_ParCSRMatrix A , HYPRE_ParVector y , HYPRE_ParVector x ); HYPRE_Int HYPRE_ParCSRDiagScale ( HYPRE_Solver solver , HYPRE_ParCSRMatrix HA , HYPRE_ParVector Hy , HYPRE_ParVector Hx ); /* par_add_cycle.c */ HYPRE_Int hypre_BoomerAMGAdditiveCycle ( void *amg_vdata ); HYPRE_Int hypre_CreateLambda ( void *amg_vdata ); HYPRE_Int hypre_CreateDinv ( void *amg_vdata ); /* par_amg.c */ void *hypre_BoomerAMGCreate ( void ); HYPRE_Int hypre_BoomerAMGDestroy ( void *data ); HYPRE_Int hypre_BoomerAMGSetRestriction ( void *data , HYPRE_Int restr_par ); HYPRE_Int hypre_BoomerAMGSetMaxLevels ( void *data , HYPRE_Int max_levels ); HYPRE_Int hypre_BoomerAMGGetMaxLevels ( void *data , HYPRE_Int *max_levels ); HYPRE_Int hypre_BoomerAMGSetMaxCoarseSize ( void *data , HYPRE_Int max_coarse_size ); HYPRE_Int hypre_BoomerAMGGetMaxCoarseSize ( void *data , HYPRE_Int *max_coarse_size ); HYPRE_Int hypre_BoomerAMGSetMinCoarseSize ( void *data , HYPRE_Int min_coarse_size ); HYPRE_Int hypre_BoomerAMGGetMinCoarseSize ( void *data , HYPRE_Int *min_coarse_size ); HYPRE_Int hypre_BoomerAMGSetSeqThreshold ( void *data , HYPRE_Int seq_threshold ); HYPRE_Int hypre_BoomerAMGGetSeqThreshold ( void *data , HYPRE_Int *seq_threshold ); HYPRE_Int hypre_BoomerAMGSetRedundant ( void *data , HYPRE_Int redundant ); HYPRE_Int hypre_BoomerAMGGetRedundant ( void *data , HYPRE_Int *redundant ); HYPRE_Int hypre_BoomerAMGSetStrongThreshold ( void *data , HYPRE_Real strong_threshold ); HYPRE_Int hypre_BoomerAMGGetStrongThreshold ( void *data , HYPRE_Real *strong_threshold ); HYPRE_Int hypre_BoomerAMGSetMaxRowSum ( void *data , HYPRE_Real max_row_sum ); HYPRE_Int hypre_BoomerAMGGetMaxRowSum ( void *data , HYPRE_Real *max_row_sum ); HYPRE_Int hypre_BoomerAMGSetTruncFactor ( void *data , HYPRE_Real trunc_factor ); HYPRE_Int hypre_BoomerAMGGetTruncFactor ( void *data , HYPRE_Real *trunc_factor ); HYPRE_Int hypre_BoomerAMGSetPMaxElmts ( void *data , HYPRE_Int P_max_elmts ); HYPRE_Int hypre_BoomerAMGGetPMaxElmts ( void *data , HYPRE_Int *P_max_elmts ); HYPRE_Int hypre_BoomerAMGSetJacobiTruncThreshold ( void *data , HYPRE_Real jacobi_trunc_threshold ); HYPRE_Int hypre_BoomerAMGGetJacobiTruncThreshold ( void *data , HYPRE_Real *jacobi_trunc_threshold ); HYPRE_Int hypre_BoomerAMGSetPostInterpType ( void *data , HYPRE_Int post_interp_type ); HYPRE_Int hypre_BoomerAMGGetPostInterpType ( void *data , HYPRE_Int *post_interp_type ); HYPRE_Int hypre_BoomerAMGSetSCommPkgSwitch ( void *data , HYPRE_Real S_commpkg_switch ); HYPRE_Int hypre_BoomerAMGGetSCommPkgSwitch ( void *data , HYPRE_Real *S_commpkg_switch ); HYPRE_Int hypre_BoomerAMGSetInterpType ( void *data , HYPRE_Int interp_type ); HYPRE_Int hypre_BoomerAMGGetInterpType ( void *data , HYPRE_Int *interp_type ); HYPRE_Int hypre_BoomerAMGSetSepWeight ( void *data , HYPRE_Int sep_weight ); HYPRE_Int hypre_BoomerAMGSetMinIter ( void *data , HYPRE_Int min_iter ); HYPRE_Int hypre_BoomerAMGGetMinIter ( void *data , HYPRE_Int *min_iter ); HYPRE_Int hypre_BoomerAMGSetMaxIter ( void *data , HYPRE_Int max_iter ); HYPRE_Int hypre_BoomerAMGGetMaxIter ( void *data , HYPRE_Int *max_iter ); HYPRE_Int hypre_BoomerAMGSetCoarsenType ( void *data , HYPRE_Int coarsen_type ); HYPRE_Int hypre_BoomerAMGGetCoarsenType ( void *data , HYPRE_Int *coarsen_type ); HYPRE_Int hypre_BoomerAMGSetMeasureType ( void *data , HYPRE_Int measure_type ); HYPRE_Int hypre_BoomerAMGGetMeasureType ( void *data , HYPRE_Int *measure_type ); HYPRE_Int hypre_BoomerAMGSetSetupType ( void *data , HYPRE_Int setup_type ); HYPRE_Int hypre_BoomerAMGGetSetupType ( void *data , HYPRE_Int *setup_type ); HYPRE_Int hypre_BoomerAMGSetCycleType ( void *data , HYPRE_Int cycle_type ); HYPRE_Int hypre_BoomerAMGGetCycleType ( void *data , HYPRE_Int *cycle_type ); HYPRE_Int hypre_BoomerAMGSetTol ( void *data , HYPRE_Real tol ); HYPRE_Int hypre_BoomerAMGGetTol ( void *data , HYPRE_Real *tol ); HYPRE_Int hypre_BoomerAMGSetNumSweeps ( void *data , HYPRE_Int num_sweeps ); HYPRE_Int hypre_BoomerAMGSetCycleNumSweeps ( void *data , HYPRE_Int num_sweeps , HYPRE_Int k ); HYPRE_Int hypre_BoomerAMGGetCycleNumSweeps ( void *data , HYPRE_Int *num_sweeps , HYPRE_Int k ); HYPRE_Int hypre_BoomerAMGSetNumGridSweeps ( void *data , HYPRE_Int *num_grid_sweeps ); HYPRE_Int hypre_BoomerAMGGetNumGridSweeps ( void *data , HYPRE_Int **num_grid_sweeps ); HYPRE_Int hypre_BoomerAMGSetRelaxType ( void *data , HYPRE_Int relax_type ); HYPRE_Int hypre_BoomerAMGSetCycleRelaxType ( void *data , HYPRE_Int relax_type , HYPRE_Int k ); HYPRE_Int hypre_BoomerAMGGetCycleRelaxType ( void *data , HYPRE_Int *relax_type , HYPRE_Int k ); HYPRE_Int hypre_BoomerAMGSetRelaxOrder ( void *data , HYPRE_Int relax_order ); HYPRE_Int hypre_BoomerAMGGetRelaxOrder ( void *data , HYPRE_Int *relax_order ); HYPRE_Int hypre_BoomerAMGSetGridRelaxType ( void *data , HYPRE_Int *grid_relax_type ); HYPRE_Int hypre_BoomerAMGGetGridRelaxType ( void *data , HYPRE_Int **grid_relax_type ); HYPRE_Int hypre_BoomerAMGSetGridRelaxPoints ( void *data , HYPRE_Int **grid_relax_points ); HYPRE_Int hypre_BoomerAMGGetGridRelaxPoints ( void *data , HYPRE_Int ***grid_relax_points ); HYPRE_Int hypre_BoomerAMGSetRelaxWeight ( void *data , HYPRE_Real *relax_weight ); HYPRE_Int hypre_BoomerAMGGetRelaxWeight ( void *data , HYPRE_Real **relax_weight ); HYPRE_Int hypre_BoomerAMGSetRelaxWt ( void *data , HYPRE_Real relax_weight ); HYPRE_Int hypre_BoomerAMGSetLevelRelaxWt ( void *data , HYPRE_Real relax_weight , HYPRE_Int level ); HYPRE_Int hypre_BoomerAMGGetLevelRelaxWt ( void *data , HYPRE_Real *relax_weight , HYPRE_Int level ); HYPRE_Int hypre_BoomerAMGSetOmega ( void *data , HYPRE_Real *omega ); HYPRE_Int hypre_BoomerAMGGetOmega ( void *data , HYPRE_Real **omega ); HYPRE_Int hypre_BoomerAMGSetOuterWt ( void *data , HYPRE_Real omega ); HYPRE_Int hypre_BoomerAMGSetLevelOuterWt ( void *data , HYPRE_Real omega , HYPRE_Int level ); HYPRE_Int hypre_BoomerAMGGetLevelOuterWt ( void *data , HYPRE_Real *omega , HYPRE_Int level ); HYPRE_Int hypre_BoomerAMGSetLogging ( void *data , HYPRE_Int logging ); HYPRE_Int hypre_BoomerAMGGetLogging ( void *data , HYPRE_Int *logging ); HYPRE_Int hypre_BoomerAMGSetPrintLevel ( void *data , HYPRE_Int print_level ); HYPRE_Int hypre_BoomerAMGGetPrintLevel ( void *data , HYPRE_Int *print_level ); HYPRE_Int hypre_BoomerAMGSetPrintFileName ( void *data , const char *print_file_name ); HYPRE_Int hypre_BoomerAMGGetPrintFileName ( void *data , char **print_file_name ); HYPRE_Int hypre_BoomerAMGSetNumIterations ( void *data , HYPRE_Int num_iterations ); HYPRE_Int hypre_BoomerAMGSetDebugFlag ( void *data , HYPRE_Int debug_flag ); HYPRE_Int hypre_BoomerAMGGetDebugFlag ( void *data , HYPRE_Int *debug_flag ); HYPRE_Int hypre_BoomerAMGSetNumFunctions ( void *data , HYPRE_Int num_functions ); HYPRE_Int hypre_BoomerAMGGetNumFunctions ( void *data , HYPRE_Int *num_functions ); HYPRE_Int hypre_BoomerAMGSetNodal ( void *data , HYPRE_Int nodal ); HYPRE_Int hypre_BoomerAMGSetNodalLevels ( void *data , HYPRE_Int nodal_levels ); HYPRE_Int hypre_BoomerAMGSetNodalDiag ( void *data , HYPRE_Int nodal ); HYPRE_Int hypre_BoomerAMGSetNumPaths ( void *data , HYPRE_Int num_paths ); HYPRE_Int hypre_BoomerAMGSetAggNumLevels ( void *data , HYPRE_Int agg_num_levels ); HYPRE_Int hypre_BoomerAMGSetAggInterpType ( void *data , HYPRE_Int agg_interp_type ); HYPRE_Int hypre_BoomerAMGSetAggPMaxElmts ( void *data , HYPRE_Int agg_P_max_elmts ); HYPRE_Int hypre_BoomerAMGSetMultAddPMaxElmts ( void *data , HYPRE_Int add_P_max_elmts ); HYPRE_Int hypre_BoomerAMGSetAddRelaxType ( void *data , HYPRE_Int add_rlx_type ); HYPRE_Int hypre_BoomerAMGSetAddRelaxWt ( void *data , HYPRE_Real add_rlx_wt ); HYPRE_Int hypre_BoomerAMGSetAggP12MaxElmts ( void *data , HYPRE_Int agg_P12_max_elmts ); HYPRE_Int hypre_BoomerAMGSetAggTruncFactor ( void *data , HYPRE_Real agg_trunc_factor ); HYPRE_Int hypre_BoomerAMGSetMultAddTruncFactor ( void *data , HYPRE_Real add_trunc_factor ); HYPRE_Int hypre_BoomerAMGSetAggP12TruncFactor ( void *data , HYPRE_Real agg_P12_trunc_factor ); HYPRE_Int hypre_BoomerAMGSetNumPoints ( void *data , HYPRE_Int num_points ); HYPRE_Int hypre_BoomerAMGSetDofFunc ( void *data , HYPRE_Int *dof_func ); HYPRE_Int hypre_BoomerAMGSetPointDofMap ( void *data , HYPRE_Int *point_dof_map ); HYPRE_Int hypre_BoomerAMGSetDofPoint ( void *data , HYPRE_Int *dof_point ); HYPRE_Int hypre_BoomerAMGGetNumIterations ( void *data , HYPRE_Int *num_iterations ); HYPRE_Int hypre_BoomerAMGGetCumNumIterations ( void *data , HYPRE_Int *cum_num_iterations ); HYPRE_Int hypre_BoomerAMGGetCumNnzAP ( void *data , HYPRE_Real *cum_nnz_AP ); HYPRE_Int hypre_BoomerAMGGetResidual ( void *data , hypre_ParVector **resid ); HYPRE_Int hypre_BoomerAMGGetRelResidualNorm ( void *data , HYPRE_Real *rel_resid_norm ); HYPRE_Int hypre_BoomerAMGSetChebyOrder ( void *data , HYPRE_Int order ); HYPRE_Int hypre_BoomerAMGSetChebyFraction ( void *data , HYPRE_Real ratio ); HYPRE_Int hypre_BoomerAMGSetChebyEigEst ( void *data , HYPRE_Int eig_est ); HYPRE_Int hypre_BoomerAMGSetChebyVariant ( void *data , HYPRE_Int variant ); HYPRE_Int hypre_BoomerAMGSetChebyScale ( void *data , HYPRE_Int scale ); HYPRE_Int hypre_BoomerAMGSetAdditive ( void *data , HYPRE_Int additive ); HYPRE_Int hypre_BoomerAMGGetAdditive ( void *data , HYPRE_Int *additive ); HYPRE_Int hypre_BoomerAMGSetMultAdditive ( void *data , HYPRE_Int mult_additive ); HYPRE_Int hypre_BoomerAMGGetMultAdditive ( void *data , HYPRE_Int *mult_additive ); HYPRE_Int hypre_BoomerAMGSetSimple ( void *data , HYPRE_Int simple ); HYPRE_Int hypre_BoomerAMGGetSimple ( void *data , HYPRE_Int *simple ); HYPRE_Int hypre_BoomerAMGSetAddLastLvl ( void *data , HYPRE_Int add_last_lvl ); HYPRE_Int hypre_BoomerAMGSetNonGalerkinTol ( void *data , HYPRE_Real nongalerkin_tol ); HYPRE_Int hypre_BoomerAMGSetLevelNonGalerkinTol ( void *data , HYPRE_Real nongalerkin_tol , HYPRE_Int level ); HYPRE_Int hypre_BoomerAMGSetNonGalerkTol ( void *data , HYPRE_Int nongalerk_num_tol , HYPRE_Real *nongalerk_tol ); HYPRE_Int hypre_BoomerAMGSetRAP2 ( void *data , HYPRE_Int rap2 ); HYPRE_Int hypre_BoomerAMGSetKeepTranspose ( void *data , HYPRE_Int keepTranspose ); /* par_amg_setup.c */ HYPRE_Int hypre_BoomerAMGSetup ( void *amg_vdata , hypre_ParCSRMatrix *A , hypre_ParVector *f , hypre_ParVector *u ); /* par_amg_solve.c */ HYPRE_Int hypre_BoomerAMGSolve ( void *amg_vdata , hypre_ParCSRMatrix *A , hypre_ParVector *f , hypre_ParVector *u ); /* par_cg_relax_wt.c */ HYPRE_Int hypre_BoomerAMGCGRelaxWt ( void *amg_vdata , HYPRE_Int level , HYPRE_Int num_cg_sweeps , HYPRE_Real *rlx_wt_ptr ); HYPRE_Int hypre_Bisection ( HYPRE_Int n , HYPRE_Real *diag , HYPRE_Real *offd , HYPRE_Real y , HYPRE_Real z , HYPRE_Real tol , HYPRE_Int k , HYPRE_Real *ev_ptr ); /* par_cheby.c */ HYPRE_Int hypre_ParCSRRelax_Cheby_Setup ( hypre_ParCSRMatrix *A , HYPRE_Real max_eig , HYPRE_Real min_eig , HYPRE_Real fraction , HYPRE_Int order , HYPRE_Int scale , HYPRE_Int variant , HYPRE_Real **coefs_ptr , HYPRE_Real **ds_ptr ); HYPRE_Int hypre_ParCSRRelax_Cheby_Solve ( hypre_ParCSRMatrix *A , hypre_ParVector *f , HYPRE_Real *ds_data , HYPRE_Real *coefs , HYPRE_Int order , HYPRE_Int scale , HYPRE_Int variant , hypre_ParVector *u , hypre_ParVector *v , hypre_ParVector *r ); /* par_coarsen.c */ HYPRE_Int hypre_BoomerAMGCoarsen ( hypre_ParCSRMatrix *S , hypre_ParCSRMatrix *A , HYPRE_Int CF_init , HYPRE_Int debug_flag , HYPRE_Int **CF_marker_ptr ); HYPRE_Int hypre_BoomerAMGCoarsenRuge ( hypre_ParCSRMatrix *S , hypre_ParCSRMatrix *A , HYPRE_Int measure_type , HYPRE_Int coarsen_type , HYPRE_Int debug_flag , HYPRE_Int **CF_marker_ptr ); HYPRE_Int hypre_BoomerAMGCoarsenFalgout ( hypre_ParCSRMatrix *S , hypre_ParCSRMatrix *A , HYPRE_Int measure_type , HYPRE_Int debug_flag , HYPRE_Int **CF_marker_ptr ); HYPRE_Int hypre_BoomerAMGCoarsenHMIS ( hypre_ParCSRMatrix *S , hypre_ParCSRMatrix *A , HYPRE_Int measure_type , HYPRE_Int debug_flag , HYPRE_Int **CF_marker_ptr ); HYPRE_Int hypre_BoomerAMGCoarsenPMIS ( hypre_ParCSRMatrix *S , hypre_ParCSRMatrix *A , HYPRE_Int CF_init , HYPRE_Int debug_flag , HYPRE_Int **CF_marker_ptr ); /* par_coarse_parms.c */ HYPRE_Int hypre_BoomerAMGCoarseParms ( MPI_Comm comm , HYPRE_Int local_num_variables , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int *CF_marker , HYPRE_Int **coarse_dof_func_ptr , HYPRE_Int **coarse_pnts_global_ptr ); /* par_cycle.c */ HYPRE_Int hypre_BoomerAMGCycle ( void *amg_vdata , hypre_ParVector **F_array , hypre_ParVector **U_array ); /* par_difconv.c */ HYPRE_ParCSRMatrix GenerateDifConv ( MPI_Comm comm , HYPRE_Int nx , HYPRE_Int ny , HYPRE_Int nz , HYPRE_Int P , HYPRE_Int Q , HYPRE_Int R , HYPRE_Int p , HYPRE_Int q , HYPRE_Int r , HYPRE_Real *value ); /* par_indepset.c */ HYPRE_Int hypre_BoomerAMGIndepSetInit ( hypre_ParCSRMatrix *S , HYPRE_Real *measure_array , HYPRE_Int seq_rand ); HYPRE_Int hypre_BoomerAMGIndepSet ( hypre_ParCSRMatrix *S , HYPRE_Real *measure_array , HYPRE_Int *graph_array , HYPRE_Int graph_array_size , HYPRE_Int *graph_array_offd , HYPRE_Int graph_array_offd_size , HYPRE_Int *IS_marker , HYPRE_Int *IS_marker_offd ); /* par_interp.c */ HYPRE_Int hypre_BoomerAMGBuildInterp ( hypre_ParCSRMatrix *A , HYPRE_Int *CF_marker , hypre_ParCSRMatrix *S , HYPRE_Int *num_cpts_global , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int debug_flag , HYPRE_Real trunc_factor , HYPRE_Int max_elmts , HYPRE_Int *col_offd_S_to_A , hypre_ParCSRMatrix **P_ptr ); HYPRE_Int hypre_BoomerAMGBuildInterpHE ( hypre_ParCSRMatrix *A , HYPRE_Int *CF_marker , hypre_ParCSRMatrix *S , HYPRE_Int *num_cpts_global , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int debug_flag , HYPRE_Real trunc_factor , HYPRE_Int max_elmts , HYPRE_Int *col_offd_S_to_A , hypre_ParCSRMatrix **P_ptr ); HYPRE_Int hypre_BoomerAMGBuildDirInterp ( hypre_ParCSRMatrix *A , HYPRE_Int *CF_marker , hypre_ParCSRMatrix *S , HYPRE_Int *num_cpts_global , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int debug_flag , HYPRE_Real trunc_factor , HYPRE_Int max_elmts , HYPRE_Int *col_offd_S_to_A , hypre_ParCSRMatrix **P_ptr ); HYPRE_Int hypre_BoomerAMGInterpTruncation ( hypre_ParCSRMatrix *P , HYPRE_Real trunc_factor , HYPRE_Int max_elmts ); void hypre_qsort2abs ( HYPRE_Int *v , HYPRE_Real *w , HYPRE_Int left , HYPRE_Int right ); HYPRE_Int hypre_BoomerAMGBuildInterpModUnk ( hypre_ParCSRMatrix *A , HYPRE_Int *CF_marker , hypre_ParCSRMatrix *S , HYPRE_Int *num_cpts_global , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int debug_flag , HYPRE_Real trunc_factor , HYPRE_Int max_elmts , HYPRE_Int *col_offd_S_to_A , hypre_ParCSRMatrix **P_ptr ); HYPRE_Int hypre_BoomerAMGTruncandBuild ( hypre_ParCSRMatrix *P , HYPRE_Real trunc_factor , HYPRE_Int max_elmts ); hypre_ParCSRMatrix *hypre_CreateC ( hypre_ParCSRMatrix *A , HYPRE_Real w ); /* par_jacobi_interp.c */ void hypre_BoomerAMGJacobiInterp ( hypre_ParCSRMatrix *A , hypre_ParCSRMatrix **P , hypre_ParCSRMatrix *S , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int *CF_marker , HYPRE_Int level , HYPRE_Real truncation_threshold , HYPRE_Real truncation_threshold_minus ); void hypre_BoomerAMGJacobiInterp_1 ( hypre_ParCSRMatrix *A , hypre_ParCSRMatrix **P , hypre_ParCSRMatrix *S , HYPRE_Int *CF_marker , HYPRE_Int level , HYPRE_Real truncation_threshold , HYPRE_Real truncation_threshold_minus , HYPRE_Int *dof_func , HYPRE_Int *dof_func_offd , HYPRE_Real weight_AF ); void hypre_BoomerAMGTruncateInterp ( hypre_ParCSRMatrix *P , HYPRE_Real eps , HYPRE_Real dlt , HYPRE_Int *CF_marker ); HYPRE_Int hypre_ParCSRMatrix_dof_func_offd ( hypre_ParCSRMatrix *A , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int **dof_func_offd ); /* par_laplace_27pt.c */ HYPRE_ParCSRMatrix GenerateLaplacian27pt ( MPI_Comm comm , HYPRE_Int nx , HYPRE_Int ny , HYPRE_Int nz , HYPRE_Int P , HYPRE_Int Q , HYPRE_Int R , HYPRE_Int p , HYPRE_Int q , HYPRE_Int r , HYPRE_Real *value ); HYPRE_Int hypre_map3 ( HYPRE_Int ix , HYPRE_Int iy , HYPRE_Int iz , HYPRE_Int p , HYPRE_Int q , HYPRE_Int r , HYPRE_Int P , HYPRE_Int Q , HYPRE_Int R , HYPRE_Int *nx_part , HYPRE_Int *ny_part , HYPRE_Int *nz_part , HYPRE_Int *global_part ); /* par_laplace_9pt.c */ HYPRE_ParCSRMatrix GenerateLaplacian9pt ( MPI_Comm comm , HYPRE_Int nx , HYPRE_Int ny , HYPRE_Int P , HYPRE_Int Q , HYPRE_Int p , HYPRE_Int q , HYPRE_Real *value ); HYPRE_Int hypre_map2 ( HYPRE_Int ix , HYPRE_Int iy , HYPRE_Int p , HYPRE_Int q , HYPRE_Int P , HYPRE_Int Q , HYPRE_Int *nx_part , HYPRE_Int *ny_part , HYPRE_Int *global_part ); /* par_laplace.c */ HYPRE_ParCSRMatrix GenerateLaplacian ( MPI_Comm comm , HYPRE_Int nx , HYPRE_Int ny , HYPRE_Int nz , HYPRE_Int P , HYPRE_Int Q , HYPRE_Int R , HYPRE_Int p , HYPRE_Int q , HYPRE_Int r , HYPRE_Real *value ); HYPRE_Int hypre_map ( HYPRE_Int ix , HYPRE_Int iy , HYPRE_Int iz , HYPRE_Int p , HYPRE_Int q , HYPRE_Int r , HYPRE_Int P , HYPRE_Int Q , HYPRE_Int R , HYPRE_Int *nx_part , HYPRE_Int *ny_part , HYPRE_Int *nz_part , HYPRE_Int *global_part ); HYPRE_ParCSRMatrix GenerateSysLaplacian ( MPI_Comm comm , HYPRE_Int nx , HYPRE_Int ny , HYPRE_Int nz , HYPRE_Int P , HYPRE_Int Q , HYPRE_Int R , HYPRE_Int p , HYPRE_Int q , HYPRE_Int r , HYPRE_Int num_fun , HYPRE_Real *mtrx , HYPRE_Real *value ); HYPRE_ParCSRMatrix GenerateSysLaplacianVCoef ( MPI_Comm comm , HYPRE_Int nx , HYPRE_Int ny , HYPRE_Int nz , HYPRE_Int P , HYPRE_Int Q , HYPRE_Int R , HYPRE_Int p , HYPRE_Int q , HYPRE_Int r , HYPRE_Int num_fun , HYPRE_Real *mtrx , HYPRE_Real *value ); /* par_lr_interp.c */ HYPRE_Int hypre_BoomerAMGBuildStdInterp ( hypre_ParCSRMatrix *A , HYPRE_Int *CF_marker , hypre_ParCSRMatrix *S , HYPRE_Int *num_cpts_global , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int debug_flag , HYPRE_Real trunc_factor , HYPRE_Int max_elmts , HYPRE_Int sep_weight , HYPRE_Int *col_offd_S_to_A , hypre_ParCSRMatrix **P_ptr ); HYPRE_Int hypre_BoomerAMGBuildExtPIInterp ( hypre_ParCSRMatrix *A , HYPRE_Int *CF_marker , hypre_ParCSRMatrix *S , HYPRE_Int *num_cpts_global , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int debug_flag , HYPRE_Real trunc_factor , HYPRE_Int max_elmts , HYPRE_Int *col_offd_S_to_A , hypre_ParCSRMatrix **P_ptr ); HYPRE_Int hypre_BoomerAMGBuildExtPICCInterp ( hypre_ParCSRMatrix *A , HYPRE_Int *CF_marker , hypre_ParCSRMatrix *S , HYPRE_Int *num_cpts_global , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int debug_flag , HYPRE_Real trunc_factor , HYPRE_Int max_elmts , HYPRE_Int *col_offd_S_to_A , hypre_ParCSRMatrix **P_ptr ); HYPRE_Int hypre_BoomerAMGBuildFFInterp ( hypre_ParCSRMatrix *A , HYPRE_Int *CF_marker , hypre_ParCSRMatrix *S , HYPRE_Int *num_cpts_global , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int debug_flag , HYPRE_Real trunc_factor , HYPRE_Int max_elmts , HYPRE_Int *col_offd_S_to_A , hypre_ParCSRMatrix **P_ptr ); HYPRE_Int hypre_BoomerAMGBuildFF1Interp ( hypre_ParCSRMatrix *A , HYPRE_Int *CF_marker , hypre_ParCSRMatrix *S , HYPRE_Int *num_cpts_global , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int debug_flag , HYPRE_Real trunc_factor , HYPRE_Int max_elmts , HYPRE_Int *col_offd_S_to_A , hypre_ParCSRMatrix **P_ptr ); HYPRE_Int hypre_BoomerAMGBuildExtInterp ( hypre_ParCSRMatrix *A , HYPRE_Int *CF_marker , hypre_ParCSRMatrix *S , HYPRE_Int *num_cpts_global , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int debug_flag , HYPRE_Real trunc_factor , HYPRE_Int max_elmts , HYPRE_Int *col_offd_S_to_A , hypre_ParCSRMatrix **P_ptr ); /* par_multi_interp.c */ HYPRE_Int hypre_BoomerAMGBuildMultipass ( hypre_ParCSRMatrix *A , HYPRE_Int *CF_marker , hypre_ParCSRMatrix *S , HYPRE_Int *num_cpts_global , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int debug_flag , HYPRE_Real trunc_factor , HYPRE_Int P_max_elmts , HYPRE_Int weight_option , HYPRE_Int *col_offd_S_to_A , hypre_ParCSRMatrix **P_ptr ); /* par_nongalerkin.c */ HYPRE_Int hypre_GrabSubArray ( HYPRE_Int *indices , HYPRE_Int start , HYPRE_Int end , HYPRE_Int *array , HYPRE_Int *output ); void hypre_qsort2_abs ( HYPRE_Int *v , HYPRE_Real *w , HYPRE_Int left , HYPRE_Int right ); HYPRE_Int hypre_IntersectTwoArrays ( HYPRE_Int *x , HYPRE_Real *x_data , HYPRE_Int x_length , HYPRE_Int *y , HYPRE_Int y_length , HYPRE_Int *z , HYPRE_Real *output_x_data , HYPRE_Int *intersect_length ); HYPRE_Int hypre_SortedCopyParCSRData ( hypre_ParCSRMatrix *A , hypre_ParCSRMatrix *B ); HYPRE_Int hypre_BoomerAMG_MyCreateS ( hypre_ParCSRMatrix *A , HYPRE_Real strength_threshold , HYPRE_Real max_row_sum , HYPRE_Int num_functions , HYPRE_Int *dof_func , hypre_ParCSRMatrix **S_ptr ); HYPRE_Int hypre_NonGalerkinIJBufferInit ( HYPRE_Int *ijbuf_cnt , HYPRE_Int *ijbuf_rowcounter , HYPRE_Int *ijbuf_numcols ); HYPRE_Int hypre_NonGalerkinIJBufferNewRow ( HYPRE_Int *ijbuf_rownums , HYPRE_Int *ijbuf_numcols , HYPRE_Int *ijbuf_rowcounter , HYPRE_Int new_row ); HYPRE_Int hypre_NonGalerkinIJBufferCompressRow ( HYPRE_Int *ijbuf_cnt , HYPRE_Int ijbuf_rowcounter , HYPRE_Real *ijbuf_data , HYPRE_Int *ijbuf_cols , HYPRE_Int *ijbuf_rownums , HYPRE_Int *ijbuf_numcols ); HYPRE_Int hypre_NonGalerkinIJBufferCompress ( HYPRE_Int ijbuf_size , HYPRE_Int *ijbuf_cnt , HYPRE_Int *ijbuf_rowcounter , HYPRE_Real **ijbuf_data , HYPRE_Int **ijbuf_cols , HYPRE_Int **ijbuf_rownums , HYPRE_Int **ijbuf_numcols ); HYPRE_Int hypre_NonGalerkinIJBufferWrite ( HYPRE_IJMatrix B , HYPRE_Int *ijbuf_cnt , HYPRE_Int ijbuf_size , HYPRE_Int *ijbuf_rowcounter , HYPRE_Real **ijbuf_data , HYPRE_Int **ijbuf_cols , HYPRE_Int **ijbuf_rownums , HYPRE_Int **ijbuf_numcols , HYPRE_Int row_to_write , HYPRE_Int col_to_write , HYPRE_Real val_to_write ); HYPRE_Int hypre_NonGalerkinIJBufferEmpty ( HYPRE_IJMatrix B , HYPRE_Int ijbuf_size , HYPRE_Int *ijbuf_cnt , HYPRE_Int ijbuf_rowcounter , HYPRE_Real **ijbuf_data , HYPRE_Int **ijbuf_cols , HYPRE_Int **ijbuf_rownums , HYPRE_Int **ijbuf_numcols ); hypre_ParCSRMatrix * hypre_NonGalerkinSparsityPattern(hypre_ParCSRMatrix *R_IAP, hypre_ParCSRMatrix *RAP, HYPRE_Int * CF_marker, HYPRE_Real droptol, HYPRE_Int sym_collapse, HYPRE_Int collapse_beta ); HYPRE_Int hypre_BoomerAMGBuildNonGalerkinCoarseOperator( hypre_ParCSRMatrix **RAP_ptr, hypre_ParCSRMatrix *AP, HYPRE_Real strong_threshold, HYPRE_Real max_row_sum, HYPRE_Int num_functions, HYPRE_Int * dof_func_value, HYPRE_Real S_commpkg_switch, HYPRE_Int * CF_marker, HYPRE_Real droptol, HYPRE_Int sym_collapse, HYPRE_Real lump_percent, HYPRE_Int collapse_beta ); /* par_rap.c */ hypre_CSRMatrix *hypre_ExchangeRAPData ( hypre_CSRMatrix *RAP_int , hypre_ParCSRCommPkg *comm_pkg_RT ); HYPRE_Int hypre_BoomerAMGBuildCoarseOperator ( hypre_ParCSRMatrix *RT , hypre_ParCSRMatrix *A , hypre_ParCSRMatrix *P , hypre_ParCSRMatrix **RAP_ptr ); HYPRE_Int hypre_BoomerAMGBuildCoarseOperatorKT ( hypre_ParCSRMatrix *RT , hypre_ParCSRMatrix *A , hypre_ParCSRMatrix *P , HYPRE_Int keepTranspose, hypre_ParCSRMatrix **RAP_ptr ); /* par_rap_communication.c */ HYPRE_Int hypre_GetCommPkgRTFromCommPkgA ( hypre_ParCSRMatrix *RT , hypre_ParCSRMatrix *A , HYPRE_Int *fine_to_coarse_offd ); HYPRE_Int hypre_GenerateSendMapAndCommPkg ( MPI_Comm comm , HYPRE_Int num_sends , HYPRE_Int num_recvs , HYPRE_Int *recv_procs , HYPRE_Int *send_procs , HYPRE_Int *recv_vec_starts , hypre_ParCSRMatrix *A ); /* par_relax.c */ HYPRE_Int hypre_BoomerAMGRelax ( hypre_ParCSRMatrix *A , hypre_ParVector *f , HYPRE_Int *cf_marker , HYPRE_Int relax_type , HYPRE_Int relax_points , HYPRE_Real relax_weight , HYPRE_Real omega , HYPRE_Real *l1_norms , hypre_ParVector *u , hypre_ParVector *Vtemp , hypre_ParVector *Ztemp ); HYPRE_Int hypre_GaussElimSetup ( hypre_ParAMGData *amg_data , HYPRE_Int level , HYPRE_Int relax_type ); HYPRE_Int hypre_GaussElimSolve ( hypre_ParAMGData *amg_data , HYPRE_Int level , HYPRE_Int relax_type ); HYPRE_Int gselim ( HYPRE_Real *A , HYPRE_Real *x , HYPRE_Int n ); /* par_relax_interface.c */ HYPRE_Int hypre_BoomerAMGRelaxIF ( hypre_ParCSRMatrix *A , hypre_ParVector *f , HYPRE_Int *cf_marker , HYPRE_Int relax_type , HYPRE_Int relax_order , HYPRE_Int cycle_type , HYPRE_Real relax_weight , HYPRE_Real omega , HYPRE_Real *l1_norms , hypre_ParVector *u , hypre_ParVector *Vtemp , hypre_ParVector *Ztemp ); /* par_relax_more.c */ HYPRE_Int hypre_ParCSRMaxEigEstimate ( hypre_ParCSRMatrix *A , HYPRE_Int scale , HYPRE_Real *max_eig ); HYPRE_Int hypre_ParCSRMaxEigEstimateCG ( hypre_ParCSRMatrix *A , HYPRE_Int scale , HYPRE_Int max_iter , HYPRE_Real *max_eig , HYPRE_Real *min_eig ); HYPRE_Int hypre_ParCSRRelax_Cheby ( hypre_ParCSRMatrix *A , hypre_ParVector *f , HYPRE_Real max_eig , HYPRE_Real min_eig , HYPRE_Real fraction , HYPRE_Int order , HYPRE_Int scale , HYPRE_Int variant , hypre_ParVector *u , hypre_ParVector *v , hypre_ParVector *r ); HYPRE_Int hypre_BoomerAMGRelax_FCFJacobi ( hypre_ParCSRMatrix *A , hypre_ParVector *f , HYPRE_Int *cf_marker , HYPRE_Real relax_weight , hypre_ParVector *u , hypre_ParVector *Vtemp ); HYPRE_Int hypre_ParCSRRelax_CG ( HYPRE_Solver solver , hypre_ParCSRMatrix *A , hypre_ParVector *f , hypre_ParVector *u , HYPRE_Int num_its ); HYPRE_Int hypre_LINPACKcgtql1 ( HYPRE_Int *n , HYPRE_Real *d , HYPRE_Real *e , HYPRE_Int *ierr ); HYPRE_Real hypre_LINPACKcgpthy ( HYPRE_Real *a , HYPRE_Real *b ); HYPRE_Int hypre_ParCSRRelax_L1_Jacobi ( hypre_ParCSRMatrix *A , hypre_ParVector *f , HYPRE_Int *cf_marker , HYPRE_Int relax_points , HYPRE_Real relax_weight , HYPRE_Real *l1_norms , hypre_ParVector *u , hypre_ParVector *Vtemp ); /* par_rotate_7pt.c */ HYPRE_ParCSRMatrix GenerateRotate7pt ( MPI_Comm comm , HYPRE_Int nx , HYPRE_Int ny , HYPRE_Int P , HYPRE_Int Q , HYPRE_Int p , HYPRE_Int q , HYPRE_Real alpha , HYPRE_Real eps ); /* par_scaled_matnorm.c */ HYPRE_Int hypre_ParCSRMatrixScaledNorm ( hypre_ParCSRMatrix *A , HYPRE_Real *scnorm ); /* par_stats.c */ HYPRE_Int hypre_BoomerAMGSetupStats ( void *amg_vdata , hypre_ParCSRMatrix *A ); HYPRE_Int hypre_BoomerAMGWriteSolverParams ( void *data ); /* par_strength.c */ HYPRE_Int hypre_BoomerAMGCreateS ( hypre_ParCSRMatrix *A , HYPRE_Real strength_threshold , HYPRE_Real max_row_sum , HYPRE_Int num_functions , HYPRE_Int *dof_func , hypre_ParCSRMatrix **S_ptr ); HYPRE_Int hypre_BoomerAMGCreateSabs ( hypre_ParCSRMatrix *A , HYPRE_Real strength_threshold , HYPRE_Real max_row_sum , HYPRE_Int num_functions , HYPRE_Int *dof_func , hypre_ParCSRMatrix **S_ptr ); HYPRE_Int hypre_BoomerAMGCreateSCommPkg ( hypre_ParCSRMatrix *A , hypre_ParCSRMatrix *S , HYPRE_Int **col_offd_S_to_A_ptr ); HYPRE_Int hypre_BoomerAMGCreate2ndS ( hypre_ParCSRMatrix *S , HYPRE_Int *CF_marker , HYPRE_Int num_paths , HYPRE_Int *coarse_row_starts , hypre_ParCSRMatrix **C_ptr ); HYPRE_Int hypre_BoomerAMGCorrectCFMarker ( HYPRE_Int *CF_marker , HYPRE_Int num_var , HYPRE_Int *new_CF_marker ); HYPRE_Int hypre_BoomerAMGCorrectCFMarker2 ( HYPRE_Int *CF_marker , HYPRE_Int num_var , HYPRE_Int *new_CF_marker ); /* partial.c */ HYPRE_Int hypre_BoomerAMGBuildPartialExtPIInterp ( hypre_ParCSRMatrix *A , HYPRE_Int *CF_marker , hypre_ParCSRMatrix *S , HYPRE_Int *num_cpts_global , HYPRE_Int *num_old_cpts_global , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int debug_flag , HYPRE_Real trunc_factor , HYPRE_Int max_elmts , HYPRE_Int *col_offd_S_to_A , hypre_ParCSRMatrix **P_ptr ); HYPRE_Int hypre_BoomerAMGBuildPartialStdInterp ( hypre_ParCSRMatrix *A , HYPRE_Int *CF_marker , hypre_ParCSRMatrix *S , HYPRE_Int *num_cpts_global , HYPRE_Int *num_old_cpts_global , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int debug_flag , HYPRE_Real trunc_factor , HYPRE_Int max_elmts , HYPRE_Int sep_weight , HYPRE_Int *col_offd_S_to_A , hypre_ParCSRMatrix **P_ptr ); HYPRE_Int hypre_BoomerAMGBuildPartialExtInterp ( hypre_ParCSRMatrix *A , HYPRE_Int *CF_marker , hypre_ParCSRMatrix *S , HYPRE_Int *num_cpts_global , HYPRE_Int *num_old_cpts_global , HYPRE_Int num_functions , HYPRE_Int *dof_func , HYPRE_Int debug_flag , HYPRE_Real trunc_factor , HYPRE_Int max_elmts , HYPRE_Int *col_offd_S_to_A , hypre_ParCSRMatrix **P_ptr ); /* par_vardifconv.c */ HYPRE_ParCSRMatrix GenerateVarDifConv ( MPI_Comm comm , HYPRE_Int nx , HYPRE_Int ny , HYPRE_Int nz , HYPRE_Int P , HYPRE_Int Q , HYPRE_Int R , HYPRE_Int p , HYPRE_Int q , HYPRE_Int r , HYPRE_Real eps , HYPRE_ParVector *rhs_ptr ); HYPRE_Real afun ( HYPRE_Real xx , HYPRE_Real yy , HYPRE_Real zz ); HYPRE_Real bfun ( HYPRE_Real xx , HYPRE_Real yy , HYPRE_Real zz ); HYPRE_Real cfun ( HYPRE_Real xx , HYPRE_Real yy , HYPRE_Real zz ); HYPRE_Real dfun ( HYPRE_Real xx , HYPRE_Real yy , HYPRE_Real zz ); HYPRE_Real efun ( HYPRE_Real xx , HYPRE_Real yy , HYPRE_Real zz ); HYPRE_Real ffun ( HYPRE_Real xx , HYPRE_Real yy , HYPRE_Real zz ); HYPRE_Real gfun ( HYPRE_Real xx , HYPRE_Real yy , HYPRE_Real zz ); HYPRE_Real rfun ( HYPRE_Real xx , HYPRE_Real yy , HYPRE_Real zz ); HYPRE_Real bndfun ( HYPRE_Real xx , HYPRE_Real yy , HYPRE_Real zz ); /* pcg_par.c */ char *hypre_ParKrylovCAlloc ( HYPRE_Int count , HYPRE_Int elt_size ); HYPRE_Int hypre_ParKrylovFree ( char *ptr ); void *hypre_ParKrylovCreateVector ( void *vvector ); void *hypre_ParKrylovCreateVectorArray ( HYPRE_Int n , void *vvector ); HYPRE_Int hypre_ParKrylovDestroyVector ( void *vvector ); void *hypre_ParKrylovMatvecCreate ( void *A , void *x ); HYPRE_Int hypre_ParKrylovMatvec ( void *matvec_data , HYPRE_Complex alpha , void *A , void *x , HYPRE_Complex beta , void *y ); HYPRE_Int hypre_ParKrylovMatvecT ( void *matvec_data , HYPRE_Complex alpha , void *A , void *x , HYPRE_Complex beta , void *y ); HYPRE_Int hypre_ParKrylovMatvecDestroy ( void *matvec_data ); HYPRE_Real hypre_ParKrylovInnerProd ( void *x , void *y ); HYPRE_Int hypre_ParKrylovCopyVector ( void *x , void *y ); HYPRE_Int hypre_ParKrylovClearVector ( void *x ); HYPRE_Int hypre_ParKrylovScaleVector ( HYPRE_Complex alpha , void *x ); HYPRE_Int hypre_ParKrylovAxpy ( HYPRE_Complex alpha , void *x , void *y ); HYPRE_Int hypre_ParKrylovCommInfo ( void *A , HYPRE_Int *my_id , HYPRE_Int *num_procs ); HYPRE_Int hypre_ParKrylovIdentitySetup ( void *vdata , void *A , void *b , void *x ); HYPRE_Int hypre_ParKrylovIdentity ( void *vdata , void *A , void *b , void *x ); #ifdef __cplusplus } #endif #endif
66,694
74.446833
566
h
AMG
AMG-master/parcsr_ls/ams.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef hypre_AMS_DATA_HEADER #define hypre_AMS_DATA_HEADER /*-------------------------------------------------------------------------- * Auxiliary space Maxwell Solver data *--------------------------------------------------------------------------*/ typedef struct { /* Space dimension (2 or 3) */ HYPRE_Int dim; /* Edge element (ND1) stiffness matrix */ hypre_ParCSRMatrix *A; /* Discrete gradient matrix (vertex-to-edge) */ hypre_ParCSRMatrix *G; /* Coarse grid matrix on the range of G^T */ hypre_ParCSRMatrix *A_G; /* AMG solver for A_G */ HYPRE_Solver B_G; /* Is the mass term coefficient zero? */ HYPRE_Int beta_is_zero; /* Nedelec nodal interpolation matrix (vertex^dim-to-edge) */ hypre_ParCSRMatrix *Pi; /* Coarse grid matrix on the range of Pi^T */ hypre_ParCSRMatrix *A_Pi; /* AMG solver for A_Pi */ HYPRE_Solver B_Pi; /* Components of the Nedelec interpolation matrix (vertex-to-edge each) */ hypre_ParCSRMatrix *Pix, *Piy, *Piz; /* Coarse grid matrices on the ranges of Pi{x,y,z}^T */ hypre_ParCSRMatrix *A_Pix, *A_Piy, *A_Piz; /* AMG solvers for A_Pi{x,y,z} */ HYPRE_Solver B_Pix, B_Piy, B_Piz; /* Does the solver own the Nedelec interpolations? */ HYPRE_Int owns_Pi; /* Does the solver own the coarse grid matrices? */ HYPRE_Int owns_A_G, owns_A_Pi; /* Coordinates of the vertices (z = 0 if dim == 2) */ hypre_ParVector *x, *y, *z; /* Representations of the constant vectors in the Nedelec basis */ hypre_ParVector *Gx, *Gy, *Gz; /* Nodes in the interior of the zero-conductivity region */ hypre_ParVector *interior_nodes; /* Discrete gradient matrix for the interior nodes only */ hypre_ParCSRMatrix *G0; /* Coarse grid matrix on the interior nodes */ hypre_ParCSRMatrix *A_G0; /* AMG solver for A_G0 */ HYPRE_Solver B_G0; /* How frequently to project the r.h.s. onto Ker(G0^T)? */ HYPRE_Int projection_frequency; /* Internal counter to use with projection_frequency in PCG */ HYPRE_Int solve_counter; /* Solver options */ HYPRE_Int maxit; HYPRE_Real tol; HYPRE_Int cycle_type; HYPRE_Int print_level; /* Smoothing options for A */ HYPRE_Int A_relax_type; HYPRE_Int A_relax_times; HYPRE_Real *A_l1_norms; HYPRE_Real A_relax_weight; HYPRE_Real A_omega; HYPRE_Real A_max_eig_est; HYPRE_Real A_min_eig_est; HYPRE_Int A_cheby_order; HYPRE_Real A_cheby_fraction; /* AMG options for B_G */ HYPRE_Int B_G_coarsen_type; HYPRE_Int B_G_agg_levels; HYPRE_Int B_G_relax_type; HYPRE_Int B_G_coarse_relax_type; HYPRE_Real B_G_theta; HYPRE_Int B_G_interp_type; HYPRE_Int B_G_Pmax; /* AMG options for B_Pi */ HYPRE_Int B_Pi_coarsen_type; HYPRE_Int B_Pi_agg_levels; HYPRE_Int B_Pi_relax_type; HYPRE_Int B_Pi_coarse_relax_type; HYPRE_Real B_Pi_theta; HYPRE_Int B_Pi_interp_type; HYPRE_Int B_Pi_Pmax; /* Temporary vectors */ hypre_ParVector *r0, *g0, *r1, *g1, *r2, *g2; /* Output log info */ HYPRE_Int num_iterations; HYPRE_Real rel_resid_norm; } hypre_AMSData; /* Space dimension */ #define hypre_AMSDataDimension(ams_data) ((ams_data)->dim) /* Edge stiffness matrix */ #define hypre_AMSDataA(ams_data) ((ams_data)->A) /* Vertex space data */ #define hypre_AMSDataDiscreteGradient(ams_data) ((ams_data)->G) #define hypre_AMSDataPoissonBeta(ams_data) ((ams_data)->A_G) #define hypre_AMSDataPoissonBetaAMG(ams_data) ((ams_data)->B_G) #define hypre_AMSDataOwnsPoissonBeta(ams_data) ((ams_data)->owns_A_G) #define hypre_AMSDataBetaIsZero(ams_data) ((ams_data)->beta_is_zero) /* Vector vertex space data */ #define hypre_AMSDataPiInterpolation(ams_data) ((ams_data)->Pi) #define hypre_AMSDataOwnsPiInterpolation(ams_data) ((ams_data)->owns_Pi) #define hypre_AMSDataPoissonAlpha(ams_data) ((ams_data)->A_Pi) #define hypre_AMSDataPoissonAlphaAMG(ams_data) ((ams_data)->B_Pi) #define hypre_AMSDataOwnsPoissonAlpha(ams_data) ((ams_data)->owns_A_Pi) /* Coordinates of the vertices */ #define hypre_AMSDataVertexCoordinateX(ams_data) ((ams_data)->x) #define hypre_AMSDataVertexCoordinateY(ams_data) ((ams_data)->y) #define hypre_AMSDataVertexCoordinateZ(ams_data) ((ams_data)->z) /* Representations of the constant vectors in the Nedelec basis */ #define hypre_AMSDataEdgeConstantX(ams_data) ((ams_data)->Gx) #define hypre_AMSDataEdgeConstantY(ams_data) ((ams_data)->Gy) #define hypre_AMSDataEdgeConstantZ(ams_data) ((ams_data)->Gz) /* Solver options */ #define hypre_AMSDataMaxIter(ams_data) ((ams_data)->maxit) #define hypre_AMSDataTol(ams_data) ((ams_data)->tol) #define hypre_AMSDataCycleType(ams_data) ((ams_data)->cycle_type) #define hypre_AMSDataPrintLevel(ams_data) ((ams_data)->print_level) /* Smoothing and AMG options */ #define hypre_AMSDataARelaxType(ams_data) ((ams_data)->A_relax_type) #define hypre_AMSDataARelaxTimes(ams_data) ((ams_data)->A_relax_times) #define hypre_AMSDataAL1Norms(ams_data) ((ams_data)->A_l1_norms) #define hypre_AMSDataARelaxWeight(ams_data) ((ams_data)->A_relax_weight) #define hypre_AMSDataAOmega(ams_data) ((ams_data)->A_omega) #define hypre_AMSDataAMaxEigEst(ams_data) ((ams_data)->A_max_eig_est) #define hypre_AMSDataAMinEigEst(ams_data) ((ams_data)->A_min_eig_est) #define hypre_AMSDataAChebyOrder(ams_data) ((ams_data)->A_cheby_order) #define hypre_AMSDataAChebyFraction(ams_data) ((ams_data)->A_cheby_fraction) #define hypre_AMSDataPoissonAlphaAMGCoarsenType(ams_data) ((ams_data)->B_Pi_coarsen_type) #define hypre_AMSDataPoissonAlphaAMGAggLevels(ams_data) ((ams_data)->B_Pi_agg_levels) #define hypre_AMSDataPoissonAlphaAMGRelaxType(ams_data) ((ams_data)->B_Pi_relax_type) #define hypre_AMSDataPoissonAlphaAMGStrengthThreshold(ams_data) ((ams_data)->B_Pi_theta) #define hypre_AMSDataPoissonBetaAMGCoarsenType(ams_data) ((ams_data)->B_G_coarsen_type) #define hypre_AMSDataPoissonBetaAMGAggLevels(ams_data) ((ams_data)->B_G_agg_levels) #define hypre_AMSDataPoissonBetaAMGRelaxType(ams_data) ((ams_data)->B_G_relax_type) #define hypre_AMSDataPoissonBetaAMGStrengthThreshold(ams_data) ((ams_data)->B_G_theta) /* Temporary vectors */ #define hypre_AMSDataTempEdgeVectorR(ams_data) ((ams_data)->r0) #define hypre_AMSDataTempEdgeVectorG(ams_data) ((ams_data)->g0) #define hypre_AMSDataTempVertexVectorR(ams_data) ((ams_data)->r1) #define hypre_AMSDataTempVertexVectorG(ams_data) ((ams_data)->g1) #define hypre_AMSDataTempVecVertexVectorR(ams_data) ((ams_data)->r2) #define hypre_AMSDataTempVecVertexVectorG(ams_data) ((ams_data)->g2) #endif
7,471
37.715026
89
h
AMG
AMG-master/parcsr_ls/aux_interp.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifdef __cplusplus extern "C" { #endif void hypre_ParCSRCommExtendA(hypre_ParCSRMatrix *A, HYPRE_Int newoff, HYPRE_Int *found, HYPRE_Int *p_num_recvs, HYPRE_Int **p_recv_procs, HYPRE_Int **p_recv_vec_starts, HYPRE_Int *p_num_sends, HYPRE_Int **p_send_procs, HYPRE_Int **p_send_map_starts, HYPRE_Int **p_send_map_elmts, HYPRE_Int **p_node_add); HYPRE_Int alt_insert_new_nodes(hypre_ParCSRCommPkg *comm_pkg, hypre_ParCSRCommPkg *extend_comm_pkg, HYPRE_Int *IN_marker, HYPRE_Int full_off_procNodes, HYPRE_Int *OUT_marker); HYPRE_Int hypre_ssort(HYPRE_Int *data, HYPRE_Int n); HYPRE_Int index_of_minimum(HYPRE_Int *data, HYPRE_Int n); void swap_int(HYPRE_Int *data, HYPRE_Int a, HYPRE_Int b); void initialize_vecs(HYPRE_Int diag_n, HYPRE_Int offd_n, HYPRE_Int *diag_ftc, HYPRE_Int *offd_ftc, HYPRE_Int *diag_pm, HYPRE_Int *offd_pm, HYPRE_Int *tmp_CF); HYPRE_Int exchange_interp_data( HYPRE_Int **CF_marker_offd, HYPRE_Int **dof_func_offd, hypre_CSRMatrix **A_ext, HYPRE_Int *full_off_procNodes, hypre_CSRMatrix **Sop, hypre_ParCSRCommPkg **extend_comm_pkg, hypre_ParCSRMatrix *A, HYPRE_Int *CF_marker, hypre_ParCSRMatrix *S, HYPRE_Int num_functions, HYPRE_Int *dof_func, HYPRE_Int skip_fine_or_same_sign); void build_interp_colmap(hypre_ParCSRMatrix *P, HYPRE_Int full_off_procNodes, HYPRE_Int *tmp_CF_marker_offd, HYPRE_Int *fine_to_coarse_offd); #ifdef __cplusplus } #endif
2,478
40.316667
141
h
AMG
AMG-master/parcsr_ls/headers.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #include <stdlib.h> #include <stdio.h> #include <math.h> #include "_hypre_parcsr_ls.h"
1,017
36.703704
81
h
AMG
AMG-master/parcsr_ls/par_amg.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef hypre_ParAMG_DATA_HEADER #define hypre_ParAMG_DATA_HEADER #define CUMNUMIT /*#include "par_csr_block_matrix.h"*/ /*-------------------------------------------------------------------------- * hypre_ParAMGData *--------------------------------------------------------------------------*/ typedef struct { /* setup params */ HYPRE_Int max_levels; HYPRE_Real strong_threshold; HYPRE_Real max_row_sum; HYPRE_Real trunc_factor; HYPRE_Real agg_trunc_factor; HYPRE_Real agg_P12_trunc_factor; HYPRE_Real jacobi_trunc_threshold; HYPRE_Real S_commpkg_switch; HYPRE_Int measure_type; HYPRE_Int setup_type; HYPRE_Int coarsen_type; HYPRE_Int P_max_elmts; HYPRE_Int interp_type; HYPRE_Int sep_weight; HYPRE_Int agg_interp_type; HYPRE_Int agg_P_max_elmts; HYPRE_Int agg_P12_max_elmts; HYPRE_Int restr_par; HYPRE_Int agg_num_levels; HYPRE_Int num_paths; HYPRE_Int post_interp_type; HYPRE_Int max_coarse_size; HYPRE_Int min_coarse_size; HYPRE_Int seq_threshold; HYPRE_Int redundant; HYPRE_Int participate; /* solve params */ HYPRE_Int max_iter; HYPRE_Int min_iter; HYPRE_Int cycle_type; HYPRE_Int *num_grid_sweeps; HYPRE_Int *grid_relax_type; HYPRE_Int **grid_relax_points; HYPRE_Int relax_order; HYPRE_Int user_coarse_relax_type; HYPRE_Int user_relax_type; HYPRE_Int user_num_sweeps; HYPRE_Real user_relax_weight; HYPRE_Real outer_wt; HYPRE_Real *relax_weight; HYPRE_Real *omega; HYPRE_Real tol; /* problem data */ hypre_ParCSRMatrix *A; HYPRE_Int num_variables; HYPRE_Int num_functions; HYPRE_Int nodal; HYPRE_Int nodal_levels; HYPRE_Int nodal_diag; HYPRE_Int num_points; HYPRE_Int *dof_func; HYPRE_Int *dof_point; HYPRE_Int *point_dof_map; /* data generated in the setup phase */ hypre_ParCSRMatrix **A_array; hypre_ParVector **F_array; hypre_ParVector **U_array; hypre_ParCSRMatrix **P_array; hypre_ParCSRMatrix **R_array; HYPRE_Int **CF_marker_array; HYPRE_Int **dof_func_array; HYPRE_Int **dof_point_array; HYPRE_Int **point_dof_map_array; HYPRE_Int num_levels; HYPRE_Real **l1_norms; HYPRE_Int block_mode; HYPRE_Real *max_eig_est; HYPRE_Real *min_eig_est; HYPRE_Int cheby_eig_est; HYPRE_Int cheby_order; HYPRE_Int cheby_variant; HYPRE_Int cheby_scale; HYPRE_Real cheby_fraction; HYPRE_Real **cheby_ds; HYPRE_Real **cheby_coefs; /* data needed for non-Galerkin option */ HYPRE_Int nongalerk_num_tol; HYPRE_Real *nongalerk_tol; HYPRE_Real nongalerkin_tol; HYPRE_Real *nongal_tol_array; /* data generated in the solve phase */ hypre_ParVector *Vtemp; hypre_Vector *Vtemp_local; HYPRE_Real *Vtemp_local_data; HYPRE_Real cycle_op_count; hypre_ParVector *Rtemp; hypre_ParVector *Ptemp; hypre_ParVector *Ztemp; /* log info */ HYPRE_Int logging; HYPRE_Int num_iterations; #ifdef CUMNUMIT HYPRE_Int cum_num_iterations; #endif HYPRE_Real cum_nnz_A_P; HYPRE_Real rel_resid_norm; hypre_ParVector *residual; /* available if logging>1 */ /* output params */ HYPRE_Int print_level; char log_file_name[256]; HYPRE_Int debug_flag; /* enable redundant coarse grid solve */ HYPRE_Solver coarse_solver; hypre_ParCSRMatrix *A_coarse; hypre_ParVector *f_coarse; hypre_ParVector *u_coarse; MPI_Comm new_comm; /* store matrix, vector and communication info for Gaussian elimination */ HYPRE_Real *A_mat; HYPRE_Real *b_vec; HYPRE_Int *comm_info; /* information for multiplication with Lambda - additive AMG */ HYPRE_Int additive; HYPRE_Int mult_additive; HYPRE_Int simple; HYPRE_Int add_last_lvl; HYPRE_Int add_P_max_elmts; HYPRE_Real add_trunc_factor; HYPRE_Int add_rlx_type; HYPRE_Real add_rlx_wt; hypre_ParCSRMatrix *Lambda; hypre_ParCSRMatrix *Atilde; hypre_ParVector *Rtilde; hypre_ParVector *Xtilde; HYPRE_Real *D_inv; /* Use 2 mat-mat-muls instead of triple product*/ HYPRE_Int rap2; HYPRE_Int keepTranspose; } hypre_ParAMGData; /*-------------------------------------------------------------------------- * Accessor functions for the hypre_AMGData structure *--------------------------------------------------------------------------*/ /* setup params */ #define hypre_ParAMGDataRestriction(amg_data) ((amg_data)->restr_par) #define hypre_ParAMGDataMaxLevels(amg_data) ((amg_data)->max_levels) #define hypre_ParAMGDataStrongThreshold(amg_data) \ ((amg_data)->strong_threshold) #define hypre_ParAMGDataMaxRowSum(amg_data) ((amg_data)->max_row_sum) #define hypre_ParAMGDataTruncFactor(amg_data) ((amg_data)->trunc_factor) #define hypre_ParAMGDataAggTruncFactor(amg_data) ((amg_data)->agg_trunc_factor) #define hypre_ParAMGDataAggP12TruncFactor(amg_data) ((amg_data)->agg_P12_trunc_factor) #define hypre_ParAMGDataJacobiTruncThreshold(amg_data) ((amg_data)->jacobi_trunc_threshold) #define hypre_ParAMGDataSCommPkgSwitch(amg_data) ((amg_data)->S_commpkg_switch) #define hypre_ParAMGDataInterpType(amg_data) ((amg_data)->interp_type) #define hypre_ParAMGDataSepWeight(amg_data) ((amg_data)->sep_weight) #define hypre_ParAMGDataAggInterpType(amg_data) ((amg_data)->agg_interp_type) #define hypre_ParAMGDataCoarsenType(amg_data) ((amg_data)->coarsen_type) #define hypre_ParAMGDataMeasureType(amg_data) ((amg_data)->measure_type) #define hypre_ParAMGDataSetupType(amg_data) ((amg_data)->setup_type) #define hypre_ParAMGDataPMaxElmts(amg_data) ((amg_data)->P_max_elmts) #define hypre_ParAMGDataAggPMaxElmts(amg_data) ((amg_data)->agg_P_max_elmts) #define hypre_ParAMGDataAggP12MaxElmts(amg_data) ((amg_data)->agg_P12_max_elmts) #define hypre_ParAMGDataNumPaths(amg_data) ((amg_data)->num_paths) #define hypre_ParAMGDataAggNumLevels(amg_data) ((amg_data)->agg_num_levels) #define hypre_ParAMGDataPostInterpType(amg_data) ((amg_data)->post_interp_type) #define hypre_ParAMGDataL1Norms(amg_data) ((amg_data)->l1_norms) #define hypre_ParAMGDataMaxCoarseSize(amg_data) ((amg_data)->max_coarse_size) #define hypre_ParAMGDataMinCoarseSize(amg_data) ((amg_data)->min_coarse_size) #define hypre_ParAMGDataSeqThreshold(amg_data) ((amg_data)->seq_threshold) /* solve params */ #define hypre_ParAMGDataMinIter(amg_data) ((amg_data)->min_iter) #define hypre_ParAMGDataMaxIter(amg_data) ((amg_data)->max_iter) #define hypre_ParAMGDataCycleType(amg_data) ((amg_data)->cycle_type) #define hypre_ParAMGDataTol(amg_data) ((amg_data)->tol) #define hypre_ParAMGDataNumGridSweeps(amg_data) ((amg_data)->num_grid_sweeps) #define hypre_ParAMGDataUserCoarseRelaxType(amg_data) ((amg_data)->user_coarse_relax_type) #define hypre_ParAMGDataUserRelaxType(amg_data) ((amg_data)->user_relax_type) #define hypre_ParAMGDataUserRelaxWeight(amg_data) ((amg_data)->user_relax_weight) #define hypre_ParAMGDataUserNumSweeps(amg_data) ((amg_data)->user_num_sweeps) #define hypre_ParAMGDataGridRelaxType(amg_data) ((amg_data)->grid_relax_type) #define hypre_ParAMGDataGridRelaxPoints(amg_data) \ ((amg_data)->grid_relax_points) #define hypre_ParAMGDataRelaxOrder(amg_data) ((amg_data)->relax_order) #define hypre_ParAMGDataRelaxWeight(amg_data) ((amg_data)->relax_weight) #define hypre_ParAMGDataOmega(amg_data) ((amg_data)->omega) #define hypre_ParAMGDataOuterWt(amg_data) ((amg_data)->outer_wt) /* problem data parameters */ #define hypre_ParAMGDataNumVariables(amg_data) ((amg_data)->num_variables) #define hypre_ParAMGDataNumFunctions(amg_data) ((amg_data)->num_functions) #define hypre_ParAMGDataNodal(amg_data) ((amg_data)->nodal) #define hypre_ParAMGDataNodalLevels(amg_data) ((amg_data)->nodal_levels) #define hypre_ParAMGDataNodalDiag(amg_data) ((amg_data)->nodal_diag) #define hypre_ParAMGDataNumPoints(amg_data) ((amg_data)->num_points) #define hypre_ParAMGDataDofFunc(amg_data) ((amg_data)->dof_func) #define hypre_ParAMGDataDofPoint(amg_data) ((amg_data)->dof_point) #define hypre_ParAMGDataPointDofMap(amg_data) ((amg_data)->point_dof_map) /* data generated by the setup phase */ #define hypre_ParAMGDataCFMarkerArray(amg_data) ((amg_data)-> CF_marker_array) #define hypre_ParAMGDataAArray(amg_data) ((amg_data)->A_array) #define hypre_ParAMGDataFArray(amg_data) ((amg_data)->F_array) #define hypre_ParAMGDataUArray(amg_data) ((amg_data)->U_array) #define hypre_ParAMGDataPArray(amg_data) ((amg_data)->P_array) #define hypre_ParAMGDataRArray(amg_data) ((amg_data)->R_array) #define hypre_ParAMGDataDofFuncArray(amg_data) ((amg_data)->dof_func_array) #define hypre_ParAMGDataDofPointArray(amg_data) ((amg_data)->dof_point_array) #define hypre_ParAMGDataPointDofMapArray(amg_data) \ ((amg_data)->point_dof_map_array) #define hypre_ParAMGDataNumLevels(amg_data) ((amg_data)->num_levels) #define hypre_ParAMGDataMaxEigEst(amg_data) ((amg_data)->max_eig_est) #define hypre_ParAMGDataMinEigEst(amg_data) ((amg_data)->min_eig_est) #define hypre_ParAMGDataChebyEigEst(amg_data) ((amg_data)->cheby_eig_est) #define hypre_ParAMGDataChebyVariant(amg_data) ((amg_data)->cheby_variant) #define hypre_ParAMGDataChebyScale(amg_data) ((amg_data)->cheby_scale) #define hypre_ParAMGDataChebyOrder(amg_data) ((amg_data)->cheby_order) #define hypre_ParAMGDataChebyFraction(amg_data) ((amg_data)->cheby_fraction) #define hypre_ParAMGDataChebyDS(amg_data) ((amg_data)->cheby_ds) #define hypre_ParAMGDataChebyCoefs(amg_data) ((amg_data)->cheby_coefs) #define hypre_ParAMGDataBlockMode(amg_data) ((amg_data)->block_mode) /* data generated in the solve phase */ #define hypre_ParAMGDataVtemp(amg_data) ((amg_data)->Vtemp) #define hypre_ParAMGDataVtempLocal(amg_data) ((amg_data)->Vtemp_local) #define hypre_ParAMGDataVtemplocalData(amg_data) ((amg_data)->Vtemp_local_data) #define hypre_ParAMGDataCycleOpCount(amg_data) ((amg_data)->cycle_op_count) #define hypre_ParAMGDataRtemp(amg_data) ((amg_data)->Rtemp) #define hypre_ParAMGDataPtemp(amg_data) ((amg_data)->Ptemp) #define hypre_ParAMGDataZtemp(amg_data) ((amg_data)->Ztemp) /* fields used by GSMG */ #define hypre_ParAMGDataGSMG(amg_data) ((amg_data)->gsmg) #define hypre_ParAMGDataNumSamples(amg_data) ((amg_data)->num_samples) /* log info data */ #define hypre_ParAMGDataLogging(amg_data) ((amg_data)->logging) #define hypre_ParAMGDataNumIterations(amg_data) ((amg_data)->num_iterations) #ifdef CUMNUMIT #define hypre_ParAMGDataCumNumIterations(amg_data) ((amg_data)->cum_num_iterations) #endif #define hypre_ParAMGDataRelativeResidualNorm(amg_data) ((amg_data)->rel_resid_norm) #define hypre_ParAMGDataResidual(amg_data) ((amg_data)->residual) /* output parameters */ #define hypre_ParAMGDataPrintLevel(amg_data) ((amg_data)->print_level) #define hypre_ParAMGDataLogFileName(amg_data) ((amg_data)->log_file_name) #define hypre_ParAMGDataDebugFlag(amg_data) ((amg_data)->debug_flag) #define hypre_ParAMGDataCumNnzAP(amg_data) ((amg_data)->cum_nnz_AP) #define hypre_ParAMGDataCoarseSolver(amg_data) ((amg_data)->coarse_solver) #define hypre_ParAMGDataACoarse(amg_data) ((amg_data)->A_coarse) #define hypre_ParAMGDataFCoarse(amg_data) ((amg_data)->f_coarse) #define hypre_ParAMGDataUCoarse(amg_data) ((amg_data)->u_coarse) #define hypre_ParAMGDataNewComm(amg_data) ((amg_data)->new_comm) #define hypre_ParAMGDataRedundant(amg_data) ((amg_data)->redundant) #define hypre_ParAMGDataParticipate(amg_data) ((amg_data)->participate) #define hypre_ParAMGDataAMat(amg_data) ((amg_data)->A_mat) #define hypre_ParAMGDataBVec(amg_data) ((amg_data)->b_vec) #define hypre_ParAMGDataCommInfo(amg_data) ((amg_data)->comm_info) /* additive AMG parameters */ #define hypre_ParAMGDataAdditive(amg_data) ((amg_data)->additive) #define hypre_ParAMGDataMultAdditive(amg_data) ((amg_data)->mult_additive) #define hypre_ParAMGDataSimple(amg_data) ((amg_data)->simple) #define hypre_ParAMGDataAddLastLvl(amg_data) ((amg_data)->add_last_lvl) #define hypre_ParAMGDataMultAddPMaxElmts(amg_data) ((amg_data)->add_P_max_elmts) #define hypre_ParAMGDataMultAddTruncFactor(amg_data) ((amg_data)->add_trunc_factor) #define hypre_ParAMGDataAddRelaxType(amg_data) ((amg_data)->add_rlx_type) #define hypre_ParAMGDataAddRelaxWt(amg_data) ((amg_data)->add_rlx_wt) #define hypre_ParAMGDataLambda(amg_data) ((amg_data)->Lambda) #define hypre_ParAMGDataAtilde(amg_data) ((amg_data)->Atilde) #define hypre_ParAMGDataRtilde(amg_data) ((amg_data)->Rtilde) #define hypre_ParAMGDataXtilde(amg_data) ((amg_data)->Xtilde) #define hypre_ParAMGDataDinv(amg_data) ((amg_data)->D_inv) /* non-Galerkin parameters */ #define hypre_ParAMGDataNonGalerkNumTol(amg_data) ((amg_data)->nongalerk_num_tol) #define hypre_ParAMGDataNonGalerkTol(amg_data) ((amg_data)->nongalerk_tol) #define hypre_ParAMGDataNonGalerkinTol(amg_data) ((amg_data)->nongalerkin_tol) #define hypre_ParAMGDataNonGalTolArray(amg_data) ((amg_data)->nongal_tol_array) #define hypre_ParAMGDataRAP2(amg_data) ((amg_data)->rap2) #define hypre_ParAMGDataKeepTranspose(amg_data) ((amg_data)->keepTranspose) #endif
14,437
41.589971
91
h
AMG
AMG-master/parcsr_mv/HYPRE_parcsr_mv.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header file for HYPRE_parcsr_mv library * *****************************************************************************/ #ifndef HYPRE_PARCSR_MV_HEADER #define HYPRE_PARCSR_MV_HEADER #include "HYPRE_utilities.h" #include "HYPRE_seq_mv.h" #ifdef __cplusplus extern "C" { #endif /*-------------------------------------------------------------------------- * Structures *--------------------------------------------------------------------------*/ struct hypre_ParCSRMatrix_struct; typedef struct hypre_ParCSRMatrix_struct *HYPRE_ParCSRMatrix; struct hypre_ParVector_struct; typedef struct hypre_ParVector_struct *HYPRE_ParVector; /*-------------------------------------------------------------------------- * Prototypes *--------------------------------------------------------------------------*/ /* HYPRE_parcsr_matrix.c */ HYPRE_Int HYPRE_ParCSRMatrixCreate( MPI_Comm comm , HYPRE_Int global_num_rows , HYPRE_Int global_num_cols , HYPRE_Int *row_starts , HYPRE_Int *col_starts , HYPRE_Int num_cols_offd , HYPRE_Int num_nonzeros_diag , HYPRE_Int num_nonzeros_offd , HYPRE_ParCSRMatrix *matrix ); HYPRE_Int HYPRE_ParCSRMatrixDestroy( HYPRE_ParCSRMatrix matrix ); HYPRE_Int HYPRE_ParCSRMatrixInitialize( HYPRE_ParCSRMatrix matrix ); HYPRE_Int HYPRE_ParCSRMatrixRead( MPI_Comm comm , const char *file_name , HYPRE_ParCSRMatrix *matrix ); HYPRE_Int HYPRE_ParCSRMatrixPrint( HYPRE_ParCSRMatrix matrix , const char *file_name ); HYPRE_Int HYPRE_ParCSRMatrixGetComm( HYPRE_ParCSRMatrix matrix , MPI_Comm *comm ); HYPRE_Int HYPRE_ParCSRMatrixGetDims( HYPRE_ParCSRMatrix matrix , HYPRE_Int *M , HYPRE_Int *N ); HYPRE_Int HYPRE_ParCSRMatrixGetRowPartitioning( HYPRE_ParCSRMatrix matrix , HYPRE_Int **row_partitioning_ptr ); HYPRE_Int HYPRE_ParCSRMatrixGetColPartitioning( HYPRE_ParCSRMatrix matrix , HYPRE_Int **col_partitioning_ptr ); HYPRE_Int HYPRE_ParCSRMatrixGetLocalRange( HYPRE_ParCSRMatrix matrix , HYPRE_Int *row_start , HYPRE_Int *row_end , HYPRE_Int *col_start , HYPRE_Int *col_end ); HYPRE_Int HYPRE_ParCSRMatrixGetRow( HYPRE_ParCSRMatrix matrix , HYPRE_Int row , HYPRE_Int *size , HYPRE_Int **col_ind , HYPRE_Complex **values ); HYPRE_Int HYPRE_ParCSRMatrixRestoreRow( HYPRE_ParCSRMatrix matrix , HYPRE_Int row , HYPRE_Int *size , HYPRE_Int **col_ind , HYPRE_Complex **values ); HYPRE_Int HYPRE_CSRMatrixToParCSRMatrix( MPI_Comm comm , HYPRE_CSRMatrix A_CSR , HYPRE_Int *row_partitioning , HYPRE_Int *col_partitioning , HYPRE_ParCSRMatrix *matrix ); HYPRE_Int HYPRE_ParCSRMatrixMatvec( HYPRE_Complex alpha , HYPRE_ParCSRMatrix A , HYPRE_ParVector x , HYPRE_Complex beta , HYPRE_ParVector y ); HYPRE_Int HYPRE_ParCSRMatrixMatvecT( HYPRE_Complex alpha , HYPRE_ParCSRMatrix A , HYPRE_ParVector x , HYPRE_Complex beta , HYPRE_ParVector y ); /* HYPRE_parcsr_vector.c */ HYPRE_Int HYPRE_ParVectorCreate( MPI_Comm comm , HYPRE_Int global_size , HYPRE_Int *partitioning , HYPRE_ParVector *vector ); HYPRE_Int HYPRE_ParVectorDestroy( HYPRE_ParVector vector ); HYPRE_Int HYPRE_ParVectorInitialize( HYPRE_ParVector vector ); HYPRE_Int HYPRE_ParVectorRead( MPI_Comm comm , const char *file_name , HYPRE_ParVector *vector ); HYPRE_Int HYPRE_ParVectorPrint( HYPRE_ParVector vector , const char *file_name ); HYPRE_Int HYPRE_ParVectorSetConstantValues( HYPRE_ParVector vector , HYPRE_Complex value ); HYPRE_Int HYPRE_ParVectorSetRandomValues( HYPRE_ParVector vector , HYPRE_Int seed ); HYPRE_Int HYPRE_ParVectorCopy( HYPRE_ParVector x , HYPRE_ParVector y ); HYPRE_Int HYPRE_ParVectorScale( HYPRE_Complex value , HYPRE_ParVector x ); HYPRE_Int HYPRE_ParVectorInnerProd( HYPRE_ParVector x , HYPRE_ParVector y , HYPRE_Real *prod ); HYPRE_Int HYPRE_VectorToParVector( MPI_Comm comm , HYPRE_Vector b , HYPRE_Int *partitioning , HYPRE_ParVector *vector ); #ifdef __cplusplus } #endif #endif
4,801
56.855422
271
h
AMG
AMG-master/parcsr_mv/_hypre_parcsr_mv.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #include "HYPRE_parcsr_mv.h" #ifndef hypre_PARCSR_MV_HEADER #define hypre_PARCSR_MV_HEADER #include "_hypre_utilities.h" #include "seq_mv.h" #ifdef __cplusplus extern "C" { #endif #ifndef HYPRE_PAR_CSR_COMMUNICATION_HEADER #define HYPRE_PAR_CSR_COMMUNICATION_HEADER /*-------------------------------------------------------------------------- * hypre_ParCSRCommPkg: * Structure containing information for doing communications *--------------------------------------------------------------------------*/ /*#define HYPRE_USING_PERSISTENT_COMM*/ // JSP: can be defined by configure #ifdef HYPRE_USING_PERSISTENT_COMM typedef enum CommPkgJobType { HYPRE_COMM_PKG_JOB_COMPLEX = 0, HYPRE_COMM_PKG_JOB_COMPLEX_TRANSPOSE, HYPRE_COMM_PKG_JOB_INT, HYPRE_COMM_PKG_JOB_INT_TRANSPOSE, NUM_OF_COMM_PKG_JOB_TYPE, } CommPkgJobType; typedef struct { void *send_data; void *recv_data; HYPRE_Int num_requests; hypre_MPI_Request *requests; HYPRE_Int own_send_data, own_recv_data; } hypre_ParCSRPersistentCommHandle; #endif typedef struct { MPI_Comm comm; HYPRE_Int num_sends; HYPRE_Int *send_procs; HYPRE_Int *send_map_starts; HYPRE_Int *send_map_elmts; HYPRE_Int num_recvs; HYPRE_Int *recv_procs; HYPRE_Int *recv_vec_starts; /* remote communication information */ hypre_MPI_Datatype *send_mpi_types; hypre_MPI_Datatype *recv_mpi_types; #ifdef HYPRE_USING_PERSISTENT_COMM hypre_ParCSRPersistentCommHandle *persistent_comm_handles[NUM_OF_COMM_PKG_JOB_TYPE]; #endif } hypre_ParCSRCommPkg; /*-------------------------------------------------------------------------- * hypre_ParCSRCommHandle: *--------------------------------------------------------------------------*/ typedef struct { hypre_ParCSRCommPkg *comm_pkg; void *send_data; void *recv_data; HYPRE_Int num_requests; hypre_MPI_Request *requests; } hypre_ParCSRCommHandle; /*-------------------------------------------------------------------------- * Accessor macros: hypre_ParCSRCommPkg *--------------------------------------------------------------------------*/ #define hypre_ParCSRCommPkgComm(comm_pkg) (comm_pkg -> comm) #define hypre_ParCSRCommPkgNumSends(comm_pkg) (comm_pkg -> num_sends) #define hypre_ParCSRCommPkgSendProcs(comm_pkg) (comm_pkg -> send_procs) #define hypre_ParCSRCommPkgSendProc(comm_pkg, i) (comm_pkg -> send_procs[i]) #define hypre_ParCSRCommPkgSendMapStarts(comm_pkg) (comm_pkg -> send_map_starts) #define hypre_ParCSRCommPkgSendMapStart(comm_pkg,i)(comm_pkg -> send_map_starts[i]) #define hypre_ParCSRCommPkgSendMapElmts(comm_pkg) (comm_pkg -> send_map_elmts) #define hypre_ParCSRCommPkgSendMapElmt(comm_pkg,i) (comm_pkg -> send_map_elmts[i]) #define hypre_ParCSRCommPkgNumRecvs(comm_pkg) (comm_pkg -> num_recvs) #define hypre_ParCSRCommPkgRecvProcs(comm_pkg) (comm_pkg -> recv_procs) #define hypre_ParCSRCommPkgRecvProc(comm_pkg, i) (comm_pkg -> recv_procs[i]) #define hypre_ParCSRCommPkgRecvVecStarts(comm_pkg) (comm_pkg -> recv_vec_starts) #define hypre_ParCSRCommPkgRecvVecStart(comm_pkg,i)(comm_pkg -> recv_vec_starts[i]) #define hypre_ParCSRCommPkgSendMPITypes(comm_pkg) (comm_pkg -> send_mpi_types) #define hypre_ParCSRCommPkgSendMPIType(comm_pkg,i) (comm_pkg -> send_mpi_types[i]) #define hypre_ParCSRCommPkgRecvMPITypes(comm_pkg) (comm_pkg -> recv_mpi_types) #define hypre_ParCSRCommPkgRecvMPIType(comm_pkg,i) (comm_pkg -> recv_mpi_types[i]) /*-------------------------------------------------------------------------- * Accessor macros: hypre_ParCSRCommHandle *--------------------------------------------------------------------------*/ #define hypre_ParCSRCommHandleCommPkg(comm_handle) (comm_handle -> comm_pkg) #define hypre_ParCSRCommHandleSendData(comm_handle) (comm_handle -> send_data) #define hypre_ParCSRCommHandleRecvData(comm_handle) (comm_handle -> recv_data) #define hypre_ParCSRCommHandleNumRequests(comm_handle) (comm_handle -> num_requests) #define hypre_ParCSRCommHandleRequests(comm_handle) (comm_handle -> requests) #define hypre_ParCSRCommHandleRequest(comm_handle, i) (comm_handle -> requests[i]) #endif /* HYPRE_PAR_CSR_COMMUNICATION_HEADER */ #ifndef hypre_PARCSR_ASSUMED_PART #define hypre_PARCSR_ASSUMED_PART typedef struct { HYPRE_Int length; HYPRE_Int row_start; HYPRE_Int row_end; HYPRE_Int storage_length; HYPRE_Int *proc_list; HYPRE_Int *row_start_list; HYPRE_Int *row_end_list; HYPRE_Int *sort_index; } hypre_IJAssumedPart; #endif /* hypre_PARCSR_ASSUMED_PART */ #ifndef hypre_NEW_COMMPKG #define hypre_NEW_COMMPKG typedef struct { HYPRE_Int length; HYPRE_Int storage_length; HYPRE_Int *id; HYPRE_Int *vec_starts; HYPRE_Int element_storage_length; HYPRE_Int *elements; HYPRE_Real *d_elements; /* Is this used anywhere? */ void *v_elements; } hypre_ProcListElements; #endif /* hypre_NEW_COMMPKG */ /****************************************************************************** * * Header info for Parallel Vector data structure * *****************************************************************************/ #ifndef hypre_PAR_VECTOR_HEADER #define hypre_PAR_VECTOR_HEADER /*-------------------------------------------------------------------------- * hypre_ParVector *--------------------------------------------------------------------------*/ #ifndef HYPRE_PAR_VECTOR_STRUCT #define HYPRE_PAR_VECTOR_STRUCT #endif typedef struct hypre_ParVector_struct { MPI_Comm comm; HYPRE_Int global_size; HYPRE_Int first_index; HYPRE_Int last_index; HYPRE_Int *partitioning; HYPRE_Int actual_local_size; /* stores actual length of data in local vector to allow memory manipulations for temporary vectors*/ hypre_Vector *local_vector; /* Does the Vector create/destroy `data'? */ HYPRE_Int owns_data; HYPRE_Int owns_partitioning; hypre_IJAssumedPart *assumed_partition; /* only populated if no_global_partition option is used (compile-time option) AND this partition needed (for setting off-proc elements, for example)*/ } hypre_ParVector; /*-------------------------------------------------------------------------- * Accessor functions for the Vector structure *--------------------------------------------------------------------------*/ #define hypre_ParVectorComm(vector) ((vector) -> comm) #define hypre_ParVectorGlobalSize(vector) ((vector) -> global_size) #define hypre_ParVectorFirstIndex(vector) ((vector) -> first_index) #define hypre_ParVectorLastIndex(vector) ((vector) -> last_index) #define hypre_ParVectorPartitioning(vector) ((vector) -> partitioning) #define hypre_ParVectorActualLocalSize(vector) ((vector) -> actual_local_size) #define hypre_ParVectorLocalVector(vector) ((vector) -> local_vector) #define hypre_ParVectorOwnsData(vector) ((vector) -> owns_data) #define hypre_ParVectorOwnsPartitioning(vector) ((vector) -> owns_partitioning) #define hypre_ParVectorNumVectors(vector)\ (hypre_VectorNumVectors( hypre_ParVectorLocalVector(vector) )) #define hypre_ParVectorAssumedPartition(vector) ((vector) -> assumed_partition) #endif /****************************************************************************** * * Header info for Parallel CSR Matrix data structures * * Note: this matrix currently uses 0-based indexing. * *****************************************************************************/ #ifndef hypre_PAR_CSR_MATRIX_HEADER #define hypre_PAR_CSR_MATRIX_HEADER /*-------------------------------------------------------------------------- * Parallel CSR Matrix *--------------------------------------------------------------------------*/ #ifndef HYPRE_PAR_CSR_MATRIX_STRUCT #define HYPRE_PAR_CSR_MATRIX_STRUCT #endif typedef struct hypre_ParCSRMatrix_struct { MPI_Comm comm; HYPRE_Int global_num_rows; HYPRE_Int global_num_cols; HYPRE_Int first_row_index; HYPRE_Int first_col_diag; /* need to know entire local range in case row_starts and col_starts are null (i.e., bgl) AHB 6/05*/ HYPRE_Int last_row_index; HYPRE_Int last_col_diag; hypre_CSRMatrix *diag; hypre_CSRMatrix *offd; hypre_CSRMatrix *diagT, *offdT; /* JSP: transposed matrices are created lazily and optional */ HYPRE_Int *col_map_offd; /* maps columns of offd to global columns */ HYPRE_Int *row_starts; /* array of length num_procs+1, row_starts[i] contains the global number of the first row on proc i, first_row_index = row_starts[my_id], row_starts[num_procs] = global_num_rows */ HYPRE_Int *col_starts; /* array of length num_procs+1, col_starts[i] contains the global number of the first column of diag on proc i, first_col_diag = col_starts[my_id], col_starts[num_procs] = global_num_cols */ hypre_ParCSRCommPkg *comm_pkg; hypre_ParCSRCommPkg *comm_pkgT; /* Does the ParCSRMatrix create/destroy `diag', `offd', `col_map_offd'? */ HYPRE_Int owns_data; /* Does the ParCSRMatrix create/destroy `row_starts', `col_starts'? */ HYPRE_Int owns_row_starts; HYPRE_Int owns_col_starts; HYPRE_Int num_nonzeros; HYPRE_Real d_num_nonzeros; /* Buffers used by GetRow to hold row currently being accessed. AJC, 4/99 */ HYPRE_Int *rowindices; HYPRE_Complex *rowvalues; HYPRE_Int getrowactive; hypre_IJAssumedPart *assumed_partition; /* only populated if no_global_partition option is used (compile-time option)*/ } hypre_ParCSRMatrix; /*-------------------------------------------------------------------------- * Accessor functions for the Parallel CSR Matrix structure *--------------------------------------------------------------------------*/ #define hypre_ParCSRMatrixComm(matrix) ((matrix) -> comm) #define hypre_ParCSRMatrixGlobalNumRows(matrix) ((matrix) -> global_num_rows) #define hypre_ParCSRMatrixGlobalNumCols(matrix) ((matrix) -> global_num_cols) #define hypre_ParCSRMatrixFirstRowIndex(matrix) ((matrix) -> first_row_index) #define hypre_ParCSRMatrixFirstColDiag(matrix) ((matrix) -> first_col_diag) #define hypre_ParCSRMatrixLastRowIndex(matrix) ((matrix) -> last_row_index) #define hypre_ParCSRMatrixLastColDiag(matrix) ((matrix) -> last_col_diag) #define hypre_ParCSRMatrixDiag(matrix) ((matrix) -> diag) #define hypre_ParCSRMatrixOffd(matrix) ((matrix) -> offd) #define hypre_ParCSRMatrixDiagT(matrix) ((matrix) -> diagT) #define hypre_ParCSRMatrixOffdT(matrix) ((matrix) -> offdT) #define hypre_ParCSRMatrixColMapOffd(matrix) ((matrix) -> col_map_offd) #define hypre_ParCSRMatrixRowStarts(matrix) ((matrix) -> row_starts) #define hypre_ParCSRMatrixColStarts(matrix) ((matrix) -> col_starts) #define hypre_ParCSRMatrixCommPkg(matrix) ((matrix) -> comm_pkg) #define hypre_ParCSRMatrixCommPkgT(matrix) ((matrix) -> comm_pkgT) #define hypre_ParCSRMatrixOwnsData(matrix) ((matrix) -> owns_data) #define hypre_ParCSRMatrixOwnsRowStarts(matrix) ((matrix) -> owns_row_starts) #define hypre_ParCSRMatrixOwnsColStarts(matrix) ((matrix) -> owns_col_starts) #define hypre_ParCSRMatrixNumRows(matrix) \ hypre_CSRMatrixNumRows(hypre_ParCSRMatrixDiag(matrix)) #define hypre_ParCSRMatrixNumCols(matrix) \ hypre_CSRMatrixNumCols(hypre_ParCSRMatrixDiag(matrix)) #define hypre_ParCSRMatrixNumNonzeros(matrix) ((matrix) -> num_nonzeros) #define hypre_ParCSRMatrixDNumNonzeros(matrix) ((matrix) -> d_num_nonzeros) #define hypre_ParCSRMatrixRowindices(matrix) ((matrix) -> rowindices) #define hypre_ParCSRMatrixRowvalues(matrix) ((matrix) -> rowvalues) #define hypre_ParCSRMatrixGetrowactive(matrix) ((matrix) -> getrowactive) #define hypre_ParCSRMatrixAssumedPartition(matrix) ((matrix) -> assumed_partition) #endif /* HYPRE_parcsr_matrix.c */ HYPRE_Int HYPRE_ParCSRMatrixCreate ( MPI_Comm comm , HYPRE_Int global_num_rows , HYPRE_Int global_num_cols , HYPRE_Int *row_starts , HYPRE_Int *col_starts , HYPRE_Int num_cols_offd , HYPRE_Int num_nonzeros_diag , HYPRE_Int num_nonzeros_offd , HYPRE_ParCSRMatrix *matrix ); HYPRE_Int HYPRE_ParCSRMatrixDestroy ( HYPRE_ParCSRMatrix matrix ); HYPRE_Int HYPRE_ParCSRMatrixInitialize ( HYPRE_ParCSRMatrix matrix ); HYPRE_Int HYPRE_ParCSRMatrixRead ( MPI_Comm comm , const char *file_name , HYPRE_ParCSRMatrix *matrix ); HYPRE_Int HYPRE_ParCSRMatrixPrint ( HYPRE_ParCSRMatrix matrix , const char *file_name ); HYPRE_Int HYPRE_ParCSRMatrixGetComm ( HYPRE_ParCSRMatrix matrix , MPI_Comm *comm ); HYPRE_Int HYPRE_ParCSRMatrixGetDims ( HYPRE_ParCSRMatrix matrix , HYPRE_Int *M , HYPRE_Int *N ); HYPRE_Int HYPRE_ParCSRMatrixGetRowPartitioning ( HYPRE_ParCSRMatrix matrix , HYPRE_Int **row_partitioning_ptr ); HYPRE_Int HYPRE_ParCSRMatrixGetColPartitioning ( HYPRE_ParCSRMatrix matrix , HYPRE_Int **col_partitioning_ptr ); HYPRE_Int HYPRE_ParCSRMatrixGetLocalRange ( HYPRE_ParCSRMatrix matrix , HYPRE_Int *row_start , HYPRE_Int *row_end , HYPRE_Int *col_start , HYPRE_Int *col_end ); HYPRE_Int HYPRE_ParCSRMatrixGetRow ( HYPRE_ParCSRMatrix matrix , HYPRE_Int row , HYPRE_Int *size , HYPRE_Int **col_ind , HYPRE_Complex **values ); HYPRE_Int HYPRE_ParCSRMatrixRestoreRow ( HYPRE_ParCSRMatrix matrix , HYPRE_Int row , HYPRE_Int *size , HYPRE_Int **col_ind , HYPRE_Complex **values ); HYPRE_Int HYPRE_CSRMatrixToParCSRMatrix ( MPI_Comm comm , HYPRE_CSRMatrix A_CSR , HYPRE_Int *row_partitioning , HYPRE_Int *col_partitioning , HYPRE_ParCSRMatrix *matrix ); HYPRE_Int HYPRE_CSRMatrixToParCSRMatrix_WithNewPartitioning ( MPI_Comm comm , HYPRE_CSRMatrix A_CSR , HYPRE_ParCSRMatrix *matrix ); HYPRE_Int HYPRE_ParCSRMatrixMatvec ( HYPRE_Complex alpha , HYPRE_ParCSRMatrix A , HYPRE_ParVector x , HYPRE_Complex beta , HYPRE_ParVector y ); HYPRE_Int HYPRE_ParCSRMatrixMatvecT ( HYPRE_Complex alpha , HYPRE_ParCSRMatrix A , HYPRE_ParVector x , HYPRE_Complex beta , HYPRE_ParVector y ); /* HYPRE_parcsr_vector.c */ HYPRE_Int HYPRE_ParVectorCreate ( MPI_Comm comm , HYPRE_Int global_size , HYPRE_Int *partitioning , HYPRE_ParVector *vector ); HYPRE_Int HYPRE_ParMultiVectorCreate ( MPI_Comm comm , HYPRE_Int global_size , HYPRE_Int *partitioning , HYPRE_Int number_vectors , HYPRE_ParVector *vector ); HYPRE_Int HYPRE_ParVectorDestroy ( HYPRE_ParVector vector ); HYPRE_Int HYPRE_ParVectorInitialize ( HYPRE_ParVector vector ); HYPRE_Int HYPRE_ParVectorRead ( MPI_Comm comm , const char *file_name , HYPRE_ParVector *vector ); HYPRE_Int HYPRE_ParVectorPrint ( HYPRE_ParVector vector , const char *file_name ); HYPRE_Int HYPRE_ParVectorSetConstantValues ( HYPRE_ParVector vector , HYPRE_Complex value ); HYPRE_Int HYPRE_ParVectorSetRandomValues ( HYPRE_ParVector vector , HYPRE_Int seed ); HYPRE_Int HYPRE_ParVectorCopy ( HYPRE_ParVector x , HYPRE_ParVector y ); HYPRE_ParVector HYPRE_ParVectorCloneShallow ( HYPRE_ParVector x ); HYPRE_Int HYPRE_ParVectorScale ( HYPRE_Complex value , HYPRE_ParVector x ); HYPRE_Int HYPRE_ParVectorAxpy ( HYPRE_Complex alpha , HYPRE_ParVector x , HYPRE_ParVector y ); HYPRE_Int HYPRE_ParVectorInnerProd ( HYPRE_ParVector x , HYPRE_ParVector y , HYPRE_Real *prod ); HYPRE_Int HYPRE_VectorToParVector ( MPI_Comm comm , HYPRE_Vector b , HYPRE_Int *partitioning , HYPRE_ParVector *vector ); /* new_commpkg.c */ HYPRE_Int hypre_PrintCommpkg ( hypre_ParCSRMatrix *A , const char *file_name ); HYPRE_Int hypre_NewCommPkgCreate_core ( MPI_Comm comm , HYPRE_Int *col_map_off_d , HYPRE_Int first_col_diag , HYPRE_Int col_start , HYPRE_Int col_end , HYPRE_Int num_cols_off_d , HYPRE_Int global_num_cols , HYPRE_Int *p_num_recvs , HYPRE_Int **p_recv_procs , HYPRE_Int **p_recv_vec_starts , HYPRE_Int *p_num_sends , HYPRE_Int **p_send_procs , HYPRE_Int **p_send_map_starts , HYPRE_Int **p_send_map_elements , hypre_IJAssumedPart *apart ); HYPRE_Int hypre_NewCommPkgCreate ( hypre_ParCSRMatrix *parcsr_A ); HYPRE_Int hypre_NewCommPkgDestroy ( hypre_ParCSRMatrix *parcsr_A ); HYPRE_Int hypre_RangeFillResponseIJDetermineRecvProcs ( void *p_recv_contact_buf , HYPRE_Int contact_size , HYPRE_Int contact_proc , void *ro , MPI_Comm comm , void **p_send_response_buf , HYPRE_Int *response_message_size ); HYPRE_Int hypre_FillResponseIJDetermineSendProcs ( void *p_recv_contact_buf , HYPRE_Int contact_size , HYPRE_Int contact_proc , void *ro , MPI_Comm comm , void **p_send_response_buf , HYPRE_Int *response_message_size ); /* par_csr_assumed_part.c */ HYPRE_Int hypre_LocateAssummedPartition ( MPI_Comm comm , HYPRE_Int row_start , HYPRE_Int row_end , HYPRE_Int global_first_row , HYPRE_Int global_num_rows , hypre_IJAssumedPart *part , HYPRE_Int myid ); HYPRE_Int hypre_ParCSRMatrixCreateAssumedPartition ( hypre_ParCSRMatrix *matrix ); HYPRE_Int hypre_AssumedPartitionDestroy ( hypre_IJAssumedPart *apart ); HYPRE_Int hypre_GetAssumedPartitionProcFromRow ( MPI_Comm comm , HYPRE_Int row , HYPRE_Int global_first_row , HYPRE_Int global_num_rows , HYPRE_Int *proc_id ); HYPRE_Int hypre_GetAssumedPartitionRowRange ( MPI_Comm comm , HYPRE_Int proc_id , HYPRE_Int global_first_row , HYPRE_Int global_num_rows , HYPRE_Int *row_start , HYPRE_Int *row_end ); HYPRE_Int hypre_ParVectorCreateAssumedPartition ( hypre_ParVector *vector ); /* par_csr_communication.c */ hypre_ParCSRCommHandle *hypre_ParCSRCommHandleCreate ( HYPRE_Int job , hypre_ParCSRCommPkg *comm_pkg , void *send_data , void *recv_data ); HYPRE_Int hypre_ParCSRCommHandleDestroy ( hypre_ParCSRCommHandle *comm_handle ); void hypre_MatvecCommPkgCreate_core ( MPI_Comm comm , HYPRE_Int *col_map_offd , HYPRE_Int first_col_diag , HYPRE_Int *col_starts , HYPRE_Int num_cols_diag , HYPRE_Int num_cols_offd , HYPRE_Int firstColDiag , HYPRE_Int *colMapOffd , HYPRE_Int data , HYPRE_Int *p_num_recvs , HYPRE_Int **p_recv_procs , HYPRE_Int **p_recv_vec_starts , HYPRE_Int *p_num_sends , HYPRE_Int **p_send_procs , HYPRE_Int **p_send_map_starts , HYPRE_Int **p_send_map_elmts ); HYPRE_Int hypre_MatvecCommPkgCreate ( hypre_ParCSRMatrix *A ); HYPRE_Int hypre_MatvecCommPkgDestroy ( hypre_ParCSRCommPkg *comm_pkg ); HYPRE_Int hypre_BuildCSRMatrixMPIDataType ( HYPRE_Int num_nonzeros , HYPRE_Int num_rows , HYPRE_Complex *a_data , HYPRE_Int *a_i , HYPRE_Int *a_j , hypre_MPI_Datatype *csr_matrix_datatype ); HYPRE_Int hypre_BuildCSRJDataType ( HYPRE_Int num_nonzeros , HYPRE_Complex *a_data , HYPRE_Int *a_j , hypre_MPI_Datatype *csr_jdata_datatype ); /* par_csr_matop.c */ void hypre_ParMatmul_RowSizes ( HYPRE_Int **C_diag_i , HYPRE_Int **C_offd_i , HYPRE_Int *A_diag_i , HYPRE_Int *A_diag_j , HYPRE_Int *A_offd_i , HYPRE_Int *A_offd_j , HYPRE_Int *B_diag_i , HYPRE_Int *B_diag_j , HYPRE_Int *B_offd_i , HYPRE_Int *B_offd_j , HYPRE_Int *B_ext_diag_i , HYPRE_Int *B_ext_diag_j , HYPRE_Int *B_ext_offd_i , HYPRE_Int *B_ext_offd_j , HYPRE_Int *map_B_to_C , HYPRE_Int *C_diag_size , HYPRE_Int *C_offd_size , HYPRE_Int num_rows_diag_A , HYPRE_Int num_cols_offd_A , HYPRE_Int allsquare , HYPRE_Int num_cols_diag_B , HYPRE_Int num_cols_offd_B , HYPRE_Int num_cols_offd_C ); hypre_ParCSRMatrix *hypre_ParMatmul ( hypre_ParCSRMatrix *A , hypre_ParCSRMatrix *B ); void hypre_ParCSRMatrixExtractBExt_Arrays ( HYPRE_Int **pB_ext_i , HYPRE_Int **pB_ext_j , HYPRE_Complex **pB_ext_data , HYPRE_Int **pB_ext_row_map , HYPRE_Int *num_nonzeros , HYPRE_Int data , HYPRE_Int find_row_map , MPI_Comm comm , hypre_ParCSRCommPkg *comm_pkg , HYPRE_Int num_cols_B , HYPRE_Int num_recvs , HYPRE_Int num_sends , HYPRE_Int first_col_diag , HYPRE_Int *row_starts , HYPRE_Int *recv_vec_starts , HYPRE_Int *send_map_starts , HYPRE_Int *send_map_elmts , HYPRE_Int *diag_i , HYPRE_Int *diag_j , HYPRE_Int *offd_i , HYPRE_Int *offd_j , HYPRE_Int *col_map_offd , HYPRE_Real *diag_data , HYPRE_Real *offd_data ); void hypre_ParCSRMatrixExtractBExt_Arrays_Overlap ( HYPRE_Int **pB_ext_i , HYPRE_Int **pB_ext_j , HYPRE_Complex **pB_ext_data , HYPRE_Int **pB_ext_row_map , HYPRE_Int *num_nonzeros , HYPRE_Int data , HYPRE_Int find_row_map , MPI_Comm comm , hypre_ParCSRCommPkg *comm_pkg , HYPRE_Int num_cols_B , HYPRE_Int num_recvs , HYPRE_Int num_sends , HYPRE_Int first_col_diag , HYPRE_Int *row_starts , HYPRE_Int *recv_vec_starts , HYPRE_Int *send_map_starts , HYPRE_Int *send_map_elmts , HYPRE_Int *diag_i , HYPRE_Int *diag_j , HYPRE_Int *offd_i , HYPRE_Int *offd_j , HYPRE_Int *col_map_offd , HYPRE_Real *diag_data , HYPRE_Real *offd_data, hypre_ParCSRCommHandle **comm_handle_idx, hypre_ParCSRCommHandle **comm_handle_data, HYPRE_Int *CF_marker, HYPRE_Int *CF_marker_offd, HYPRE_Int skip_fine, HYPRE_Int skip_same_sign ); hypre_CSRMatrix *hypre_ParCSRMatrixExtractBExt ( hypre_ParCSRMatrix *B , hypre_ParCSRMatrix *A , HYPRE_Int data ); hypre_CSRMatrix *hypre_ParCSRMatrixExtractBExt_Overlap ( hypre_ParCSRMatrix *B , hypre_ParCSRMatrix *A , HYPRE_Int data, hypre_ParCSRCommHandle **comm_handle_idx, hypre_ParCSRCommHandle **comm_handle_data, HYPRE_Int *CF_marker, HYPRE_Int *CF_marker_offd, HYPRE_Int skip_fine, HYPRE_Int skip_same_sign ); HYPRE_Int hypre_ParCSRMatrixTranspose ( hypre_ParCSRMatrix *A , hypre_ParCSRMatrix **AT_ptr , HYPRE_Int data ); void hypre_ParCSRMatrixGenSpanningTree ( hypre_ParCSRMatrix *G_csr , HYPRE_Int **indices , HYPRE_Int G_type ); void hypre_ParCSRMatrixExtractSubmatrices ( hypre_ParCSRMatrix *A_csr , HYPRE_Int *indices2 , hypre_ParCSRMatrix ***submatrices ); void hypre_ParCSRMatrixExtractRowSubmatrices ( hypre_ParCSRMatrix *A_csr , HYPRE_Int *indices2 , hypre_ParCSRMatrix ***submatrices ); HYPRE_Complex hypre_ParCSRMatrixLocalSumElts ( hypre_ParCSRMatrix *A ); HYPRE_Int hypre_ParCSRMatrixAminvDB ( hypre_ParCSRMatrix *A , hypre_ParCSRMatrix *B , HYPRE_Complex *d , hypre_ParCSRMatrix **C_ptr ); hypre_ParCSRMatrix *hypre_ParTMatmul ( hypre_ParCSRMatrix *A , hypre_ParCSRMatrix *B ); #ifdef HYPRE_USING_PERSISTENT_COMM hypre_ParCSRPersistentCommHandle * hypre_ParCSRCommPkgGetPersistentCommHandle(HYPRE_Int job, hypre_ParCSRCommPkg *comm_pkg); hypre_ParCSRPersistentCommHandle * hypre_ParCSRPersistentCommHandleCreate(HYPRE_Int job, hypre_ParCSRCommPkg *comm_pkg, void *send_data, void *recv_data); void hypre_ParCSRPersistentCommHandleDestroy(hypre_ParCSRPersistentCommHandle *comm_handle); void hypre_ParCSRPersistentCommHandleStart(hypre_ParCSRPersistentCommHandle *comm_handle); void hypre_ParCSRPersistentCommHandleWait(hypre_ParCSRPersistentCommHandle *comm_handle); #endif /* par_csr_matop_marked.c */ void hypre_ParMatmul_RowSizes_Marked ( HYPRE_Int **C_diag_i , HYPRE_Int **C_offd_i , HYPRE_Int **B_marker , HYPRE_Int *A_diag_i , HYPRE_Int *A_diag_j , HYPRE_Int *A_offd_i , HYPRE_Int *A_offd_j , HYPRE_Int *B_diag_i , HYPRE_Int *B_diag_j , HYPRE_Int *B_offd_i , HYPRE_Int *B_offd_j , HYPRE_Int *B_ext_diag_i , HYPRE_Int *B_ext_diag_j , HYPRE_Int *B_ext_offd_i , HYPRE_Int *B_ext_offd_j , HYPRE_Int *map_B_to_C , HYPRE_Int *C_diag_size , HYPRE_Int *C_offd_size , HYPRE_Int num_rows_diag_A , HYPRE_Int num_cols_offd_A , HYPRE_Int allsquare , HYPRE_Int num_cols_diag_B , HYPRE_Int num_cols_offd_B , HYPRE_Int num_cols_offd_C , HYPRE_Int *CF_marker , HYPRE_Int *dof_func , HYPRE_Int *dof_func_offd ); hypre_ParCSRMatrix *hypre_ParMatmul_FC ( hypre_ParCSRMatrix *A , hypre_ParCSRMatrix *P , HYPRE_Int *CF_marker , HYPRE_Int *dof_func , HYPRE_Int *dof_func_offd ); void hypre_ParMatScaleDiagInv_F ( hypre_ParCSRMatrix *C , hypre_ParCSRMatrix *A , HYPRE_Complex weight , HYPRE_Int *CF_marker ); hypre_ParCSRMatrix *hypre_ParMatMinus_F ( hypre_ParCSRMatrix *P , hypre_ParCSRMatrix *C , HYPRE_Int *CF_marker ); void hypre_ParCSRMatrixZero_F ( hypre_ParCSRMatrix *P , HYPRE_Int *CF_marker ); void hypre_ParCSRMatrixCopy_C ( hypre_ParCSRMatrix *P , hypre_ParCSRMatrix *C , HYPRE_Int *CF_marker ); void hypre_ParCSRMatrixDropEntries ( hypre_ParCSRMatrix *C , hypre_ParCSRMatrix *P , HYPRE_Int *CF_marker ); /* par_csr_matrix.c */ hypre_ParCSRMatrix *hypre_ParCSRMatrixCreate ( MPI_Comm comm , HYPRE_Int global_num_rows , HYPRE_Int global_num_cols , HYPRE_Int *row_starts , HYPRE_Int *col_starts , HYPRE_Int num_cols_offd , HYPRE_Int num_nonzeros_diag , HYPRE_Int num_nonzeros_offd ); HYPRE_Int hypre_ParCSRMatrixDestroy ( hypre_ParCSRMatrix *matrix ); HYPRE_Int hypre_ParCSRMatrixInitialize ( hypre_ParCSRMatrix *matrix ); HYPRE_Int hypre_ParCSRMatrixSetNumNonzeros ( hypre_ParCSRMatrix *matrix ); HYPRE_Int hypre_ParCSRMatrixSetDNumNonzeros ( hypre_ParCSRMatrix *matrix ); HYPRE_Int hypre_ParCSRMatrixSetDataOwner ( hypre_ParCSRMatrix *matrix , HYPRE_Int owns_data ); HYPRE_Int hypre_ParCSRMatrixSetRowStartsOwner ( hypre_ParCSRMatrix *matrix , HYPRE_Int owns_row_starts ); HYPRE_Int hypre_ParCSRMatrixSetColStartsOwner ( hypre_ParCSRMatrix *matrix , HYPRE_Int owns_col_starts ); hypre_ParCSRMatrix *hypre_ParCSRMatrixRead ( MPI_Comm comm , const char *file_name ); HYPRE_Int hypre_ParCSRMatrixPrint ( hypre_ParCSRMatrix *matrix , const char *file_name ); HYPRE_Int hypre_ParCSRMatrixPrintIJ ( const hypre_ParCSRMatrix *matrix , const HYPRE_Int base_i , const HYPRE_Int base_j , const char *filename ); HYPRE_Int hypre_ParCSRMatrixReadIJ ( MPI_Comm comm , const char *filename , HYPRE_Int *base_i_ptr , HYPRE_Int *base_j_ptr , hypre_ParCSRMatrix **matrix_ptr ); HYPRE_Int hypre_ParCSRMatrixGetLocalRange ( hypre_ParCSRMatrix *matrix , HYPRE_Int *row_start , HYPRE_Int *row_end , HYPRE_Int *col_start , HYPRE_Int *col_end ); HYPRE_Int hypre_ParCSRMatrixGetRow ( hypre_ParCSRMatrix *mat , HYPRE_Int row , HYPRE_Int *size , HYPRE_Int **col_ind , HYPRE_Complex **values ); HYPRE_Int hypre_ParCSRMatrixRestoreRow ( hypre_ParCSRMatrix *matrix , HYPRE_Int row , HYPRE_Int *size , HYPRE_Int **col_ind , HYPRE_Complex **values ); hypre_ParCSRMatrix *hypre_CSRMatrixToParCSRMatrix ( MPI_Comm comm , hypre_CSRMatrix *A , HYPRE_Int *row_starts , HYPRE_Int *col_starts ); HYPRE_Int GenerateDiagAndOffd ( hypre_CSRMatrix *A , hypre_ParCSRMatrix *matrix , HYPRE_Int first_col_diag , HYPRE_Int last_col_diag ); hypre_CSRMatrix *hypre_MergeDiagAndOffd ( hypre_ParCSRMatrix *par_matrix ); hypre_CSRMatrix *hypre_ParCSRMatrixToCSRMatrixAll ( hypre_ParCSRMatrix *par_matrix ); HYPRE_Int hypre_ParCSRMatrixCopy ( hypre_ParCSRMatrix *A , hypre_ParCSRMatrix *B , HYPRE_Int copy_data ); HYPRE_Int hypre_FillResponseParToCSRMatrix ( void *p_recv_contact_buf , HYPRE_Int contact_size , HYPRE_Int contact_proc , void *ro , MPI_Comm comm , void **p_send_response_buf , HYPRE_Int *response_message_size ); hypre_ParCSRMatrix *hypre_ParCSRMatrixCompleteClone ( hypre_ParCSRMatrix *A ); hypre_ParCSRMatrix *hypre_ParCSRMatrixUnion ( hypre_ParCSRMatrix *A , hypre_ParCSRMatrix *B ); /* par_csr_matvec.c */ // y = alpha*A*x + beta*b HYPRE_Int hypre_ParCSRMatrixMatvecOutOfPlace ( HYPRE_Complex alpha , hypre_ParCSRMatrix *A , hypre_ParVector *x , HYPRE_Complex beta , hypre_ParVector *b, hypre_ParVector *y ); // y = alpha*A*x + beta*y HYPRE_Int hypre_ParCSRMatrixMatvec ( HYPRE_Complex alpha , hypre_ParCSRMatrix *A , hypre_ParVector *x , HYPRE_Complex beta , hypre_ParVector *y ); HYPRE_Int hypre_ParCSRMatrixMatvecT ( HYPRE_Complex alpha , hypre_ParCSRMatrix *A , hypre_ParVector *x , HYPRE_Complex beta , hypre_ParVector *y ); HYPRE_Int hypre_ParCSRMatrixMatvec_FF ( HYPRE_Complex alpha , hypre_ParCSRMatrix *A , hypre_ParVector *x , HYPRE_Complex beta , hypre_ParVector *y , HYPRE_Int *CF_marker , HYPRE_Int fpt ); /* par_vector.c */ hypre_ParVector *hypre_ParVectorCreate ( MPI_Comm comm , HYPRE_Int global_size , HYPRE_Int *partitioning ); hypre_ParVector *hypre_ParMultiVectorCreate ( MPI_Comm comm , HYPRE_Int global_size , HYPRE_Int *partitioning , HYPRE_Int num_vectors ); HYPRE_Int hypre_ParVectorDestroy ( hypre_ParVector *vector ); HYPRE_Int hypre_ParVectorInitialize ( hypre_ParVector *vector ); HYPRE_Int hypre_ParVectorSetDataOwner ( hypre_ParVector *vector , HYPRE_Int owns_data ); HYPRE_Int hypre_ParVectorSetPartitioningOwner ( hypre_ParVector *vector , HYPRE_Int owns_partitioning ); HYPRE_Int hypre_ParVectorSetNumVectors ( hypre_ParVector *vector , HYPRE_Int num_vectors ); hypre_ParVector *hypre_ParVectorRead ( MPI_Comm comm , const char *file_name ); HYPRE_Int hypre_ParVectorPrint ( hypre_ParVector *vector , const char *file_name ); HYPRE_Int hypre_ParVectorSetConstantValues ( hypre_ParVector *v , HYPRE_Complex value ); HYPRE_Int hypre_ParVectorSetRandomValues ( hypre_ParVector *v , HYPRE_Int seed ); HYPRE_Int hypre_ParVectorCopy ( hypre_ParVector *x , hypre_ParVector *y ); hypre_ParVector *hypre_ParVectorCloneShallow ( hypre_ParVector *x ); HYPRE_Int hypre_ParVectorScale ( HYPRE_Complex alpha , hypre_ParVector *y ); HYPRE_Int hypre_ParVectorAxpy ( HYPRE_Complex alpha , hypre_ParVector *x , hypre_ParVector *y ); HYPRE_Real hypre_ParVectorInnerProd ( hypre_ParVector *x , hypre_ParVector *y ); hypre_ParVector *hypre_VectorToParVector ( MPI_Comm comm , hypre_Vector *v , HYPRE_Int *vec_starts ); hypre_Vector *hypre_ParVectorToVectorAll ( hypre_ParVector *par_v ); HYPRE_Int hypre_ParVectorPrintIJ ( hypre_ParVector *vector , HYPRE_Int base_j , const char *filename ); HYPRE_Int hypre_ParVectorReadIJ ( MPI_Comm comm , const char *filename , HYPRE_Int *base_j_ptr , hypre_ParVector **vector_ptr ); HYPRE_Int hypre_FillResponseParToVectorAll ( void *p_recv_contact_buf , HYPRE_Int contact_size , HYPRE_Int contact_proc , void *ro , MPI_Comm comm , void **p_send_response_buf , HYPRE_Int *response_message_size ); HYPRE_Complex hypre_ParVectorLocalSumElts ( hypre_ParVector *vector ); #ifdef __cplusplus } #endif #endif
31,325
60.303327
812
h
AMG
AMG-master/parcsr_mv/headers.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #include <stdlib.h> #include <stdio.h> #include <math.h> #include "HYPRE.h" #include "parcsr_mv.h"
1,030
34.551724
81
h
AMG
AMG-master/parcsr_mv/new_commpkg.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef hypre_NEW_COMMPKG #define hypre_NEW_COMMPKG typedef struct { HYPRE_Int length; HYPRE_Int storage_length; HYPRE_Int *id; HYPRE_Int *vec_starts; HYPRE_Int element_storage_length; HYPRE_Int *elements; HYPRE_Real *d_elements; /* Is this used anywhere? */ void *v_elements; } hypre_ProcListElements; #endif /* hypre_NEW_COMMPKG */
1,343
36.333333
81
h
AMG
AMG-master/parcsr_mv/par_csr_assumed_part.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef hypre_PARCSR_ASSUMED_PART #define hypre_PARCSR_ASSUMED_PART typedef struct { HYPRE_Int length; HYPRE_Int row_start; HYPRE_Int row_end; HYPRE_Int storage_length; HYPRE_Int *proc_list; HYPRE_Int *row_start_list; HYPRE_Int *row_end_list; HYPRE_Int *sort_index; } hypre_IJAssumedPart; #endif /* hypre_PARCSR_ASSUMED_PART */
1,422
36.447368
81
h
AMG
AMG-master/parcsr_mv/par_csr_communication.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef HYPRE_PAR_CSR_COMMUNICATION_HEADER #define HYPRE_PAR_CSR_COMMUNICATION_HEADER /*-------------------------------------------------------------------------- * hypre_ParCSRCommPkg: * Structure containing information for doing communications *--------------------------------------------------------------------------*/ #define HYPRE_USING_PERSISTENT_COMM // JSP: can be defined by configure #ifdef HYPRE_USING_PERSISTENT_COMM typedef enum CommPkgJobType { HYPRE_COMM_PKG_JOB_COMPLEX = 0, HYPRE_COMM_PKG_JOB_COMPLEX_TRANSPOSE, HYPRE_COMM_PKG_JOB_INT, HYPRE_COMM_PKG_JOB_INT_TRANSPOSE, NUM_OF_COMM_PKG_JOB_TYPE, } CommPkgJobType; typedef struct { void *send_data; void *recv_data; HYPRE_Int num_requests; hypre_MPI_Request *requests; HYPRE_Int own_send_data, own_recv_data; } hypre_ParCSRPersistentCommHandle; #endif typedef struct { MPI_Comm comm; HYPRE_Int num_sends; HYPRE_Int *send_procs; HYPRE_Int *send_map_starts; HYPRE_Int *send_map_elmts; HYPRE_Int num_recvs; HYPRE_Int *recv_procs; HYPRE_Int *recv_vec_starts; /* remote communication information */ hypre_MPI_Datatype *send_mpi_types; hypre_MPI_Datatype *recv_mpi_types; #ifdef HYPRE_USING_PERSISTENT_COMM hypre_ParCSRPersistentCommHandle *persistent_comm_handles[NUM_OF_COMM_PKG_JOB_TYPE]; #endif } hypre_ParCSRCommPkg; /*-------------------------------------------------------------------------- * hypre_ParCSRCommHandle: *--------------------------------------------------------------------------*/ typedef struct { hypre_ParCSRCommPkg *comm_pkg; void *send_data; void *recv_data; HYPRE_Int num_requests; hypre_MPI_Request *requests; } hypre_ParCSRCommHandle; /*-------------------------------------------------------------------------- * Accessor macros: hypre_ParCSRCommPkg *--------------------------------------------------------------------------*/ #define hypre_ParCSRCommPkgComm(comm_pkg) (comm_pkg -> comm) #define hypre_ParCSRCommPkgNumSends(comm_pkg) (comm_pkg -> num_sends) #define hypre_ParCSRCommPkgSendProcs(comm_pkg) (comm_pkg -> send_procs) #define hypre_ParCSRCommPkgSendProc(comm_pkg, i) (comm_pkg -> send_procs[i]) #define hypre_ParCSRCommPkgSendMapStarts(comm_pkg) (comm_pkg -> send_map_starts) #define hypre_ParCSRCommPkgSendMapStart(comm_pkg,i)(comm_pkg -> send_map_starts[i]) #define hypre_ParCSRCommPkgSendMapElmts(comm_pkg) (comm_pkg -> send_map_elmts) #define hypre_ParCSRCommPkgSendMapElmt(comm_pkg,i) (comm_pkg -> send_map_elmts[i]) #define hypre_ParCSRCommPkgNumRecvs(comm_pkg) (comm_pkg -> num_recvs) #define hypre_ParCSRCommPkgRecvProcs(comm_pkg) (comm_pkg -> recv_procs) #define hypre_ParCSRCommPkgRecvProc(comm_pkg, i) (comm_pkg -> recv_procs[i]) #define hypre_ParCSRCommPkgRecvVecStarts(comm_pkg) (comm_pkg -> recv_vec_starts) #define hypre_ParCSRCommPkgRecvVecStart(comm_pkg,i)(comm_pkg -> recv_vec_starts[i]) #define hypre_ParCSRCommPkgSendMPITypes(comm_pkg) (comm_pkg -> send_mpi_types) #define hypre_ParCSRCommPkgSendMPIType(comm_pkg,i) (comm_pkg -> send_mpi_types[i]) #define hypre_ParCSRCommPkgRecvMPITypes(comm_pkg) (comm_pkg -> recv_mpi_types) #define hypre_ParCSRCommPkgRecvMPIType(comm_pkg,i) (comm_pkg -> recv_mpi_types[i]) /*-------------------------------------------------------------------------- * Accessor macros: hypre_ParCSRCommHandle *--------------------------------------------------------------------------*/ #define hypre_ParCSRCommHandleCommPkg(comm_handle) (comm_handle -> comm_pkg) #define hypre_ParCSRCommHandleSendData(comm_handle) (comm_handle -> send_data) #define hypre_ParCSRCommHandleRecvData(comm_handle) (comm_handle -> recv_data) #define hypre_ParCSRCommHandleNumRequests(comm_handle) (comm_handle -> num_requests) #define hypre_ParCSRCommHandleRequests(comm_handle) (comm_handle -> requests) #define hypre_ParCSRCommHandleRequest(comm_handle, i) (comm_handle -> requests[i]) #endif /* HYPRE_PAR_CSR_COMMUNICATION_HEADER */
5,177
39.453125
87
h
AMG
AMG-master/parcsr_mv/par_csr_matrix.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header info for Parallel CSR Matrix data structures * * Note: this matrix currently uses 0-based indexing. * *****************************************************************************/ #ifndef hypre_PAR_CSR_MATRIX_HEADER #define hypre_PAR_CSR_MATRIX_HEADER /*-------------------------------------------------------------------------- * Parallel CSR Matrix *--------------------------------------------------------------------------*/ #ifndef HYPRE_PAR_CSR_MATRIX_STRUCT #define HYPRE_PAR_CSR_MATRIX_STRUCT #endif typedef struct hypre_ParCSRMatrix_struct { MPI_Comm comm; HYPRE_Int global_num_rows; HYPRE_Int global_num_cols; HYPRE_Int first_row_index; HYPRE_Int first_col_diag; /* need to know entire local range in case row_starts and col_starts are null (i.e., bgl) AHB 6/05*/ HYPRE_Int last_row_index; HYPRE_Int last_col_diag; hypre_CSRMatrix *diag; hypre_CSRMatrix *offd; hypre_CSRMatrix *diagT, *offdT; /* JSP: transposed matrices are created lazily and optional */ HYPRE_Int *col_map_offd; /* maps columns of offd to global columns */ HYPRE_Int *row_starts; /* array of length num_procs+1, row_starts[i] contains the global number of the first row on proc i, first_row_index = row_starts[my_id], row_starts[num_procs] = global_num_rows */ HYPRE_Int *col_starts; /* array of length num_procs+1, col_starts[i] contains the global number of the first column of diag on proc i, first_col_diag = col_starts[my_id], col_starts[num_procs] = global_num_cols */ hypre_ParCSRCommPkg *comm_pkg; hypre_ParCSRCommPkg *comm_pkgT; /* Does the ParCSRMatrix create/destroy `diag', `offd', `col_map_offd'? */ HYPRE_Int owns_data; /* Does the ParCSRMatrix create/destroy `row_starts', `col_starts'? */ HYPRE_Int owns_row_starts; HYPRE_Int owns_col_starts; HYPRE_Int num_nonzeros; HYPRE_Real d_num_nonzeros; /* Buffers used by GetRow to hold row currently being accessed. AJC, 4/99 */ HYPRE_Int *rowindices; HYPRE_Complex *rowvalues; HYPRE_Int getrowactive; hypre_IJAssumedPart *assumed_partition; /* only populated if no_global_partition option is used (compile-time option)*/ } hypre_ParCSRMatrix; /*-------------------------------------------------------------------------- * Accessor functions for the Parallel CSR Matrix structure *--------------------------------------------------------------------------*/ #define hypre_ParCSRMatrixComm(matrix) ((matrix) -> comm) #define hypre_ParCSRMatrixGlobalNumRows(matrix) ((matrix) -> global_num_rows) #define hypre_ParCSRMatrixGlobalNumCols(matrix) ((matrix) -> global_num_cols) #define hypre_ParCSRMatrixFirstRowIndex(matrix) ((matrix) -> first_row_index) #define hypre_ParCSRMatrixFirstColDiag(matrix) ((matrix) -> first_col_diag) #define hypre_ParCSRMatrixLastRowIndex(matrix) ((matrix) -> last_row_index) #define hypre_ParCSRMatrixLastColDiag(matrix) ((matrix) -> last_col_diag) #define hypre_ParCSRMatrixDiag(matrix) ((matrix) -> diag) #define hypre_ParCSRMatrixOffd(matrix) ((matrix) -> offd) #define hypre_ParCSRMatrixDiagT(matrix) ((matrix) -> diagT) #define hypre_ParCSRMatrixOffdT(matrix) ((matrix) -> offdT) #define hypre_ParCSRMatrixColMapOffd(matrix) ((matrix) -> col_map_offd) #define hypre_ParCSRMatrixRowStarts(matrix) ((matrix) -> row_starts) #define hypre_ParCSRMatrixColStarts(matrix) ((matrix) -> col_starts) #define hypre_ParCSRMatrixCommPkg(matrix) ((matrix) -> comm_pkg) #define hypre_ParCSRMatrixCommPkgT(matrix) ((matrix) -> comm_pkgT) #define hypre_ParCSRMatrixOwnsData(matrix) ((matrix) -> owns_data) #define hypre_ParCSRMatrixOwnsRowStarts(matrix) ((matrix) -> owns_row_starts) #define hypre_ParCSRMatrixOwnsColStarts(matrix) ((matrix) -> owns_col_starts) #define hypre_ParCSRMatrixNumRows(matrix) \ hypre_CSRMatrixNumRows(hypre_ParCSRMatrixDiag(matrix)) #define hypre_ParCSRMatrixNumCols(matrix) \ hypre_CSRMatrixNumCols(hypre_ParCSRMatrixDiag(matrix)) #define hypre_ParCSRMatrixNumNonzeros(matrix) ((matrix) -> num_nonzeros) #define hypre_ParCSRMatrixDNumNonzeros(matrix) ((matrix) -> d_num_nonzeros) #define hypre_ParCSRMatrixRowindices(matrix) ((matrix) -> rowindices) #define hypre_ParCSRMatrixRowvalues(matrix) ((matrix) -> rowvalues) #define hypre_ParCSRMatrixGetrowactive(matrix) ((matrix) -> getrowactive) #define hypre_ParCSRMatrixAssumedPartition(matrix) ((matrix) -> assumed_partition) /*-------------------------------------------------------------------------- * Parallel CSR Boolean Matrix *--------------------------------------------------------------------------*/ typedef struct { MPI_Comm comm; HYPRE_Int global_num_rows; HYPRE_Int global_num_cols; HYPRE_Int first_row_index; HYPRE_Int first_col_diag; HYPRE_Int last_row_index; HYPRE_Int last_col_diag; hypre_CSRBooleanMatrix *diag; hypre_CSRBooleanMatrix *offd; HYPRE_Int *col_map_offd; HYPRE_Int *row_starts; HYPRE_Int *col_starts; hypre_ParCSRCommPkg *comm_pkg; hypre_ParCSRCommPkg *comm_pkgT; HYPRE_Int owns_data; HYPRE_Int owns_row_starts; HYPRE_Int owns_col_starts; HYPRE_Int num_nonzeros; HYPRE_Int *rowindices; HYPRE_Int getrowactive; } hypre_ParCSRBooleanMatrix; /*-------------------------------------------------------------------------- * Accessor functions for the Parallel CSR Boolean Matrix structure *--------------------------------------------------------------------------*/ #define hypre_ParCSRBooleanMatrix_Get_Comm(matrix) ((matrix)->comm) #define hypre_ParCSRBooleanMatrix_Get_GlobalNRows(matrix) ((matrix)->global_num_rows) #define hypre_ParCSRBooleanMatrix_Get_GlobalNCols(matrix) ((matrix)->global_num_cols) #define hypre_ParCSRBooleanMatrix_Get_StartRow(matrix) ((matrix)->first_row_index) #define hypre_ParCSRBooleanMatrix_Get_FirstRowIndex(matrix) ((matrix)->first_row_index) #define hypre_ParCSRBooleanMatrix_Get_FirstColDiag(matrix) ((matrix)->first_col_diag) #define hypre_ParCSRBooleanMatrix_Get_LastRowIndex(matrix) ((matrix)->last_row_index) #define hypre_ParCSRBooleanMatrix_Get_LastColDiag(matrix) ((matrix)->last_col_diag) #define hypre_ParCSRBooleanMatrix_Get_Diag(matrix) ((matrix)->diag) #define hypre_ParCSRBooleanMatrix_Get_Offd(matrix) ((matrix)->offd) #define hypre_ParCSRBooleanMatrix_Get_ColMapOffd(matrix) ((matrix)->col_map_offd) #define hypre_ParCSRBooleanMatrix_Get_RowStarts(matrix) ((matrix)->row_starts) #define hypre_ParCSRBooleanMatrix_Get_ColStarts(matrix) ((matrix)->col_starts) #define hypre_ParCSRBooleanMatrix_Get_CommPkg(matrix) ((matrix)->comm_pkg) #define hypre_ParCSRBooleanMatrix_Get_CommPkgT(matrix) ((matrix)->comm_pkgT) #define hypre_ParCSRBooleanMatrix_Get_OwnsData(matrix) ((matrix)->owns_data) #define hypre_ParCSRBooleanMatrix_Get_OwnsRowStarts(matrix) ((matrix)->owns_row_starts) #define hypre_ParCSRBooleanMatrix_Get_OwnsColStarts(matrix) ((matrix)->owns_col_starts) #define hypre_ParCSRBooleanMatrix_Get_NRows(matrix) ((matrix->diag->num_rows)) #define hypre_ParCSRBooleanMatrix_Get_NCols(matrix) ((matrix->diag->num_cols)) #define hypre_ParCSRBooleanMatrix_Get_NNZ(matrix) ((matrix)->num_nonzeros) #define hypre_ParCSRBooleanMatrix_Get_Rowindices(matrix) ((matrix)->rowindices) #define hypre_ParCSRBooleanMatrix_Get_Getrowactive(matrix) ((matrix)->getrowactive) #endif
9,164
49.357143
87
h
AMG
AMG-master/parcsr_mv/par_vector.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header info for Parallel Vector data structure * *****************************************************************************/ #ifndef hypre_PAR_VECTOR_HEADER #define hypre_PAR_VECTOR_HEADER /*-------------------------------------------------------------------------- * hypre_ParVector *--------------------------------------------------------------------------*/ #ifndef HYPRE_PAR_VECTOR_STRUCT #define HYPRE_PAR_VECTOR_STRUCT #endif typedef struct hypre_ParVector_struct { MPI_Comm comm; HYPRE_Int global_size; HYPRE_Int first_index; HYPRE_Int last_index; HYPRE_Int *partitioning; HYPRE_Int actual_local_size; /* stores actual length of data in local vector to allow memory manipulations for temporary vectors*/ hypre_Vector *local_vector; /* Does the Vector create/destroy `data'? */ HYPRE_Int owns_data; HYPRE_Int owns_partitioning; hypre_IJAssumedPart *assumed_partition; /* only populated if no_global_partition option is used (compile-time option) AND this partition needed (for setting off-proc elements, for example)*/ } hypre_ParVector; /*-------------------------------------------------------------------------- * Accessor functions for the Vector structure *--------------------------------------------------------------------------*/ #define hypre_ParVectorComm(vector) ((vector) -> comm) #define hypre_ParVectorGlobalSize(vector) ((vector) -> global_size) #define hypre_ParVectorFirstIndex(vector) ((vector) -> first_index) #define hypre_ParVectorLastIndex(vector) ((vector) -> last_index) #define hypre_ParVectorPartitioning(vector) ((vector) -> partitioning) #define hypre_ParVectorActualLocalSize(vector) ((vector) -> actual_local_size) #define hypre_ParVectorLocalVector(vector) ((vector) -> local_vector) #define hypre_ParVectorOwnsData(vector) ((vector) -> owns_data) #define hypre_ParVectorOwnsPartitioning(vector) ((vector) -> owns_partitioning) #define hypre_ParVectorNumVectors(vector)\ (hypre_VectorNumVectors( hypre_ParVectorLocalVector(vector) )) #define hypre_ParVectorAssumedPartition(vector) ((vector) -> assumed_partition) #endif
3,376
39.202381
94
h
AMG
AMG-master/seq_mv/HYPRE_seq_mv.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header file for HYPRE_mv library * *****************************************************************************/ #ifndef HYPRE_SEQ_MV_HEADER #define HYPRE_SEQ_MV_HEADER #include "../utilities/HYPRE_utilities.h" #ifdef __cplusplus extern "C" { #endif /*-------------------------------------------------------------------------- * Structures *--------------------------------------------------------------------------*/ struct hypre_CSRMatrix_struct; typedef struct hypre_CSRMatrix_struct *HYPRE_CSRMatrix; #ifndef HYPRE_VECTOR_STRUCT #define HYPRE_VECTOR_STRUCT struct hypre_Vector_struct; typedef struct hypre_Vector_struct *HYPRE_Vector; #endif /*-------------------------------------------------------------------------- * Prototypes *--------------------------------------------------------------------------*/ /* HYPRE_csr_matrix.c */ HYPRE_CSRMatrix HYPRE_CSRMatrixCreate( HYPRE_Int num_rows , HYPRE_Int num_cols , HYPRE_Int *row_sizes ); HYPRE_Int HYPRE_CSRMatrixDestroy( HYPRE_CSRMatrix matrix ); HYPRE_Int HYPRE_CSRMatrixInitialize( HYPRE_CSRMatrix matrix ); HYPRE_CSRMatrix HYPRE_CSRMatrixRead( char *file_name ); void HYPRE_CSRMatrixPrint( HYPRE_CSRMatrix matrix , char *file_name ); HYPRE_Int HYPRE_CSRMatrixGetNumRows( HYPRE_CSRMatrix matrix , HYPRE_Int *num_rows ); /* HYPRE_vector.c */ HYPRE_Vector HYPRE_VectorCreate( HYPRE_Int size ); HYPRE_Int HYPRE_VectorDestroy( HYPRE_Vector vector ); HYPRE_Int HYPRE_VectorInitialize( HYPRE_Vector vector ); HYPRE_Int HYPRE_VectorPrint( HYPRE_Vector vector , char *file_name ); HYPRE_Vector HYPRE_VectorRead( char *file_name ); typedef enum HYPRE_TimerID { // timers for solver phase HYPRE_TIMER_ID_MATVEC = 0, HYPRE_TIMER_ID_BLAS1, HYPRE_TIMER_ID_RELAX, HYPRE_TIMER_ID_GS_ELIM_SOLVE, // timers for solve MPI HYPRE_TIMER_ID_PACK_UNPACK, // copying data to/from send/recv buf HYPRE_TIMER_ID_HALO_EXCHANGE, // halo exchange in matvec and relax HYPRE_TIMER_ID_ALL_REDUCE, // timers for setup phase // coarsening HYPRE_TIMER_ID_CREATES, HYPRE_TIMER_ID_CREATE_2NDS, HYPRE_TIMER_ID_PMIS, // interpolation HYPRE_TIMER_ID_EXTENDED_I_INTERP, HYPRE_TIMER_ID_PARTIAL_INTERP, HYPRE_TIMER_ID_MULTIPASS_INTERP, HYPRE_TIMER_ID_INTERP_TRUNC, HYPRE_TIMER_ID_MATMUL, // matrix-matrix multiplication HYPRE_TIMER_ID_COARSE_PARAMS, // rap HYPRE_TIMER_ID_RAP, // timers for setup MPI HYPRE_TIMER_ID_RENUMBER_COLIDX, HYPRE_TIMER_ID_EXCHANGE_INTERP_DATA, // setup etc HYPRE_TIMER_ID_GS_ELIM_SETUP, // temporaries HYPRE_TIMER_ID_BEXT_A, HYPRE_TIMER_ID_BEXT_S, HYPRE_TIMER_ID_RENUMBER_COLIDX_RAP, HYPRE_TIMER_ID_MERGE, HYPRE_TIMER_ID_COUNT } HYPRE_TimerID; extern HYPRE_Real hypre_profile_times[HYPRE_TIMER_ID_COUNT]; #ifdef __cplusplus } #endif #endif
3,825
30.619835
104
h
AMG
AMG-master/seq_mv/csr_matrix.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header info for CSR Matrix data structures * * Note: this matrix currently uses 0-based indexing. * *****************************************************************************/ #ifndef hypre_CSR_MATRIX_HEADER #define hypre_CSR_MATRIX_HEADER /*-------------------------------------------------------------------------- * CSR Matrix *--------------------------------------------------------------------------*/ typedef struct { HYPRE_Int *i; HYPRE_Int *j; HYPRE_Int num_rows; HYPRE_Int num_cols; HYPRE_Int num_nonzeros; /* Does the CSRMatrix create/destroy `data', `i', `j'? */ HYPRE_Int owns_data; HYPRE_Complex *data; /* for compressing rows in matrix multiplication */ HYPRE_Int *rownnz; HYPRE_Int num_rownnz; } hypre_CSRMatrix; /*-------------------------------------------------------------------------- * Accessor functions for the CSR Matrix structure *--------------------------------------------------------------------------*/ #define hypre_CSRMatrixData(matrix) ((matrix) -> data) #define hypre_CSRMatrixI(matrix) ((matrix) -> i) #define hypre_CSRMatrixJ(matrix) ((matrix) -> j) #define hypre_CSRMatrixNumRows(matrix) ((matrix) -> num_rows) #define hypre_CSRMatrixNumCols(matrix) ((matrix) -> num_cols) #define hypre_CSRMatrixNumNonzeros(matrix) ((matrix) -> num_nonzeros) #define hypre_CSRMatrixRownnz(matrix) ((matrix) -> rownnz) #define hypre_CSRMatrixNumRownnz(matrix) ((matrix) -> num_rownnz) #define hypre_CSRMatrixOwnsData(matrix) ((matrix) -> owns_data) HYPRE_Int hypre_CSRMatrixGetLoadBalancedPartitionBegin( hypre_CSRMatrix *A ); HYPRE_Int hypre_CSRMatrixGetLoadBalancedPartitionEnd( hypre_CSRMatrix *A ); /*-------------------------------------------------------------------------- * CSR Boolean Matrix *--------------------------------------------------------------------------*/ typedef struct { HYPRE_Int *i; HYPRE_Int *j; HYPRE_Int num_rows; HYPRE_Int num_cols; HYPRE_Int num_nonzeros; HYPRE_Int owns_data; } hypre_CSRBooleanMatrix; /*-------------------------------------------------------------------------- * Accessor functions for the CSR Boolean Matrix structure *--------------------------------------------------------------------------*/ #define hypre_CSRBooleanMatrix_Get_I(matrix) ((matrix)->i) #define hypre_CSRBooleanMatrix_Get_J(matrix) ((matrix)->j) #define hypre_CSRBooleanMatrix_Get_NRows(matrix) ((matrix)->num_rows) #define hypre_CSRBooleanMatrix_Get_NCols(matrix) ((matrix)->num_cols) #define hypre_CSRBooleanMatrix_Get_NNZ(matrix) ((matrix)->num_nonzeros) #define hypre_CSRBooleanMatrix_Get_OwnsData(matrix) ((matrix)->owns_data) #endif
3,814
38.329897
81
h
AMG
AMG-master/seq_mv/headers.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #include <stdlib.h> #include <stdio.h> #include <math.h> #include "seq_mv.h"
1,007
36.333333
81
h
AMG
AMG-master/seq_mv/seq_mv.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef hypre_MV_HEADER #define hypre_MV_HEADER #include <stdlib.h> #include <stdio.h> #include <math.h> #include "HYPRE_seq_mv.h" #include "../utilities/_hypre_utilities.h" #ifdef __cplusplus extern "C" { #endif /****************************************************************************** * * Header info for CSR Matrix data structures * * Note: this matrix currently uses 0-based indexing. * *****************************************************************************/ #ifndef hypre_CSR_MATRIX_HEADER #define hypre_CSR_MATRIX_HEADER /*-------------------------------------------------------------------------- * CSR Matrix *--------------------------------------------------------------------------*/ typedef struct { HYPRE_Int *i; HYPRE_Int *j; HYPRE_Int num_rows; HYPRE_Int num_cols; HYPRE_Int num_nonzeros; /* Does the CSRMatrix create/destroy `data', `i', `j'? */ HYPRE_Int owns_data; HYPRE_Complex *data; /* for compressing rows in matrix multiplication */ HYPRE_Int *rownnz; HYPRE_Int num_rownnz; } hypre_CSRMatrix; /*-------------------------------------------------------------------------- * Accessor functions for the CSR Matrix structure *--------------------------------------------------------------------------*/ #define hypre_CSRMatrixData(matrix) ((matrix) -> data) #define hypre_CSRMatrixI(matrix) ((matrix) -> i) #define hypre_CSRMatrixJ(matrix) ((matrix) -> j) #define hypre_CSRMatrixNumRows(matrix) ((matrix) -> num_rows) #define hypre_CSRMatrixNumCols(matrix) ((matrix) -> num_cols) #define hypre_CSRMatrixNumNonzeros(matrix) ((matrix) -> num_nonzeros) #define hypre_CSRMatrixRownnz(matrix) ((matrix) -> rownnz) #define hypre_CSRMatrixNumRownnz(matrix) ((matrix) -> num_rownnz) #define hypre_CSRMatrixOwnsData(matrix) ((matrix) -> owns_data) HYPRE_Int hypre_CSRMatrixGetLoadBalancedPartitionBegin( hypre_CSRMatrix *A ); HYPRE_Int hypre_CSRMatrixGetLoadBalancedPartitionEnd( hypre_CSRMatrix *A ); #endif /****************************************************************************** * * Header info for Vector data structure * *****************************************************************************/ #ifndef hypre_VECTOR_HEADER #define hypre_VECTOR_HEADER /*-------------------------------------------------------------------------- * hypre_Vector *--------------------------------------------------------------------------*/ typedef struct { HYPRE_Complex *data; HYPRE_Int size; /* Does the Vector create/destroy `data'? */ HYPRE_Int owns_data; /* For multivectors...*/ HYPRE_Int num_vectors; /* the above "size" is size of one vector */ HYPRE_Int multivec_storage_method; /* ...if 0, store colwise v0[0], v0[1], ..., v1[0], v1[1], ... v2[0]... */ /* ...if 1, store rowwise v0[0], v1[0], ..., v0[1], v1[1], ... */ /* With colwise storage, vj[i] = data[ j*size + i] With rowwise storage, vj[i] = data[ j + num_vectors*i] */ HYPRE_Int vecstride, idxstride; /* ... so vj[i] = data[ j*vecstride + i*idxstride ] regardless of row_storage.*/ } hypre_Vector; /*-------------------------------------------------------------------------- * Accessor functions for the Vector structure *--------------------------------------------------------------------------*/ #define hypre_VectorData(vector) ((vector) -> data) #define hypre_VectorSize(vector) ((vector) -> size) #define hypre_VectorOwnsData(vector) ((vector) -> owns_data) #define hypre_VectorNumVectors(vector) ((vector) -> num_vectors) #define hypre_VectorMultiVecStorageMethod(vector) ((vector) -> multivec_storage_method) #define hypre_VectorVectorStride(vector) ((vector) -> vecstride ) #define hypre_VectorIndexStride(vector) ((vector) -> idxstride ) #endif /* csr_matop.c */ hypre_CSRMatrix *hypre_CSRMatrixAdd ( hypre_CSRMatrix *A , hypre_CSRMatrix *B ); hypre_CSRMatrix *hypre_CSRMatrixMultiply ( hypre_CSRMatrix *A , hypre_CSRMatrix *B ); hypre_CSRMatrix *hypre_CSRMatrixDeleteZeros ( hypre_CSRMatrix *A , HYPRE_Real tol ); HYPRE_Int hypre_CSRMatrixTranspose ( hypre_CSRMatrix *A , hypre_CSRMatrix **AT , HYPRE_Int data ); HYPRE_Int hypre_CSRMatrixReorder ( hypre_CSRMatrix *A ); HYPRE_Complex hypre_CSRMatrixSumElts ( hypre_CSRMatrix *A ); /* csr_matrix.c */ hypre_CSRMatrix *hypre_CSRMatrixCreate ( HYPRE_Int num_rows , HYPRE_Int num_cols , HYPRE_Int num_nonzeros ); HYPRE_Int hypre_CSRMatrixDestroy ( hypre_CSRMatrix *matrix ); HYPRE_Int hypre_CSRMatrixInitialize ( hypre_CSRMatrix *matrix ); HYPRE_Int hypre_CSRMatrixSetDataOwner ( hypre_CSRMatrix *matrix , HYPRE_Int owns_data ); HYPRE_Int hypre_CSRMatrixSetRownnz ( hypre_CSRMatrix *matrix ); hypre_CSRMatrix *hypre_CSRMatrixRead ( char *file_name ); HYPRE_Int hypre_CSRMatrixPrint ( hypre_CSRMatrix *matrix , char *file_name ); HYPRE_Int hypre_CSRMatrixPrintHB ( hypre_CSRMatrix *matrix_input , char *file_name ); HYPRE_Int hypre_CSRMatrixCopy ( hypre_CSRMatrix *A , hypre_CSRMatrix *B , HYPRE_Int copy_data ); hypre_CSRMatrix *hypre_CSRMatrixClone ( hypre_CSRMatrix *A ); hypre_CSRMatrix *hypre_CSRMatrixUnion ( hypre_CSRMatrix *A , hypre_CSRMatrix *B , HYPRE_Int *col_map_offd_A , HYPRE_Int *col_map_offd_B , HYPRE_Int **col_map_offd_C ); /* csr_matvec.c */ // y[offset:end] = alpha*A[offset:end,:]*x + beta*b[offset:end] HYPRE_Int hypre_CSRMatrixMatvecOutOfPlace ( HYPRE_Complex alpha , hypre_CSRMatrix *A , hypre_Vector *x , HYPRE_Complex beta , hypre_Vector *b, hypre_Vector *y, HYPRE_Int offset ); // y = alpha*A + beta*y HYPRE_Int hypre_CSRMatrixMatvec ( HYPRE_Complex alpha , hypre_CSRMatrix *A , hypre_Vector *x , HYPRE_Complex beta , hypre_Vector *y ); HYPRE_Int hypre_CSRMatrixMatvecT ( HYPRE_Complex alpha , hypre_CSRMatrix *A , hypre_Vector *x , HYPRE_Complex beta , hypre_Vector *y ); HYPRE_Int hypre_CSRMatrixMatvec_FF ( HYPRE_Complex alpha , hypre_CSRMatrix *A , hypre_Vector *x , HYPRE_Complex beta , hypre_Vector *y , HYPRE_Int *CF_marker_x , HYPRE_Int *CF_marker_y , HYPRE_Int fpt ); /* genpart.c */ HYPRE_Int hypre_GeneratePartitioning ( HYPRE_Int length , HYPRE_Int num_procs , HYPRE_Int **part_ptr ); HYPRE_Int hypre_GenerateLocalPartitioning ( HYPRE_Int length , HYPRE_Int num_procs , HYPRE_Int myid , HYPRE_Int **part_ptr ); /* HYPRE_csr_matrix.c */ HYPRE_CSRMatrix HYPRE_CSRMatrixCreate ( HYPRE_Int num_rows , HYPRE_Int num_cols , HYPRE_Int *row_sizes ); HYPRE_Int HYPRE_CSRMatrixDestroy ( HYPRE_CSRMatrix matrix ); HYPRE_Int HYPRE_CSRMatrixInitialize ( HYPRE_CSRMatrix matrix ); HYPRE_CSRMatrix HYPRE_CSRMatrixRead ( char *file_name ); void HYPRE_CSRMatrixPrint ( HYPRE_CSRMatrix matrix , char *file_name ); HYPRE_Int HYPRE_CSRMatrixGetNumRows ( HYPRE_CSRMatrix matrix , HYPRE_Int *num_rows ); /* vector.c */ hypre_Vector *hypre_SeqVectorCreate ( HYPRE_Int size ); hypre_Vector *hypre_SeqMultiVectorCreate ( HYPRE_Int size , HYPRE_Int num_vectors ); HYPRE_Int hypre_SeqVectorDestroy ( hypre_Vector *vector ); HYPRE_Int hypre_SeqVectorInitialize ( hypre_Vector *vector ); HYPRE_Int hypre_SeqVectorSetDataOwner ( hypre_Vector *vector , HYPRE_Int owns_data ); hypre_Vector *hypre_SeqVectorRead ( char *file_name ); HYPRE_Int hypre_SeqVectorPrint ( hypre_Vector *vector , char *file_name ); HYPRE_Int hypre_SeqVectorSetConstantValues ( hypre_Vector *v , HYPRE_Complex value ); HYPRE_Int hypre_SeqVectorSetRandomValues ( hypre_Vector *v , HYPRE_Int seed ); HYPRE_Int hypre_SeqVectorCopy ( hypre_Vector *x , hypre_Vector *y ); hypre_Vector *hypre_SeqVectorCloneDeep ( hypre_Vector *x ); hypre_Vector *hypre_SeqVectorCloneShallow ( hypre_Vector *x ); HYPRE_Int hypre_SeqVectorScale ( HYPRE_Complex alpha , hypre_Vector *y ); HYPRE_Int hypre_SeqVectorAxpy ( HYPRE_Complex alpha , hypre_Vector *x , hypre_Vector *y ); HYPRE_Real hypre_SeqVectorInnerProd ( hypre_Vector *x , hypre_Vector *y ); HYPRE_Complex hypre_VectorSumElts ( hypre_Vector *vector ); #ifdef __cplusplus } #endif #endif
8,927
43.864322
203
h
AMG
AMG-master/seq_mv/vector.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header info for Vector data structure * *****************************************************************************/ #ifndef hypre_VECTOR_HEADER #define hypre_VECTOR_HEADER /*-------------------------------------------------------------------------- * hypre_Vector *--------------------------------------------------------------------------*/ typedef struct { HYPRE_Complex *data; HYPRE_Int size; /* Does the Vector create/destroy `data'? */ HYPRE_Int owns_data; /* For multivectors...*/ HYPRE_Int num_vectors; /* the above "size" is size of one vector */ HYPRE_Int multivec_storage_method; /* ...if 0, store colwise v0[0], v0[1], ..., v1[0], v1[1], ... v2[0]... */ /* ...if 1, store rowwise v0[0], v1[0], ..., v0[1], v1[1], ... */ /* With colwise storage, vj[i] = data[ j*size + i] With rowwise storage, vj[i] = data[ j + num_vectors*i] */ HYPRE_Int vecstride, idxstride; /* ... so vj[i] = data[ j*vecstride + i*idxstride ] regardless of row_storage.*/ } hypre_Vector; /*-------------------------------------------------------------------------- * Accessor functions for the Vector structure *--------------------------------------------------------------------------*/ #define hypre_VectorData(vector) ((vector) -> data) #define hypre_VectorSize(vector) ((vector) -> size) #define hypre_VectorOwnsData(vector) ((vector) -> owns_data) #define hypre_VectorNumVectors(vector) ((vector) -> num_vectors) #define hypre_VectorMultiVecStorageMethod(vector) ((vector) -> multivec_storage_method) #define hypre_VectorVectorStride(vector) ((vector) -> vecstride ) #define hypre_VectorIndexStride(vector) ((vector) -> idxstride ) #endif
2,725
41.59375
87
h
AMG
AMG-master/utilities/HYPRE_error_f.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ c Copyright (c) 2008, Lawrence Livermore National Security, LLC. c Produced at the Lawrence Livermore National Laboratory. c This file is part of HYPRE. See file COPYRIGHT for details. c c HYPRE is free software; you can redistribute it and/or modify it under the c terms of the GNU Lesser General Public License (as published by the Free c Software Foundation) version 2.1 dated February 1999. c c $Revision$ integer HYPRE_ERROR_GENERIC integer HYPRE_ERROR_MEMORY integer HYPRE_ERROR_ARG integer HYPRE_ERROR_CONV parameter (HYPRE_ERROR_GENERIC = 1) parameter (HYPRE_ERROR_MEMORY = 2) parameter (HYPRE_ERROR_ARG = 4) parameter (HYPRE_ERROR_CONV = 256)
1,635
45.742857
81
h
AMG
AMG-master/utilities/HYPRE_utilities.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header file for HYPRE_utilities library * *****************************************************************************/ #include "HYPRE.h" #ifndef HYPRE_UTILITIES_HEADER #define HYPRE_UTILITIES_HEADER #ifndef HYPRE_SEQUENTIAL #include "mpi.h" #endif #ifdef HYPRE_USING_OPENMP #include <omp.h> #endif #ifdef __cplusplus extern "C" { #endif /* * Before a version of HYPRE goes out the door, increment the version * number and check in this file (for CVS to substitute the Date). */ #define HYPRE_Version() "HYPRE_RELEASE_NAME Date Compiled: " __DATE__ " " __TIME__ /*-------------------------------------------------------------------------- * Real and Complex types *--------------------------------------------------------------------------*/ #include <float.h> #if defined(HYPRE_SINGLE) typedef float HYPRE_Real; #define HYPRE_REAL_MAX FLT_MAX #define HYPRE_REAL_MIN FLT_MIN #define HYPRE_REAL_EPSILON FLT_EPSILON #define HYPRE_REAL_MIN_EXP FLT_MIN_EXP #define HYPRE_MPI_REAL MPI_FLOAT #elif defined(HYPRE_LONG_DOUBLE) typedef long double HYPRE_Real; #define HYPRE_REAL_MAX LDBL_MAX #define HYPRE_REAL_MIN LDBL_MIN #define HYPRE_REAL_EPSILON LDBL_EPSILON #define HYPRE_REAL_MIN_EXP DBL_MIN_EXP #define HYPRE_MPI_REAL MPI_LONG_DOUBLE #else /* default */ typedef double HYPRE_Real; #define HYPRE_REAL_MAX DBL_MAX #define HYPRE_REAL_MIN DBL_MIN #define HYPRE_REAL_EPSILON DBL_EPSILON #define HYPRE_REAL_MIN_EXP DBL_MIN_EXP #define HYPRE_MPI_REAL MPI_DOUBLE #endif #if defined(HYPRE_COMPLEX) typedef double _Complex HYPRE_Complex; #define HYPRE_MPI_COMPLEX MPI_C_DOUBLE_COMPLEX /* or MPI_LONG_DOUBLE ? */ #else /* default */ typedef HYPRE_Real HYPRE_Complex; #define HYPRE_MPI_COMPLEX HYPRE_MPI_REAL #endif /*-------------------------------------------------------------------------- * Sequential MPI stuff *--------------------------------------------------------------------------*/ #ifdef HYPRE_SEQUENTIAL typedef HYPRE_Int MPI_Comm; #endif /*-------------------------------------------------------------------------- * HYPRE error codes *--------------------------------------------------------------------------*/ #define HYPRE_ERROR_GENERIC 1 /* generic error */ #define HYPRE_ERROR_MEMORY 2 /* unable to allocate memory */ #define HYPRE_ERROR_ARG 4 /* argument error */ /* bits 4-8 are reserved for the index of the argument error */ #define HYPRE_ERROR_CONV 256 /* method did not converge as expected */ /*-------------------------------------------------------------------------- * HYPRE error user functions *--------------------------------------------------------------------------*/ /* Return the current hypre error flag */ HYPRE_Int HYPRE_GetError(); /* Check if the given error flag contains the given error code */ HYPRE_Int HYPRE_CheckError(HYPRE_Int hypre_ierr, HYPRE_Int hypre_error_code); /* Return the index of the argument (counting from 1) where argument error (HYPRE_ERROR_ARG) has occured */ HYPRE_Int HYPRE_GetErrorArg(); /* Describe the given error flag in the given string */ void HYPRE_DescribeError(HYPRE_Int hypre_ierr, char *descr); /* Clears the hypre error flag */ HYPRE_Int HYPRE_ClearAllErrors(); /* Clears the given error code from the hypre error flag */ HYPRE_Int HYPRE_ClearError(HYPRE_Int hypre_error_code); /*-------------------------------------------------------------------------- * HYPRE AP user functions *--------------------------------------------------------------------------*/ /*Checks whether the AP is on */ HYPRE_Int HYPRE_AssumedPartitionCheck(); #ifdef __cplusplus } #endif #endif
4,644
32.178571
82
h
AMG
AMG-master/utilities/_hypre_utilities.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef hypre_UTILITIES_HEADER #define hypre_UTILITIES_HEADER #include "HYPRE_utilities.h" #ifdef HYPRE_USING_OPENMP #include <omp.h> #endif /* This allows us to consistently avoid 'int' throughout hypre */ typedef int hypre_int; typedef long int hypre_longint; typedef unsigned int hypre_uint; typedef unsigned long int hypre_ulongint; /* This allows us to consistently avoid 'double' throughout hypre */ typedef double hypre_double; #ifdef __cplusplus extern "C" { #endif /****************************************************************************** * * General structures and values * *****************************************************************************/ #ifndef hypre_GENERAL_HEADER #define hypre_GENERAL_HEADER /*-------------------------------------------------------------------------- * Define various functions *--------------------------------------------------------------------------*/ #ifndef hypre_max #define hypre_max(a,b) (((a)<(b)) ? (b) : (a)) #endif #ifndef hypre_min #define hypre_min(a,b) (((a)<(b)) ? (a) : (b)) #endif #ifndef hypre_abs #define hypre_abs(a) (((a)>0) ? (a) : -(a)) #endif #ifndef hypre_round #define hypre_round(x) ( ((x) < 0.0) ? ((HYPRE_Int)(x - 0.5)) : ((HYPRE_Int)(x + 0.5)) ) #endif #ifndef hypre_pow2 #define hypre_pow2(i) ( 1 << (i) ) #endif #endif /****************************************************************************** * * Fake mpi stubs to generate serial codes without mpi * *****************************************************************************/ #ifndef hypre_MPISTUBS #define hypre_MPISTUBS #ifdef __cplusplus extern "C" { #endif #ifdef HYPRE_SEQUENTIAL /****************************************************************************** * MPI stubs to generate serial codes without mpi *****************************************************************************/ /*-------------------------------------------------------------------------- * Change all MPI names to hypre_MPI names to avoid link conflicts. * * NOTE: MPI_Comm is the only MPI symbol in the HYPRE user interface, * and is defined in `HYPRE_utilities.h'. *--------------------------------------------------------------------------*/ #define MPI_Comm hypre_MPI_Comm #define MPI_Group hypre_MPI_Group #define MPI_Request hypre_MPI_Request #define MPI_Datatype hypre_MPI_Datatype #define MPI_Status hypre_MPI_Status #define MPI_Op hypre_MPI_Op #define MPI_Aint hypre_MPI_Aint #define MPI_COMM_WORLD hypre_MPI_COMM_WORLD #define MPI_COMM_NULL hypre_MPI_COMM_NULL #define MPI_COMM_SELF hypre_MPI_COMM_SELF #define MPI_BOTTOM hypre_MPI_BOTTOM #define MPI_FLOAT hypre_MPI_FLOAT #define MPI_DOUBLE hypre_MPI_DOUBLE #define MPI_LONG_DOUBLE hypre_MPI_LONG_DOUBLE #define MPI_INT hypre_MPI_INT #define MPI_LONG_LONG_INT hypre_MPI_INT #define MPI_CHAR hypre_MPI_CHAR #define MPI_LONG hypre_MPI_LONG #define MPI_BYTE hypre_MPI_BYTE #define MPI_C_DOUBLE_COMPLEX hypre_MPI_COMPLEX #define MPI_SUM hypre_MPI_SUM #define MPI_MIN hypre_MPI_MIN #define MPI_MAX hypre_MPI_MAX #define MPI_LOR hypre_MPI_LOR #define MPI_SUCCESS hypre_MPI_SUCCESS #define MPI_STATUSES_IGNORE hypre_MPI_STATUSES_IGNORE #define MPI_UNDEFINED hypre_MPI_UNDEFINED #define MPI_REQUEST_NULL hypre_MPI_REQUEST_NULL #define MPI_ANY_SOURCE hypre_MPI_ANY_SOURCE #define MPI_ANY_TAG hypre_MPI_ANY_TAG #define MPI_SOURCE hypre_MPI_SOURCE #define MPI_TAG hypre_MPI_TAG #define MPI_Init hypre_MPI_Init #define MPI_Finalize hypre_MPI_Finalize #define MPI_Abort hypre_MPI_Abort #define MPI_Wtime hypre_MPI_Wtime #define MPI_Wtick hypre_MPI_Wtick #define MPI_Barrier hypre_MPI_Barrier #define MPI_Comm_create hypre_MPI_Comm_create #define MPI_Comm_dup hypre_MPI_Comm_dup #define MPI_Comm_f2c hypre_MPI_Comm_f2c #define MPI_Comm_group hypre_MPI_Comm_group #define MPI_Comm_size hypre_MPI_Comm_size #define MPI_Comm_rank hypre_MPI_Comm_rank #define MPI_Comm_free hypre_MPI_Comm_free #define MPI_Comm_split hypre_MPI_Comm_split #define MPI_Group_incl hypre_MPI_Group_incl #define MPI_Group_free hypre_MPI_Group_free #define MPI_Address hypre_MPI_Address #define MPI_Get_count hypre_MPI_Get_count #define MPI_Alltoall hypre_MPI_Alltoall #define MPI_Allgather hypre_MPI_Allgather #define MPI_Allgatherv hypre_MPI_Allgatherv #define MPI_Gather hypre_MPI_Gather #define MPI_Gatherv hypre_MPI_Gatherv #define MPI_Scatter hypre_MPI_Scatter #define MPI_Scatterv hypre_MPI_Scatterv #define MPI_Bcast hypre_MPI_Bcast #define MPI_Send hypre_MPI_Send #define MPI_Recv hypre_MPI_Recv #define MPI_Isend hypre_MPI_Isend #define MPI_Irecv hypre_MPI_Irecv #define MPI_Send_init hypre_MPI_Send_init #define MPI_Recv_init hypre_MPI_Recv_init #define MPI_Irsend hypre_MPI_Irsend #define MPI_Startall hypre_MPI_Startall #define MPI_Probe hypre_MPI_Probe #define MPI_Iprobe hypre_MPI_Iprobe #define MPI_Test hypre_MPI_Test #define MPI_Testall hypre_MPI_Testall #define MPI_Wait hypre_MPI_Wait #define MPI_Waitall hypre_MPI_Waitall #define MPI_Waitany hypre_MPI_Waitany #define MPI_Allreduce hypre_MPI_Allreduce #define MPI_Reduce hypre_MPI_Reduce #define MPI_Scan hypre_MPI_Scan #define MPI_Request_free hypre_MPI_Request_free #define MPI_Type_contiguous hypre_MPI_Type_contiguous #define MPI_Type_vector hypre_MPI_Type_vector #define MPI_Type_hvector hypre_MPI_Type_hvector #define MPI_Type_struct hypre_MPI_Type_struct #define MPI_Type_commit hypre_MPI_Type_commit #define MPI_Type_free hypre_MPI_Type_free #define MPI_Op_free hypre_MPI_Op_free #define MPI_Op_create hypre_MPI_Op_create #define MPI_User_function hypre_MPI_User_function /*-------------------------------------------------------------------------- * Types, etc. *--------------------------------------------------------------------------*/ /* These types have associated creation and destruction routines */ typedef HYPRE_Int hypre_MPI_Comm; typedef HYPRE_Int hypre_MPI_Group; typedef HYPRE_Int hypre_MPI_Request; typedef HYPRE_Int hypre_MPI_Datatype; typedef void (hypre_MPI_User_function) (); typedef struct { HYPRE_Int hypre_MPI_SOURCE; HYPRE_Int hypre_MPI_TAG; } hypre_MPI_Status; typedef HYPRE_Int hypre_MPI_Op; typedef HYPRE_Int hypre_MPI_Aint; #define hypre_MPI_COMM_SELF 1 #define hypre_MPI_COMM_WORLD 0 #define hypre_MPI_COMM_NULL -1 #define hypre_MPI_BOTTOM 0x0 #define hypre_MPI_FLOAT 0 #define hypre_MPI_DOUBLE 1 #define hypre_MPI_LONG_DOUBLE 2 #define hypre_MPI_INT 3 #define hypre_MPI_CHAR 4 #define hypre_MPI_LONG 5 #define hypre_MPI_BYTE 6 #define hypre_MPI_REAL 7 #define hypre_MPI_COMPLEX 8 #define hypre_MPI_SUM 0 #define hypre_MPI_MIN 1 #define hypre_MPI_MAX 2 #define hypre_MPI_LOR 3 #define hypre_MPI_SUCCESS 0 #define hypre_MPI_STATUSES_IGNORE 0 #define hypre_MPI_UNDEFINED -9999 #define hypre_MPI_REQUEST_NULL 0 #define hypre_MPI_ANY_SOURCE 1 #define hypre_MPI_ANY_TAG 1 #else /****************************************************************************** * MPI stubs to do casting of HYPRE_Int and hypre_int correctly *****************************************************************************/ typedef MPI_Comm hypre_MPI_Comm; typedef MPI_Group hypre_MPI_Group; typedef MPI_Request hypre_MPI_Request; typedef MPI_Datatype hypre_MPI_Datatype; typedef MPI_Status hypre_MPI_Status; typedef MPI_Op hypre_MPI_Op; typedef MPI_Aint hypre_MPI_Aint; typedef MPI_User_function hypre_MPI_User_function; #define hypre_MPI_COMM_WORLD MPI_COMM_WORLD #define hypre_MPI_COMM_NULL MPI_COMM_NULL #define hypre_MPI_BOTTOM MPI_BOTTOM #define hypre_MPI_COMM_SELF MPI_COMM_SELF #define hypre_MPI_FLOAT MPI_FLOAT #define hypre_MPI_DOUBLE MPI_DOUBLE #define hypre_MPI_LONG_DOUBLE MPI_LONG_DOUBLE /* HYPRE_MPI_INT is defined in HYPRE_utilities.h */ #define hypre_MPI_INT HYPRE_MPI_INT #define hypre_MPI_CHAR MPI_CHAR #define hypre_MPI_LONG MPI_LONG #define hypre_MPI_BYTE MPI_BYTE /* HYPRE_MPI_REAL is defined in HYPRE_utilities.h */ #define hypre_MPI_REAL HYPRE_MPI_REAL /* HYPRE_MPI_COMPLEX is defined in HYPRE_utilities.h */ #define hypre_MPI_COMPLEX HYPRE_MPI_COMPLEX #define hypre_MPI_SUM MPI_SUM #define hypre_MPI_MIN MPI_MIN #define hypre_MPI_MAX MPI_MAX #define hypre_MPI_LOR MPI_LOR #define hypre_MPI_SUCCESS MPI_SUCCESS #define hypre_MPI_STATUSES_IGNORE MPI_STATUSES_IGNORE #define hypre_MPI_UNDEFINED MPI_UNDEFINED #define hypre_MPI_REQUEST_NULL MPI_REQUEST_NULL #define hypre_MPI_ANY_SOURCE MPI_ANY_SOURCE #define hypre_MPI_ANY_TAG MPI_ANY_TAG #define hypre_MPI_SOURCE MPI_SOURCE #define hypre_MPI_TAG MPI_TAG #define hypre_MPI_LAND MPI_LAND #endif /****************************************************************************** * Everything below this applies to both ifdef cases above *****************************************************************************/ /*-------------------------------------------------------------------------- * Prototypes *--------------------------------------------------------------------------*/ /* mpistubs.c */ HYPRE_Int hypre_MPI_Init( hypre_int *argc , char ***argv ); HYPRE_Int hypre_MPI_Finalize( void ); HYPRE_Int hypre_MPI_Abort( hypre_MPI_Comm comm , HYPRE_Int errorcode ); HYPRE_Real hypre_MPI_Wtime( void ); HYPRE_Real hypre_MPI_Wtick( void ); HYPRE_Int hypre_MPI_Barrier( hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Comm_create( hypre_MPI_Comm comm , hypre_MPI_Group group , hypre_MPI_Comm *newcomm ); HYPRE_Int hypre_MPI_Comm_dup( hypre_MPI_Comm comm , hypre_MPI_Comm *newcomm ); hypre_MPI_Comm hypre_MPI_Comm_f2c( hypre_int comm ); HYPRE_Int hypre_MPI_Comm_size( hypre_MPI_Comm comm , HYPRE_Int *size ); HYPRE_Int hypre_MPI_Comm_rank( hypre_MPI_Comm comm , HYPRE_Int *rank ); HYPRE_Int hypre_MPI_Comm_free( hypre_MPI_Comm *comm ); HYPRE_Int hypre_MPI_Comm_group( hypre_MPI_Comm comm , hypre_MPI_Group *group ); HYPRE_Int hypre_MPI_Comm_split( hypre_MPI_Comm comm, HYPRE_Int n, HYPRE_Int m, hypre_MPI_Comm * comms ); HYPRE_Int hypre_MPI_Group_incl( hypre_MPI_Group group , HYPRE_Int n , HYPRE_Int *ranks , hypre_MPI_Group *newgroup ); HYPRE_Int hypre_MPI_Group_free( hypre_MPI_Group *group ); HYPRE_Int hypre_MPI_Address( void *location , hypre_MPI_Aint *address ); HYPRE_Int hypre_MPI_Get_count( hypre_MPI_Status *status , hypre_MPI_Datatype datatype , HYPRE_Int *count ); HYPRE_Int hypre_MPI_Alltoall( void *sendbuf , HYPRE_Int sendcount , hypre_MPI_Datatype sendtype , void *recvbuf , HYPRE_Int recvcount , hypre_MPI_Datatype recvtype , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Allgather( void *sendbuf , HYPRE_Int sendcount , hypre_MPI_Datatype sendtype , void *recvbuf , HYPRE_Int recvcount , hypre_MPI_Datatype recvtype , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Allgatherv( void *sendbuf , HYPRE_Int sendcount , hypre_MPI_Datatype sendtype , void *recvbuf , HYPRE_Int *recvcounts , HYPRE_Int *displs , hypre_MPI_Datatype recvtype , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Gather( void *sendbuf , HYPRE_Int sendcount , hypre_MPI_Datatype sendtype , void *recvbuf , HYPRE_Int recvcount , hypre_MPI_Datatype recvtype , HYPRE_Int root , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Gatherv( void *sendbuf , HYPRE_Int sendcount , hypre_MPI_Datatype sendtype , void *recvbuf , HYPRE_Int *recvcounts , HYPRE_Int *displs , hypre_MPI_Datatype recvtype , HYPRE_Int root , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Scatter( void *sendbuf , HYPRE_Int sendcount , hypre_MPI_Datatype sendtype , void *recvbuf , HYPRE_Int recvcount , hypre_MPI_Datatype recvtype , HYPRE_Int root , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Scatterv( void *sendbuf , HYPRE_Int *sendcounts , HYPRE_Int *displs, hypre_MPI_Datatype sendtype , void *recvbuf , HYPRE_Int recvcount , hypre_MPI_Datatype recvtype , HYPRE_Int root , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Bcast( void *buffer , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int root , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Send( void *buf , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int dest , HYPRE_Int tag , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Recv( void *buf , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int source , HYPRE_Int tag , hypre_MPI_Comm comm , hypre_MPI_Status *status ); HYPRE_Int hypre_MPI_Isend( void *buf , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int dest , HYPRE_Int tag , hypre_MPI_Comm comm , hypre_MPI_Request *request ); HYPRE_Int hypre_MPI_Irecv( void *buf , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int source , HYPRE_Int tag , hypre_MPI_Comm comm , hypre_MPI_Request *request ); HYPRE_Int hypre_MPI_Send_init( void *buf , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int dest , HYPRE_Int tag , hypre_MPI_Comm comm , hypre_MPI_Request *request ); HYPRE_Int hypre_MPI_Recv_init( void *buf , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int dest , HYPRE_Int tag , hypre_MPI_Comm comm , hypre_MPI_Request *request ); HYPRE_Int hypre_MPI_Irsend( void *buf , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int dest , HYPRE_Int tag , hypre_MPI_Comm comm , hypre_MPI_Request *request ); HYPRE_Int hypre_MPI_Startall( HYPRE_Int count , hypre_MPI_Request *array_of_requests ); HYPRE_Int hypre_MPI_Probe( HYPRE_Int source , HYPRE_Int tag , hypre_MPI_Comm comm , hypre_MPI_Status *status ); HYPRE_Int hypre_MPI_Iprobe( HYPRE_Int source , HYPRE_Int tag , hypre_MPI_Comm comm , HYPRE_Int *flag , hypre_MPI_Status *status ); HYPRE_Int hypre_MPI_Test( hypre_MPI_Request *request , HYPRE_Int *flag , hypre_MPI_Status *status ); HYPRE_Int hypre_MPI_Testall( HYPRE_Int count , hypre_MPI_Request *array_of_requests , HYPRE_Int *flag , hypre_MPI_Status *array_of_statuses ); HYPRE_Int hypre_MPI_Wait( hypre_MPI_Request *request , hypre_MPI_Status *status ); HYPRE_Int hypre_MPI_Waitall( HYPRE_Int count , hypre_MPI_Request *array_of_requests , hypre_MPI_Status *array_of_statuses ); HYPRE_Int hypre_MPI_Waitany( HYPRE_Int count , hypre_MPI_Request *array_of_requests , HYPRE_Int *index , hypre_MPI_Status *status ); HYPRE_Int hypre_MPI_Allreduce( void *sendbuf , void *recvbuf , HYPRE_Int count , hypre_MPI_Datatype datatype , hypre_MPI_Op op , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Reduce( void *sendbuf , void *recvbuf , HYPRE_Int count , hypre_MPI_Datatype datatype , hypre_MPI_Op op , HYPRE_Int root , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Scan( void *sendbuf , void *recvbuf , HYPRE_Int count , hypre_MPI_Datatype datatype , hypre_MPI_Op op , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Request_free( hypre_MPI_Request *request ); HYPRE_Int hypre_MPI_Type_contiguous( HYPRE_Int count , hypre_MPI_Datatype oldtype , hypre_MPI_Datatype *newtype ); HYPRE_Int hypre_MPI_Type_vector( HYPRE_Int count , HYPRE_Int blocklength , HYPRE_Int stride , hypre_MPI_Datatype oldtype , hypre_MPI_Datatype *newtype ); HYPRE_Int hypre_MPI_Type_hvector( HYPRE_Int count , HYPRE_Int blocklength , hypre_MPI_Aint stride , hypre_MPI_Datatype oldtype , hypre_MPI_Datatype *newtype ); HYPRE_Int hypre_MPI_Type_struct( HYPRE_Int count , HYPRE_Int *array_of_blocklengths , hypre_MPI_Aint *array_of_displacements , hypre_MPI_Datatype *array_of_types , hypre_MPI_Datatype *newtype ); HYPRE_Int hypre_MPI_Type_commit( hypre_MPI_Datatype *datatype ); HYPRE_Int hypre_MPI_Type_free( hypre_MPI_Datatype *datatype ); HYPRE_Int hypre_MPI_Op_free( hypre_MPI_Op *op ); HYPRE_Int hypre_MPI_Op_create( hypre_MPI_User_function *function , hypre_int commute , hypre_MPI_Op *op ); #ifdef __cplusplus } #endif #endif #ifndef HYPRE_SMP_HEADER #define HYPRE_SMP_HEADER #endif #define HYPRE_SMP_SCHEDULE schedule(static) /****************************************************************************** * * Header file for memory management utilities * *****************************************************************************/ #ifndef hypre_MEMORY_HEADER #define hypre_MEMORY_HEADER #include <stdio.h> #include <stdlib.h> #ifdef __cplusplus extern "C" { #endif /*-------------------------------------------------------------------------- * Use "Debug Malloc Library", dmalloc *--------------------------------------------------------------------------*/ #ifdef HYPRE_MEMORY_DMALLOC #define hypre_InitMemoryDebug(id) hypre_InitMemoryDebugDML(id) #define hypre_FinalizeMemoryDebug() hypre_FinalizeMemoryDebugDML() #define hypre_TAlloc(type, count) \ ( (type *)hypre_MAllocDML((size_t)(sizeof(type) * (count)),\ __FILE__, __LINE__) ) #define hypre_CTAlloc(type, count) \ ( (type *)hypre_CAllocDML((size_t)(count), (size_t)sizeof(type),\ __FILE__, __LINE__) ) #define hypre_TReAlloc(ptr, type, count) \ ( (type *)hypre_ReAllocDML((char *)ptr,\ (size_t)(sizeof(type) * (count)),\ __FILE__, __LINE__) ) #define hypre_TFree(ptr) \ ( hypre_FreeDML((char *)ptr, __FILE__, __LINE__), ptr = NULL ) /*-------------------------------------------------------------------------- * Use standard memory routines *--------------------------------------------------------------------------*/ #else #define hypre_InitMemoryDebug(id) #define hypre_FinalizeMemoryDebug() #define hypre_TAlloc(type, count) \ ( (type *)hypre_MAlloc((size_t)(sizeof(type) * (count))) ) #define hypre_CTAlloc(type, count) \ ( (type *)hypre_CAlloc((size_t)(count), (size_t)sizeof(type)) ) #define hypre_TReAlloc(ptr, type, count) \ ( (type *)hypre_ReAlloc((char *)ptr, (size_t)(sizeof(type) * (count))) ) #define hypre_TFree(ptr) \ ( hypre_Free((char *)ptr), ptr = NULL ) #endif #define hypre_SharedTAlloc(type, count) hypre_TAlloc(type, (count)) #define hypre_SharedCTAlloc(type, count) hypre_CTAlloc(type, (count)) #define hypre_SharedTReAlloc(type, count) hypre_TReAlloc(type, (count)) #define hypre_SharedTFree(ptr) hypre_TFree(ptr) /*-------------------------------------------------------------------------- * Prototypes *--------------------------------------------------------------------------*/ /* hypre_memory.c */ HYPRE_Int hypre_OutOfMemory ( size_t size ); char *hypre_MAlloc ( size_t size ); char *hypre_CAlloc ( size_t count , size_t elt_size ); char *hypre_ReAlloc ( char *ptr , size_t size ); void hypre_Free ( char *ptr ); char *hypre_SharedMAlloc ( size_t size ); char *hypre_SharedCAlloc ( size_t count , size_t elt_size ); char *hypre_SharedReAlloc ( char *ptr , size_t size ); void hypre_SharedFree ( char *ptr ); HYPRE_Real *hypre_IncrementSharedDataPtr ( HYPRE_Real *ptr , size_t size ); /* memory_dmalloc.c */ HYPRE_Int hypre_InitMemoryDebugDML( HYPRE_Int id ); HYPRE_Int hypre_FinalizeMemoryDebugDML( void ); char *hypre_MAllocDML( HYPRE_Int size , char *file , HYPRE_Int line ); char *hypre_CAllocDML( HYPRE_Int count , HYPRE_Int elt_size , char *file , HYPRE_Int line ); char *hypre_ReAllocDML( char *ptr , HYPRE_Int size , char *file , HYPRE_Int line ); void hypre_FreeDML( char *ptr , char *file , HYPRE_Int line ); #ifdef __cplusplus } #endif #endif #ifndef hypre_THREADING_HEADER #define hypre_THREADING_HEADER #ifdef HYPRE_USING_OPENMP HYPRE_Int hypre_NumThreads( void ); HYPRE_Int hypre_NumActiveThreads( void ); HYPRE_Int hypre_GetThreadNum( void ); #else #define hypre_NumThreads() 1 #define hypre_NumActiveThreads() 1 #define hypre_GetThreadNum() 0 #endif void hypre_GetSimpleThreadPartition( HYPRE_Int *begin, HYPRE_Int *end, HYPRE_Int n ); #endif /****************************************************************************** * * Header file for doing timing * *****************************************************************************/ #ifndef HYPRE_TIMING_HEADER #define HYPRE_TIMING_HEADER #include <stdlib.h> #include <stdio.h> #include <string.h> #ifdef __cplusplus extern "C" { #endif /*-------------------------------------------------------------------------- * Prototypes for low-level timing routines *--------------------------------------------------------------------------*/ /* timer.c */ HYPRE_Real time_getWallclockSeconds( void ); HYPRE_Real time_getCPUSeconds( void ); HYPRE_Real time_get_wallclock_seconds_( void ); HYPRE_Real time_get_cpu_seconds_( void ); /*-------------------------------------------------------------------------- * With timing off *--------------------------------------------------------------------------*/ #ifndef HYPRE_TIMING #define hypre_InitializeTiming(name) 0 #define hypre_FinalizeTiming(index) #define hypre_IncFLOPCount(inc) #define hypre_BeginTiming(i) #define hypre_EndTiming(i) #define hypre_PrintTiming(heading, wall_time, comm) #define hypre_ClearTiming() /*-------------------------------------------------------------------------- * With timing on *--------------------------------------------------------------------------*/ #else /*------------------------------------------------------- * Global timing structure *-------------------------------------------------------*/ typedef struct { HYPRE_Real *wall_time; HYPRE_Real *cpu_time; HYPRE_Real *flops; char **name; HYPRE_Int *state; /* boolean flag to allow for recursive timing */ HYPRE_Int *num_regs; /* count of how many times a name is registered */ HYPRE_Int num_names; HYPRE_Int size; HYPRE_Real wall_count; HYPRE_Real CPU_count; HYPRE_Real FLOP_count; } hypre_TimingType; #ifdef HYPRE_TIMING_GLOBALS hypre_TimingType *hypre_global_timing = NULL; #else extern hypre_TimingType *hypre_global_timing; #endif /*------------------------------------------------------- * Accessor functions *-------------------------------------------------------*/ #define hypre_TimingWallTime(i) (hypre_global_timing -> wall_time[(i)]) #define hypre_TimingCPUTime(i) (hypre_global_timing -> cpu_time[(i)]) #define hypre_TimingFLOPS(i) (hypre_global_timing -> flops[(i)]) #define hypre_TimingName(i) (hypre_global_timing -> name[(i)]) #define hypre_TimingState(i) (hypre_global_timing -> state[(i)]) #define hypre_TimingNumRegs(i) (hypre_global_timing -> num_regs[(i)]) #define hypre_TimingWallCount (hypre_global_timing -> wall_count) #define hypre_TimingCPUCount (hypre_global_timing -> CPU_count) #define hypre_TimingFLOPCount (hypre_global_timing -> FLOP_count) /*------------------------------------------------------- * Prototypes *-------------------------------------------------------*/ /* timing.c */ HYPRE_Int hypre_InitializeTiming( const char *name ); HYPRE_Int hypre_FinalizeTiming( HYPRE_Int time_index ); HYPRE_Int hypre_IncFLOPCount( HYPRE_Int inc ); HYPRE_Int hypre_BeginTiming( HYPRE_Int time_index ); HYPRE_Int hypre_EndTiming( HYPRE_Int time_index ); HYPRE_Int hypre_ClearTiming( void ); HYPRE_Int hypre_PrintTiming( const char *heading , HYPRE_Real *wall_time , MPI_Comm comm ); #endif #ifdef __cplusplus } #endif #endif /****************************************************************************** * * Header file link lists * *****************************************************************************/ #ifndef HYPRE_LINKLIST_HEADER #define HYPRE_LINKLIST_HEADER #include <stdlib.h> #include <stdio.h> #include <string.h> #ifdef __cplusplus extern "C" { #endif #define LIST_HEAD -1 #define LIST_TAIL -2 struct double_linked_list { HYPRE_Int data; struct double_linked_list *next_elt; struct double_linked_list *prev_elt; HYPRE_Int head; HYPRE_Int tail; }; typedef struct double_linked_list hypre_ListElement; typedef hypre_ListElement *hypre_LinkList; #ifdef __cplusplus } #endif #endif #ifndef hypre_EXCHANGE_DATA_HEADER #define hypre_EXCHANGE_DATA_HEADER #define hypre_BinaryTreeParentId(tree) (tree->parent_id) #define hypre_BinaryTreeNumChild(tree) (tree->num_child) #define hypre_BinaryTreeChildIds(tree) (tree->child_id) #define hypre_BinaryTreeChildId(tree, i) (tree->child_id[i]) typedef struct { HYPRE_Int parent_id; HYPRE_Int num_child; HYPRE_Int *child_id; } hypre_BinaryTree; /* In the fill_response() function the user needs to set the recv__buf and the response_message_size. Memory of size send_response_storage has been alllocated for the send_buf (in exchange_data) - if more is needed, then realloc and adjust the send_response_storage. The realloc amount should be storage+overhead. If the response is an empty "confirmation" message, then set response_message_size =0 (and do not modify the send_buf) */ typedef struct { HYPRE_Int (*fill_response)(void* recv_buf, HYPRE_Int contact_size, HYPRE_Int contact_proc, void* response_obj, MPI_Comm comm, void** response_buf, HYPRE_Int* response_message_size); HYPRE_Int send_response_overhead; /*set by exchange data */ HYPRE_Int send_response_storage; /*storage allocated for send_response_buf*/ void *data1; /*data fields user may want to access in fill_response */ void *data2; } hypre_DataExchangeResponse; HYPRE_Int hypre_CreateBinaryTree(HYPRE_Int, HYPRE_Int, hypre_BinaryTree*); HYPRE_Int hypre_DestroyBinaryTree(hypre_BinaryTree*); HYPRE_Int hypre_DataExchangeList(HYPRE_Int num_contacts, HYPRE_Int *contact_proc_list, void *contact_send_buf, HYPRE_Int *contact_send_buf_starts, HYPRE_Int contact_obj_size, HYPRE_Int response_obj_size, hypre_DataExchangeResponse *response_obj, HYPRE_Int max_response_size, HYPRE_Int rnum, MPI_Comm comm, void **p_response_recv_buf, HYPRE_Int **p_response_recv_buf_starts); #endif /* end of header */ #ifndef hypre_ERROR_HEADER #define hypre_ERROR_HEADER /*-------------------------------------------------------------------------- * Global variable used in hypre error checking *--------------------------------------------------------------------------*/ extern HYPRE_Int hypre__global_error; #define hypre_error_flag hypre__global_error /*-------------------------------------------------------------------------- * HYPRE error macros *--------------------------------------------------------------------------*/ void hypre_error_handler(const char *filename, HYPRE_Int line, HYPRE_Int ierr, const char *msg); #define hypre_error(IERR) hypre_error_handler(__FILE__, __LINE__, IERR, NULL) #define hypre_error_w_msg(IERR, msg) hypre_error_handler(__FILE__, __LINE__, IERR, msg) #define hypre_error_in_arg(IARG) hypre_error(HYPRE_ERROR_ARG | IARG<<3) #ifdef NDEBUG #define hypre_assert(EX) #else #define hypre_assert(EX) if (!(EX)) {hypre_fprintf(stderr,"hypre_assert failed: %s\n", #EX); hypre_error(1);} #endif #endif /****************************************************************************** * * Header file for Caliper instrumentation macros * *****************************************************************************/ /* #ifndef CALIPER_INSTRUMENTATION_HEADER #define CALIPER_INSTRUMENTATION_HEADER #include "HYPRE_config.h" #ifdef HYPRE_USING_CALIPER #include <caliper/cali.h> #define HYPRE_ANNOTATION_BEGIN( str ) cali_begin_string_byname("hypre.kernel", str) #define HYPRE_ANNOTATION_END( str ) cali_end_byname("hypre.kernel") #else #define HYPRE_ANNOTATION_BEGIN( str ) #define HYPRE_ANNOTATION_END( str ) #endif #endif *//* CALIPER_INSTRUMENTATION_HEADER */ /* amg_linklist.c */ void hypre_dispose_elt ( hypre_LinkList element_ptr ); void hypre_remove_point ( hypre_LinkList *LoL_head_ptr , hypre_LinkList *LoL_tail_ptr , HYPRE_Int measure , HYPRE_Int index , HYPRE_Int *lists , HYPRE_Int *where ); hypre_LinkList hypre_create_elt ( HYPRE_Int Item ); void hypre_enter_on_lists ( hypre_LinkList *LoL_head_ptr , hypre_LinkList *LoL_tail_ptr , HYPRE_Int measure , HYPRE_Int index , HYPRE_Int *lists , HYPRE_Int *where ); HYPRE_Int hypre_BinarySearch ( HYPRE_Int *list , HYPRE_Int value , HYPRE_Int list_length ); HYPRE_Int hypre_BinarySearch2 ( HYPRE_Int *list , HYPRE_Int value , HYPRE_Int low , HYPRE_Int high , HYPRE_Int *spot ); HYPRE_Int *hypre_LowerBound( HYPRE_Int *first, HYPRE_Int *last, HYPRE_Int value ); /* hypre_complex.c */ #ifdef HYPRE_COMPLEX HYPRE_Complex hypre_conj( HYPRE_Complex value ); HYPRE_Real hypre_cabs( HYPRE_Complex value ); HYPRE_Real hypre_creal( HYPRE_Complex value ); HYPRE_Real hypre_cimag( HYPRE_Complex value ); #else #define hypre_conj(value) value #define hypre_cabs(value) fabs(value) #define hypre_creal(value) value #define hypre_cimag(value) 0.0 #endif /* hypre_printf.c */ // #ifdef HYPRE_BIGINT HYPRE_Int hypre_printf( const char *format , ... ); HYPRE_Int hypre_fprintf( FILE *stream , const char *format, ... ); HYPRE_Int hypre_sprintf( char *s , const char *format, ... ); HYPRE_Int hypre_scanf( const char *format , ... ); HYPRE_Int hypre_fscanf( FILE *stream , const char *format, ... ); HYPRE_Int hypre_sscanf( char *s , const char *format, ... ); // #else // #define hypre_printf printf // #define hypre_fprintf fprintf // #define hypre_sprintf sprintf // #define hypre_scanf scanf // #define hypre_fscanf fscanf // #define hypre_sscanf sscanf // #endif /* hypre_qsort.c */ void hypre_swap ( HYPRE_Int *v , HYPRE_Int i , HYPRE_Int j ); void hypre_swap2 ( HYPRE_Int *v , HYPRE_Real *w , HYPRE_Int i , HYPRE_Int j ); void hypre_swap2i ( HYPRE_Int *v , HYPRE_Int *w , HYPRE_Int i , HYPRE_Int j ); void hypre_swap3i ( HYPRE_Int *v , HYPRE_Int *w , HYPRE_Int *z , HYPRE_Int i , HYPRE_Int j ); void hypre_swap3_d ( HYPRE_Real *v , HYPRE_Int *w , HYPRE_Int *z , HYPRE_Int i , HYPRE_Int j ); void hypre_swap4_d ( HYPRE_Real *v , HYPRE_Int *w , HYPRE_Int *z , HYPRE_Int *y , HYPRE_Int i , HYPRE_Int j ); void hypre_swap_d ( HYPRE_Real *v , HYPRE_Int i , HYPRE_Int j ); void hypre_qsort0 ( HYPRE_Int *v , HYPRE_Int left , HYPRE_Int right ); void hypre_qsort1 ( HYPRE_Int *v , HYPRE_Real *w , HYPRE_Int left , HYPRE_Int right ); void hypre_qsort2i ( HYPRE_Int *v , HYPRE_Int *w , HYPRE_Int left , HYPRE_Int right ); void hypre_qsort2 ( HYPRE_Int *v , HYPRE_Real *w , HYPRE_Int left , HYPRE_Int right ); void hypre_qsort3i ( HYPRE_Int *v , HYPRE_Int *w , HYPRE_Int *z , HYPRE_Int left , HYPRE_Int right ); void hypre_qsort3_abs ( HYPRE_Real *v , HYPRE_Int *w , HYPRE_Int *z , HYPRE_Int left , HYPRE_Int right ); void hypre_qsort4_abs ( HYPRE_Real *v , HYPRE_Int *w , HYPRE_Int *z , HYPRE_Int *y , HYPRE_Int left , HYPRE_Int right ); void hypre_qsort_abs ( HYPRE_Real *w , HYPRE_Int left , HYPRE_Int right ); /* qsplit.c */ HYPRE_Int hypre_DoubleQuickSplit ( HYPRE_Real *values , HYPRE_Int *indices , HYPRE_Int list_length , HYPRE_Int NumberKept ); /* random.c */ void hypre_SeedRand ( HYPRE_Int seed ); HYPRE_Int hypre_RandI ( void ); HYPRE_Real hypre_Rand ( void ); /* hypre_prefix_sum.c */ /** * Assumed to be called within an omp region. * Let x_i be the input of ith thread. * The output of ith thread y_i = x_0 + x_1 + ... + x_{i-1} * Additionally, sum = x_0 + x_1 + ... + x_{nthreads - 1} * Note that always y_0 = 0 * * @param workspace at least with length (nthreads+1) * workspace[tid] will contain result for tid * workspace[nthreads] will contain sum */ void hypre_prefix_sum(HYPRE_Int *in_out, HYPRE_Int *sum, HYPRE_Int *workspace); /** * This version does prefix sum in pair. * Useful when we prefix sum of diag and offd in tandem. * * @param worksapce at least with length 2*(nthreads+1) * workspace[2*tid] and workspace[2*tid+1] will contain results for tid * workspace[3*nthreads] and workspace[3*nthreads + 1] will contain sums */ void hypre_prefix_sum_pair(HYPRE_Int *in_out1, HYPRE_Int *sum1, HYPRE_Int *in_out2, HYPRE_Int *sum2, HYPRE_Int *workspace); /** * @param workspace at least with length 3*(nthreads+1) * workspace[3*tid:3*tid+3) will contain results for tid */ void hypre_prefix_sum_triple(HYPRE_Int *in_out1, HYPRE_Int *sum1, HYPRE_Int *in_out2, HYPRE_Int *sum2, HYPRE_Int *in_out3, HYPRE_Int *sum3, HYPRE_Int *workspace); /** * n prefix-sums together. * workspace[n*tid:n*(tid+1)) will contain results for tid * workspace[nthreads*tid:nthreads*(tid+1)) will contain sums * * @param workspace at least with length n*(nthreads+1) */ void hypre_prefix_sum_multiple(HYPRE_Int *in_out, HYPRE_Int *sum, HYPRE_Int n, HYPRE_Int *workspace); /* hypre_merge_sort.c */ /** * Why merge sort? * 1) Merge sort can take advantage of eliminating duplicates. * 2) Merge sort is more efficiently parallelizable than qsort */ /** * Out of place merge sort with duplicate elimination * @ret number of unique elements */ HYPRE_Int hypre_merge_sort_unique(HYPRE_Int *in, HYPRE_Int *out, HYPRE_Int len); /** * Out of place merge sort with duplicate elimination * * @param out pointer to output can be in or temp * @ret number of unique elements */ HYPRE_Int hypre_merge_sort_unique2(HYPRE_Int *in, HYPRE_Int *temp, HYPRE_Int len, HYPRE_Int **out); void hypre_merge_sort(HYPRE_Int *in, HYPRE_Int *temp, HYPRE_Int len, HYPRE_Int **sorted); /* hypre_hopscotch_hash.c */ #ifdef HYPRE_USING_OPENMP /* Check if atomic operations are available to use concurrent hopscotch hash table */ #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) && (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100 #define HYPRE_USING_ATOMIC //#elif defined _MSC_VER // JSP: haven't tested, so comment out for now //#define HYPRE_USING_ATOMIC //#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__) // JSP: not many compilers have implemented this, so comment out for now //#define HYPRE_USING_ATOMIC //#include <stdatomic.h> #endif #endif // HYPRE_USING_OPENMP #ifdef HYPRE_HOPSCOTCH #ifdef HYPRE_USING_ATOMIC // concurrent hopscotch hashing is possible only with atomic supports #define HYPRE_CONCURRENT_HOPSCOTCH #endif #endif #ifdef HYPRE_CONCURRENT_HOPSCOTCH typedef struct { HYPRE_Int volatile timestamp; omp_lock_t lock; } hypre_HopscotchSegment; #endif /** * The current typical use case of unordered set is putting input sequence * with lots of duplication (putting all colidx received from other ranks), * followed by one sweep of enumeration. * Since the capacity is set to the number of inputs, which is much larger * than the number of unique elements, we optimize for initialization and * enumeration whose time is proportional to the capacity. * For initialization and enumeration, structure of array (SoA) is better * for vectorization, cache line utilization, and so on. */ typedef struct { HYPRE_Int volatile segmentMask; HYPRE_Int volatile bucketMask; #ifdef HYPRE_CONCURRENT_HOPSCOTCH hypre_HopscotchSegment* volatile segments; #endif HYPRE_Int *volatile key; hypre_uint *volatile hopInfo; HYPRE_Int *volatile hash; } hypre_UnorderedIntSet; typedef struct { hypre_uint volatile hopInfo; HYPRE_Int volatile hash; HYPRE_Int volatile key; HYPRE_Int volatile data; } hypre_HopscotchBucket; /** * The current typical use case of unoredered map is putting input sequence * with no duplication (inverse map of a bijective mapping) followed by * lots of lookups. * For lookup, array of structure (AoS) gives better cache line utilization. */ typedef struct { HYPRE_Int volatile segmentMask; HYPRE_Int volatile bucketMask; #ifdef HYPRE_CONCURRENT_HOPSCOTCH hypre_HopscotchSegment* volatile segments; #endif hypre_HopscotchBucket* volatile table; } hypre_UnorderedIntMap; /** * Sort array "in" with length len and put result in array "out" * "in" will be deallocated unless in == *out * inverse_map is an inverse hash table s.t. inverse_map[i] = j iff (*out)[j] = i */ void hypre_sort_and_create_inverse_map( HYPRE_Int *in, HYPRE_Int len, HYPRE_Int **out, hypre_UnorderedIntMap *inverse_map); #ifdef __cplusplus } #endif #endif
45,750
41.089236
226
h
AMG
AMG-master/utilities/amg_linklist.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header file link lists * *****************************************************************************/ #ifndef HYPRE_LINKLIST_HEADER #define HYPRE_LINKLIST_HEADER #include <stdlib.h> #include <stdio.h> #include <string.h> #ifdef __cplusplus extern "C" { #endif struct double_linked_list { HYPRE_Int data; struct double_linked_list *next_elt; struct double_linked_list *prev_elt; HYPRE_Int head; HYPRE_Int tail; }; typedef struct double_linked_list hypre_ListElement; typedef hypre_ListElement *hypre_LinkList; #ifdef __cplusplus } #endif #endif
1,674
30.603774
81
h
AMG
AMG-master/utilities/caliper_instrumentation.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header file for Caliper instrumentation macros * *****************************************************************************/ #ifndef CALIPER_INSTRUMENTATION_HEADER #define CALIPER_INSTRUMENTATION_HEADER #include "HYPRE_config.h" #ifdef HYPRE_USING_CALIPER #include <caliper/cali.h> #define HYPRE_ANNOTATION_BEGIN( str ) cali_begin_string_byname("hypre.kernel", str) #define HYPRE_ANNOTATION_END( str ) cali_end_byname("hypre.kernel") #else #define HYPRE_ANNOTATION_BEGIN( str ) #define HYPRE_ANNOTATION_END( str ) #endif #endif /* CALIPER_INSTRUMENTATION_HEADER */
1,593
34.422222
83
h
AMG
AMG-master/utilities/exchange_data.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef hypre_EXCHANGE_DATA_HEADER #define hypre_EXCHANGE_DATA_HEADER #define hypre_BinaryTreeParentId(tree) (tree->parent_id) #define hypre_BinaryTreeNumChild(tree) (tree->num_child) #define hypre_BinaryTreeChildIds(tree) (tree->child_id) #define hypre_BinaryTreeChildId(tree, i) (tree->child_id[i]) typedef struct { HYPRE_Int parent_id; HYPRE_Int num_child; HYPRE_Int *child_id; } hypre_BinaryTree; /* In the fill_response() function the user needs to set the recv__buf and the response_message_size. Memory of size send_response_storage has been alllocated for the send_buf (in exchange_data) - if more is needed, then realloc and adjust the send_response_storage. The realloc amount should be storage+overhead. If the response is an empty "confirmation" message, then set response_message_size =0 (and do not modify the send_buf) */ typedef struct { HYPRE_Int (*fill_response)(void* recv_buf, HYPRE_Int contact_size, HYPRE_Int contact_proc, void* response_obj, MPI_Comm comm, void** response_buf, HYPRE_Int* response_message_size); HYPRE_Int send_response_overhead; /*set by exchange data */ HYPRE_Int send_response_storage; /*storage allocated for send_response_buf*/ void *data1; /*data fields user may want to access in fill_response */ void *data2; } hypre_DataExchangeResponse; HYPRE_Int hypre_CreateBinaryTree(HYPRE_Int, HYPRE_Int, hypre_BinaryTree*); HYPRE_Int hypre_DestroyBinaryTree(hypre_BinaryTree*); HYPRE_Int hypre_DataExchangeList(HYPRE_Int num_contacts, HYPRE_Int *contact_proc_list, void *contact_send_buf, HYPRE_Int *contact_send_buf_starts, HYPRE_Int contact_obj_size, HYPRE_Int response_obj_size, hypre_DataExchangeResponse *response_obj, HYPRE_Int max_response_size, HYPRE_Int rnum, MPI_Comm comm, void **p_response_recv_buf, HYPRE_Int **p_response_recv_buf_starts); #endif /* end of header */
3,071
44.850746
92
h
AMG
AMG-master/utilities/general.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * General structures and values * *****************************************************************************/ #ifndef hypre_GENERAL_HEADER #define hypre_GENERAL_HEADER /* This allows us to consistently avoid 'int' throughout hypre */ typedef int hypre_int; typedef long int hypre_longint; typedef unsigned int hypre_uint; typedef unsigned long int hypre_ulongint; /* This allows us to consistently avoid 'double' throughout hypre */ typedef double hypre_double; /*-------------------------------------------------------------------------- * Define various functions *--------------------------------------------------------------------------*/ #ifndef hypre_max #define hypre_max(a,b) (((a)<(b)) ? (b) : (a)) #endif #ifndef hypre_min #define hypre_min(a,b) (((a)<(b)) ? (a) : (b)) #endif #ifndef hypre_abs #define hypre_abs(a) (((a)>0) ? (a) : -(a)) #endif #ifndef hypre_round #define hypre_round(x) ( ((x) < 0.0) ? ((HYPRE_Int)(x - 0.5)) : ((HYPRE_Int)(x + 0.5)) ) #endif #ifndef hypre_pow2 #define hypre_pow2(i) ( 1 << (i) ) #endif #endif
2,111
33.622951
89
h
AMG
AMG-master/utilities/hypre_error.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef hypre_ERROR_HEADER #define hypre_ERROR_HEADER /*-------------------------------------------------------------------------- * Global variable used in hypre error checking *--------------------------------------------------------------------------*/ extern HYPRE_Int hypre__global_error; #define hypre_error_flag hypre__global_error /*-------------------------------------------------------------------------- * HYPRE error macros *--------------------------------------------------------------------------*/ void hypre_error_handler(const char *filename, HYPRE_Int line, HYPRE_Int ierr, const char *msg); #define hypre_error(IERR) hypre_error_handler(__FILE__, __LINE__, IERR, NULL) #define hypre_error_w_msg(IERR, msg) hypre_error_handler(__FILE__, __LINE__, IERR, msg) #define hypre_error_in_arg(IARG) hypre_error(HYPRE_ERROR_ARG | IARG<<3) #ifdef NDEBUG #define hypre_assert(EX) #else #define hypre_assert(EX) if (!(EX)) {hypre_fprintf(stderr,"hypre_assert failed: %s\n", #EX); hypre_error(1);} #endif #endif
1,958
43.522727
109
h
AMG
AMG-master/utilities/hypre_hopscotch_hash.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /** * Hopscotch hash is modified from the code downloaded from * https://sites.google.com/site/cconcurrencypackage/hopscotch-hashing * with the following terms of usage */ //////////////////////////////////////////////////////////////////////////////// //TERMS OF USAGE //------------------------------------------------------------------------------ // // Permission to use, copy, modify and distribute this software and // its documentation for any purpose is hereby granted without fee, // provided that due acknowledgments to the authors are provided and // this permission notice appears in all copies of the software. // The software is provided "as is". There is no warranty of any kind. // //Authors: // Maurice Herlihy // Brown University // and // Nir Shavit // Tel-Aviv University // and // Moran Tzafrir // Tel-Aviv University // // Date: July 15, 2008. // //////////////////////////////////////////////////////////////////////////////// // Programmer : Moran Tzafrir ([email protected]) // Modified : Jongsoo Park ([email protected]) // Oct 1, 2015. // //////////////////////////////////////////////////////////////////////////////// #ifndef hypre_HOPSCOTCH_HASH_HEADER #define hypre_HOPSCOTCH_HASH_HEADER #include <stdio.h> #include <limits.h> #include <assert.h> #include <math.h> #ifdef HYPRE_USING_OPENMP #include <omp.h> #endif #include "_hypre_utilities.h" // Potentially architecture specific features used here: // __builtin_ffs // __sync_val_compare_and_swap #ifdef __cplusplus extern "C" { #endif /****************************************************************************** * This next section of code is here instead of in _hypre_utilities.h to get * around some portability issues with Visual Studio. By putting it here, we * can explicitly include this '.h' file in a few files in hypre and compile * them with C++ instead of C (VS does not support C99 'inline'). ******************************************************************************/ #ifdef HYPRE_USING_ATOMIC static inline HYPRE_Int hypre_compare_and_swap(HYPRE_Int *ptr, HYPRE_Int oldval, HYPRE_Int newval) { #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) && (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100 return __sync_val_compare_and_swap(ptr, oldval, newval); //#elif defind _MSC_VER //return _InterlockedCompareExchange((long *)ptr, newval, oldval); //#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__) // JSP: not many compilers have implemented this, so comment out for now //_Atomic HYPRE_Int *atomic_ptr = ptr; //atomic_compare_exchange_strong(atomic_ptr, &oldval, newval); //return oldval; #endif } static inline HYPRE_Int hypre_fetch_and_add(HYPRE_Int *ptr, HYPRE_Int value) { #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) && (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100 return __sync_fetch_and_add(ptr, value); //#elif defined _MSC_VER //return _InterlockedExchangeAdd((long *)ptr, value); //#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__) // JSP: not many compilers have implemented this, so comment out for now //_Atomic HYPRE_Int *atomic_ptr = ptr; //return atomic_fetch_add(atomic_ptr, value); #endif } #else // !HYPRE_USING_ATOMIC static inline HYPRE_Int hypre_compare_and_swap(HYPRE_Int *ptr, HYPRE_Int oldval, HYPRE_Int newval) { if (*ptr == oldval) { *ptr = newval; return oldval; } else return *ptr; } static inline HYPRE_Int hypre_fetch_and_add(HYPRE_Int *ptr, HYPRE_Int value) { HYPRE_Int oldval = *ptr; *ptr += value; return oldval; } #endif // !HYPRE_USING_ATOMIC /******************************************************************************/ // Constants ................................................................ #define HYPRE_HOPSCOTCH_HASH_HOP_RANGE (32) #define HYPRE_HOPSCOTCH_HASH_INSERT_RANGE (4*1024) #define HYPRE_HOPSCOTCH_HASH_EMPTY (0) #define HYPRE_HOPSCOTCH_HASH_BUSY (1) // Small Utilities .......................................................... #ifdef HYPRE_CONCURRENT_HOPSCOTCH static inline HYPRE_Int first_lsb_bit_indx(hypre_uint x) { if (0 == x) return -1; return __builtin_ffs(x) - 1; } #endif /** * hypre_Hash is adapted from xxHash with the following license. */ /* xxHash - Extremely Fast Hash algorithm Header File Copyright (C) 2012-2015, Yann Collet. BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT OWNER 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. You can contact the author at : - xxHash source repository : https://github.com/Cyan4973/xxHash */ /*************************************** * Constants ***************************************/ #define HYPRE_XXH_PRIME32_1 2654435761U #define HYPRE_XXH_PRIME32_2 2246822519U #define HYPRE_XXH_PRIME32_3 3266489917U #define HYPRE_XXH_PRIME32_4 668265263U #define HYPRE_XXH_PRIME32_5 374761393U #define HYPRE_XXH_PRIME64_1 11400714785074694791ULL #define HYPRE_XXH_PRIME64_2 14029467366897019727ULL #define HYPRE_XXH_PRIME64_3 1609587929392839161ULL #define HYPRE_XXH_PRIME64_4 9650029242287828579ULL #define HYPRE_XXH_PRIME64_5 2870177450012600261ULL # define HYPRE_XXH_rotl32(x,r) ((x << r) | (x >> (32 - r))) # define HYPRE_XXH_rotl64(x,r) ((x << r) | (x >> (64 - r))) #ifdef HYPRE_BIGINT static inline HYPRE_Int hypre_Hash(HYPRE_Int input) { hypre_ulongint h64 = HYPRE_XXH_PRIME64_5 + sizeof(input); hypre_ulongint k1 = input; k1 *= HYPRE_XXH_PRIME64_2; k1 = HYPRE_XXH_rotl64(k1, 31); k1 *= HYPRE_XXH_PRIME64_1; h64 ^= k1; h64 = HYPRE_XXH_rotl64(h64, 27)*HYPRE_XXH_PRIME64_1 + HYPRE_XXH_PRIME64_4; h64 ^= h64 >> 33; h64 *= HYPRE_XXH_PRIME64_2; h64 ^= h64 >> 29; h64 *= HYPRE_XXH_PRIME64_3; h64 ^= h64 >> 32; #ifndef NDEBUG if (HYPRE_HOPSCOTCH_HASH_EMPTY == h64) { hypre_printf("hash(%lld) = %d\n", h64, HYPRE_HOPSCOTCH_HASH_EMPTY); assert(HYPRE_HOPSCOTCH_HASH_EMPTY != h64); } #endif return h64; } #else static inline HYPRE_Int hypre_Hash(HYPRE_Int input) { hypre_uint h32 = HYPRE_XXH_PRIME32_5 + sizeof(input); // 1665863975 is added to input so that // only -1073741824 gives HYPRE_HOPSCOTCH_HASH_EMPTY. // Hence, we're fine as long as key is non-negative. h32 += (input + 1665863975)*HYPRE_XXH_PRIME32_3; h32 = HYPRE_XXH_rotl32(h32, 17)*HYPRE_XXH_PRIME32_4; h32 ^= h32 >> 15; h32 *= HYPRE_XXH_PRIME32_2; h32 ^= h32 >> 13; h32 *= HYPRE_XXH_PRIME32_3; h32 ^= h32 >> 16; //assert(HYPRE_HOPSCOTCH_HASH_EMPTY != h32); return h32; } #endif static inline void hypre_UnorderedIntSetFindCloserFreeBucket( hypre_UnorderedIntSet *s, #ifdef HYPRE_CONCURRENT_HOPSCOTCH hypre_HopscotchSegment* start_seg, #endif HYPRE_Int *free_bucket, HYPRE_Int *free_dist ) { HYPRE_Int move_bucket = *free_bucket - (HYPRE_HOPSCOTCH_HASH_HOP_RANGE - 1); HYPRE_Int move_free_dist; for (move_free_dist = HYPRE_HOPSCOTCH_HASH_HOP_RANGE - 1; move_free_dist > 0; --move_free_dist) { hypre_uint start_hop_info = s->hopInfo[move_bucket]; HYPRE_Int move_new_free_dist = -1; hypre_uint mask = 1; HYPRE_Int i; for (i = 0; i < move_free_dist; ++i, mask <<= 1) { if (mask & start_hop_info) { move_new_free_dist = i; break; } } if (-1 != move_new_free_dist) { #ifdef HYPRE_CONCURRENT_HOPSCOTCH hypre_HopscotchSegment* move_segment = &(s->segments[move_bucket & s->segmentMask]); if(start_seg != move_segment) omp_set_lock(&move_segment->lock); #endif if (start_hop_info == s->hopInfo[move_bucket]) { // new_free_bucket -> free_bucket and empty new_free_bucket HYPRE_Int new_free_bucket = move_bucket + move_new_free_dist; s->key[*free_bucket] = s->key[new_free_bucket]; s->hash[*free_bucket] = s->hash[new_free_bucket]; #ifdef HYPRE_CONCURRENT_HOPSCOTCH ++move_segment->timestamp; #pragma omp flush #endif s->hopInfo[move_bucket] |= (1U << move_free_dist); s->hopInfo[move_bucket] &= ~(1U << move_new_free_dist); *free_bucket = new_free_bucket; *free_dist -= move_free_dist - move_new_free_dist; #ifdef HYPRE_CONCURRENT_HOPSCOTCH if(start_seg != move_segment) omp_unset_lock(&move_segment->lock); #endif return; } #ifdef HYPRE_CONCURRENT_HOPSCOTCH if(start_seg != move_segment) omp_unset_lock(&move_segment->lock); #endif } ++move_bucket; } *free_bucket = -1; *free_dist = 0; } static inline void hypre_UnorderedIntMapFindCloserFreeBucket( hypre_UnorderedIntMap *m, #ifdef HYPRE_CONCURRENT_HOPSCOTCH hypre_HopscotchSegment* start_seg, #endif hypre_HopscotchBucket** free_bucket, HYPRE_Int* free_dist) { hypre_HopscotchBucket* move_bucket = *free_bucket - (HYPRE_HOPSCOTCH_HASH_HOP_RANGE - 1); HYPRE_Int move_free_dist; for (move_free_dist = HYPRE_HOPSCOTCH_HASH_HOP_RANGE - 1; move_free_dist > 0; --move_free_dist) { hypre_uint start_hop_info = move_bucket->hopInfo; HYPRE_Int move_new_free_dist = -1; hypre_uint mask = 1; HYPRE_Int i; for (i = 0; i < move_free_dist; ++i, mask <<= 1) { if (mask & start_hop_info) { move_new_free_dist = i; break; } } if (-1 != move_new_free_dist) { #ifdef HYPRE_CONCURRENT_HOPSCOTCH hypre_HopscotchSegment* move_segment = &(m->segments[(move_bucket - m->table) & m->segmentMask]); if (start_seg != move_segment) omp_set_lock(&move_segment->lock); #endif if (start_hop_info == move_bucket->hopInfo) { // new_free_bucket -> free_bucket and empty new_free_bucket hypre_HopscotchBucket* new_free_bucket = move_bucket + move_new_free_dist; (*free_bucket)->data = new_free_bucket->data; (*free_bucket)->key = new_free_bucket->key; (*free_bucket)->hash = new_free_bucket->hash; #ifdef HYPRE_CONCURRENT_HOPSCOTCH ++move_segment->timestamp; #pragma omp flush #endif move_bucket->hopInfo |= (1U << move_free_dist); move_bucket->hopInfo &= ~(1U << move_new_free_dist); *free_bucket = new_free_bucket; *free_dist -= move_free_dist - move_new_free_dist; #ifdef HYPRE_CONCURRENT_HOPSCOTCH if(start_seg != move_segment) omp_unset_lock(&move_segment->lock); #endif return; } #ifdef HYPRE_CONCURRENT_HOPSCOTCH if(start_seg != move_segment) omp_unset_lock(&move_segment->lock); #endif } ++move_bucket; } *free_bucket = NULL; *free_dist = 0; } void hypre_UnorderedIntSetCreate( hypre_UnorderedIntSet *s, HYPRE_Int inCapacity, HYPRE_Int concurrencyLevel); void hypre_UnorderedIntMapCreate( hypre_UnorderedIntMap *m, HYPRE_Int inCapacity, HYPRE_Int concurrencyLevel); void hypre_UnorderedIntSetDestroy( hypre_UnorderedIntSet *s ); void hypre_UnorderedIntMapDestroy( hypre_UnorderedIntMap *m ); // Query Operations ......................................................... #ifdef HYPRE_CONCURRENT_HOPSCOTCH static inline HYPRE_Int hypre_UnorderedIntSetContains( hypre_UnorderedIntSet *s, HYPRE_Int key ) { //CALCULATE HASH .......................... HYPRE_Int hash = hypre_Hash(key); //CHECK IF ALREADY CONTAIN ................ hypre_HopscotchSegment *segment = &s->segments[hash & s->segmentMask]; HYPRE_Int bucket = hash & s->bucketMask; hypre_uint hopInfo = s->hopInfo[bucket]; if (0 == hopInfo) return 0; else if (1 == hopInfo ) { if (hash == s->hash[bucket] && key == s->key[bucket]) return 1; else return 0; } HYPRE_Int startTimestamp = segment->timestamp; while (0 != hopInfo) { HYPRE_Int i = first_lsb_bit_indx(hopInfo); HYPRE_Int currElm = bucket + i; if (hash == s->hash[currElm] && key == s->key[currElm]) return 1; hopInfo &= ~(1U << i); } if (segment->timestamp == startTimestamp) return 0; HYPRE_Int i; for (i = 0; i< HYPRE_HOPSCOTCH_HASH_HOP_RANGE; ++i) { if (hash == s->hash[bucket + i] && key == s->key[bucket + i]) return 1; } return 0; } /** * @ret -1 if key doesn't exist */ static inline HYPRE_Int hypre_UnorderedIntMapGet( hypre_UnorderedIntMap *m, HYPRE_Int key) { //CALCULATE HASH .......................... HYPRE_Int hash = hypre_Hash(key); //CHECK IF ALREADY CONTAIN ................ hypre_HopscotchSegment *segment = &m->segments[hash & m->segmentMask]; hypre_HopscotchBucket *elmAry = &(m->table[hash & m->bucketMask]); hypre_uint hopInfo = elmAry->hopInfo; if (0 == hopInfo) return -1; else if (1 == hopInfo ) { if (hash == elmAry->hash && key == elmAry->key) return elmAry->data; else return -1; } HYPRE_Int startTimestamp = segment->timestamp; while (0 != hopInfo) { HYPRE_Int i = first_lsb_bit_indx(hopInfo); hypre_HopscotchBucket* currElm = elmAry + i; if (hash == currElm->hash && key == currElm->key) return currElm->data; hopInfo &= ~(1U << i); } if (segment->timestamp == startTimestamp) return -1; hypre_HopscotchBucket *currBucket = &(m->table[hash & m->bucketMask]); HYPRE_Int i; for (i = 0; i< HYPRE_HOPSCOTCH_HASH_HOP_RANGE; ++i, ++currBucket) { if (hash == currBucket->hash && key == currBucket->key) return currBucket->data; } return -1; } #endif //status Operations ......................................................... static inline HYPRE_Int hypre_UnorderedIntSetSize(hypre_UnorderedIntSet *s) { HYPRE_Int counter = 0; HYPRE_Int n = s->bucketMask + HYPRE_HOPSCOTCH_HASH_INSERT_RANGE; HYPRE_Int i; for (i = 0; i < n; ++i) { if (HYPRE_HOPSCOTCH_HASH_EMPTY != s->hash[i]) { ++counter; } } return counter; } static inline HYPRE_Int hypre_UnorderedIntMapSize(hypre_UnorderedIntMap *m) { HYPRE_Int counter = 0; HYPRE_Int n = m->bucketMask + HYPRE_HOPSCOTCH_HASH_INSERT_RANGE; HYPRE_Int i; for (i = 0; i < n; ++i) { if( HYPRE_HOPSCOTCH_HASH_EMPTY != m->table[i].hash ) { ++counter; } } return counter; } HYPRE_Int *hypre_UnorderedIntSetCopyToArray( hypre_UnorderedIntSet *s, HYPRE_Int *len ); //modification Operations ................................................... #ifdef HYPRE_CONCURRENT_HOPSCOTCH static inline void hypre_UnorderedIntSetPut( hypre_UnorderedIntSet *s, HYPRE_Int key ) { //CALCULATE HASH .......................... HYPRE_Int hash = hypre_Hash(key); //LOCK KEY HASH ENTERY .................... hypre_HopscotchSegment *segment = &s->segments[hash & s->segmentMask]; omp_set_lock(&segment->lock); HYPRE_Int bucket = hash&s->bucketMask; //CHECK IF ALREADY CONTAIN ................ hypre_uint hopInfo = s->hopInfo[bucket]; while (0 != hopInfo) { HYPRE_Int i = first_lsb_bit_indx(hopInfo); HYPRE_Int currElm = bucket + i; if(hash == s->hash[currElm] && key == s->key[currElm]) { omp_unset_lock(&segment->lock); return; } hopInfo &= ~(1U << i); } //LOOK FOR FREE BUCKET .................... HYPRE_Int free_bucket = bucket; HYPRE_Int free_dist = 0; for ( ; free_dist < HYPRE_HOPSCOTCH_HASH_INSERT_RANGE; ++free_dist, ++free_bucket) { if( (HYPRE_HOPSCOTCH_HASH_EMPTY == s->hash[free_bucket]) && (HYPRE_HOPSCOTCH_HASH_EMPTY == hypre_compare_and_swap((HYPRE_Int *)&s->hash[free_bucket], (HYPRE_Int)HYPRE_HOPSCOTCH_HASH_EMPTY, (HYPRE_Int)HYPRE_HOPSCOTCH_HASH_BUSY)) ) break; } //PLACE THE NEW KEY ....................... if (free_dist < HYPRE_HOPSCOTCH_HASH_INSERT_RANGE) { do { if (free_dist < HYPRE_HOPSCOTCH_HASH_HOP_RANGE) { s->key[free_bucket] = key; s->hash[free_bucket] = hash; s->hopInfo[bucket] |= 1U << free_dist; omp_unset_lock(&segment->lock); return; } hypre_UnorderedIntSetFindCloserFreeBucket(s, segment, &free_bucket, &free_dist); } while (-1 != free_bucket); } //NEED TO RESIZE .......................... hypre_error_w_msg(HYPRE_ERROR_GENERIC,"ERROR - RESIZE is not implemented\n"); /*fprintf(stderr, "ERROR - RESIZE is not implemented\n");*/ exit(1); return; } static inline HYPRE_Int hypre_UnorderedIntMapPutIfAbsent( hypre_UnorderedIntMap *m, HYPRE_Int key, HYPRE_Int data) { //CALCULATE HASH .......................... HYPRE_Int hash = hypre_Hash(key); //LOCK KEY HASH ENTERY .................... hypre_HopscotchSegment *segment = &m->segments[hash & m->segmentMask]; omp_set_lock(&segment->lock); hypre_HopscotchBucket* startBucket = &(m->table[hash & m->bucketMask]); //CHECK IF ALREADY CONTAIN ................ hypre_uint hopInfo = startBucket->hopInfo; while (0 != hopInfo) { HYPRE_Int i = first_lsb_bit_indx(hopInfo); hypre_HopscotchBucket* currElm = startBucket + i; if (hash == currElm->hash && key == currElm->key) { HYPRE_Int rc = currElm->data; omp_unset_lock(&segment->lock); return rc; } hopInfo &= ~(1U << i); } //LOOK FOR FREE BUCKET .................... hypre_HopscotchBucket* free_bucket = startBucket; HYPRE_Int free_dist = 0; for ( ; free_dist < HYPRE_HOPSCOTCH_HASH_INSERT_RANGE; ++free_dist, ++free_bucket) { if( (HYPRE_HOPSCOTCH_HASH_EMPTY == free_bucket->hash) && (HYPRE_HOPSCOTCH_HASH_EMPTY == __sync_val_compare_and_swap((HYPRE_Int *)&free_bucket->hash, (HYPRE_Int)HYPRE_HOPSCOTCH_HASH_EMPTY, (HYPRE_Int)HYPRE_HOPSCOTCH_HASH_BUSY)) ) break; } //PLACE THE NEW KEY ....................... if (free_dist < HYPRE_HOPSCOTCH_HASH_INSERT_RANGE) { do { if (free_dist < HYPRE_HOPSCOTCH_HASH_HOP_RANGE) { free_bucket->data = data; free_bucket->key = key; free_bucket->hash = hash; startBucket->hopInfo |= 1U << free_dist; omp_unset_lock(&segment->lock); return HYPRE_HOPSCOTCH_HASH_EMPTY; } hypre_UnorderedIntMapFindCloserFreeBucket(m, segment, &free_bucket, &free_dist); } while (NULL != free_bucket); } //NEED TO RESIZE .......................... hypre_error_w_msg(HYPRE_ERROR_GENERIC,"ERROR - RESIZE is not implemented\n"); /*fprintf(stderr, "ERROR - RESIZE is not implemented\n");*/ exit(1); return HYPRE_HOPSCOTCH_HASH_EMPTY; } #endif #ifdef __cplusplus } // extern "C" #endif #endif // hypre_HOPSCOTCH_HASH_HEADER
21,351
31.798771
233
h
AMG
AMG-master/utilities/hypre_memory.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header file for memory management utilities * *****************************************************************************/ #ifndef hypre_MEMORY_HEADER #define hypre_MEMORY_HEADER #include <stdio.h> #include <stdlib.h> #ifdef __cplusplus extern "C" { #endif /*-------------------------------------------------------------------------- * Use "Debug Malloc Library", dmalloc *--------------------------------------------------------------------------*/ #ifdef HYPRE_MEMORY_DMALLOC #define hypre_InitMemoryDebug(id) hypre_InitMemoryDebugDML(id) #define hypre_FinalizeMemoryDebug() hypre_FinalizeMemoryDebugDML() #define hypre_TAlloc(type, count) \ ( (type *)hypre_MAllocDML((size_t)(sizeof(type) * (count)),\ __FILE__, __LINE__) ) #define hypre_CTAlloc(type, count) \ ( (type *)hypre_CAllocDML((size_t)(count), (size_t)sizeof(type),\ __FILE__, __LINE__) ) #define hypre_TReAlloc(ptr, type, count) \ ( (type *)hypre_ReAllocDML((char *)ptr,\ (size_t)(sizeof(type) * (count)),\ __FILE__, __LINE__) ) #define hypre_TFree(ptr) \ ( hypre_FreeDML((char *)ptr, __FILE__, __LINE__), ptr = NULL ) /*-------------------------------------------------------------------------- * Use standard memory routines *--------------------------------------------------------------------------*/ #else #define hypre_InitMemoryDebug(id) #define hypre_FinalizeMemoryDebug() #define hypre_TAlloc(type, count) \ ( (type *)hypre_MAlloc((size_t)(sizeof(type) * (count))) ) #define hypre_CTAlloc(type, count) \ ( (type *)hypre_CAlloc((size_t)(count), (size_t)sizeof(type)) ) #define hypre_TReAlloc(ptr, type, count) \ ( (type *)hypre_ReAlloc((char *)ptr, (size_t)(sizeof(type) * (count))) ) #define hypre_TFree(ptr) \ ( hypre_Free((char *)ptr), ptr = NULL ) #endif #define hypre_SharedTAlloc(type, count) hypre_TAlloc(type, (count)) #define hypre_SharedCTAlloc(type, count) hypre_CTAlloc(type, (count)) #define hypre_SharedTReAlloc(type, count) hypre_TReAlloc(type, (count)) #define hypre_SharedTFree(ptr) hypre_TFree(ptr) /*-------------------------------------------------------------------------- * Prototypes *--------------------------------------------------------------------------*/ /* hypre_memory.c */ HYPRE_Int hypre_OutOfMemory ( size_t size ); char *hypre_MAlloc ( size_t size ); char *hypre_CAlloc ( size_t count , size_t elt_size ); char *hypre_ReAlloc ( char *ptr , size_t size ); void hypre_Free ( char *ptr ); char *hypre_SharedMAlloc ( size_t size ); char *hypre_SharedCAlloc ( size_t count , size_t elt_size ); char *hypre_SharedReAlloc ( char *ptr , size_t size ); void hypre_SharedFree ( char *ptr ); HYPRE_Real *hypre_IncrementSharedDataPtr ( HYPRE_Real *ptr , size_t size ); /* memory_dmalloc.c */ HYPRE_Int hypre_InitMemoryDebugDML( HYPRE_Int id ); HYPRE_Int hypre_FinalizeMemoryDebugDML( void ); char *hypre_MAllocDML( HYPRE_Int size , char *file , HYPRE_Int line ); char *hypre_CAllocDML( HYPRE_Int count , HYPRE_Int elt_size , char *file , HYPRE_Int line ); char *hypre_ReAllocDML( char *ptr , HYPRE_Int size , char *file , HYPRE_Int line ); void hypre_FreeDML( char *ptr , char *file , HYPRE_Int line ); #ifdef __cplusplus } #endif #endif
4,292
35.692308
92
h
AMG
AMG-master/utilities/hypre_smp.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef HYPRE_SMP_HEADER #define HYPRE_SMP_HEADER #endif #define HYPRE_SMP_SCHEDULE schedule(static)
1,028
41.875
81
h
AMG
AMG-master/utilities/mpistubs.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Fake mpi stubs to generate serial codes without mpi * *****************************************************************************/ #ifndef hypre_MPISTUBS #define hypre_MPISTUBS #ifdef __cplusplus extern "C" { #endif #ifdef HYPRE_SEQUENTIAL /****************************************************************************** * MPI stubs to generate serial codes without mpi *****************************************************************************/ /*-------------------------------------------------------------------------- * Change all MPI names to hypre_MPI names to avoid link conflicts. * * NOTE: MPI_Comm is the only MPI symbol in the HYPRE user interface, * and is defined in `HYPRE_utilities.h'. *--------------------------------------------------------------------------*/ #define MPI_Comm hypre_MPI_Comm #define MPI_Group hypre_MPI_Group #define MPI_Request hypre_MPI_Request #define MPI_Datatype hypre_MPI_Datatype #define MPI_Status hypre_MPI_Status #define MPI_Op hypre_MPI_Op #define MPI_Aint hypre_MPI_Aint #define MPI_COMM_WORLD hypre_MPI_COMM_WORLD #define MPI_COMM_NULL hypre_MPI_COMM_NULL #define MPI_COMM_SELF hypre_MPI_COMM_SELF #define MPI_BOTTOM hypre_MPI_BOTTOM #define MPI_FLOAT hypre_MPI_FLOAT #define MPI_DOUBLE hypre_MPI_DOUBLE #define MPI_LONG_DOUBLE hypre_MPI_LONG_DOUBLE #define MPI_INT hypre_MPI_INT #define MPI_LONG_LONG_INT hypre_MPI_INT #define MPI_CHAR hypre_MPI_CHAR #define MPI_LONG hypre_MPI_LONG #define MPI_BYTE hypre_MPI_BYTE #define MPI_C_DOUBLE_COMPLEX hypre_MPI_COMPLEX #define MPI_SUM hypre_MPI_SUM #define MPI_MIN hypre_MPI_MIN #define MPI_MAX hypre_MPI_MAX #define MPI_LOR hypre_MPI_LOR #define MPI_SUCCESS hypre_MPI_SUCCESS #define MPI_STATUSES_IGNORE hypre_MPI_STATUSES_IGNORE #define MPI_UNDEFINED hypre_MPI_UNDEFINED #define MPI_REQUEST_NULL hypre_MPI_REQUEST_NULL #define MPI_ANY_SOURCE hypre_MPI_ANY_SOURCE #define MPI_ANY_TAG hypre_MPI_ANY_TAG #define MPI_SOURCE hypre_MPI_SOURCE #define MPI_TAG hypre_MPI_TAG #define MPI_Init hypre_MPI_Init #define MPI_Finalize hypre_MPI_Finalize #define MPI_Abort hypre_MPI_Abort #define MPI_Wtime hypre_MPI_Wtime #define MPI_Wtick hypre_MPI_Wtick #define MPI_Barrier hypre_MPI_Barrier #define MPI_Comm_create hypre_MPI_Comm_create #define MPI_Comm_dup hypre_MPI_Comm_dup #define MPI_Comm_f2c hypre_MPI_Comm_f2c #define MPI_Comm_group hypre_MPI_Comm_group #define MPI_Comm_size hypre_MPI_Comm_size #define MPI_Comm_rank hypre_MPI_Comm_rank #define MPI_Comm_free hypre_MPI_Comm_free #define MPI_Comm_split hypre_MPI_Comm_split #define MPI_Group_incl hypre_MPI_Group_incl #define MPI_Group_free hypre_MPI_Group_free #define MPI_Address hypre_MPI_Address #define MPI_Get_count hypre_MPI_Get_count #define MPI_Alltoall hypre_MPI_Alltoall #define MPI_Allgather hypre_MPI_Allgather #define MPI_Allgatherv hypre_MPI_Allgatherv #define MPI_Gather hypre_MPI_Gather #define MPI_Gatherv hypre_MPI_Gatherv #define MPI_Scatter hypre_MPI_Scatter #define MPI_Scatterv hypre_MPI_Scatterv #define MPI_Bcast hypre_MPI_Bcast #define MPI_Send hypre_MPI_Send #define MPI_Recv hypre_MPI_Recv #define MPI_Isend hypre_MPI_Isend #define MPI_Irecv hypre_MPI_Irecv #define MPI_Send_init hypre_MPI_Send_init #define MPI_Recv_init hypre_MPI_Recv_init #define MPI_Irsend hypre_MPI_Irsend #define MPI_Startall hypre_MPI_Startall #define MPI_Probe hypre_MPI_Probe #define MPI_Iprobe hypre_MPI_Iprobe #define MPI_Test hypre_MPI_Test #define MPI_Testall hypre_MPI_Testall #define MPI_Wait hypre_MPI_Wait #define MPI_Waitall hypre_MPI_Waitall #define MPI_Waitany hypre_MPI_Waitany #define MPI_Allreduce hypre_MPI_Allreduce #define MPI_Reduce hypre_MPI_Reduce #define MPI_Scan hypre_MPI_Scan #define MPI_Request_free hypre_MPI_Request_free #define MPI_Type_contiguous hypre_MPI_Type_contiguous #define MPI_Type_vector hypre_MPI_Type_vector #define MPI_Type_hvector hypre_MPI_Type_hvector #define MPI_Type_struct hypre_MPI_Type_struct #define MPI_Type_commit hypre_MPI_Type_commit #define MPI_Type_free hypre_MPI_Type_free #define MPI_Op_free hypre_MPI_Op_free #define MPI_Op_create hypre_MPI_Op_create #define MPI_User_function hypre_MPI_User_function /*-------------------------------------------------------------------------- * Types, etc. *--------------------------------------------------------------------------*/ /* These types have associated creation and destruction routines */ typedef HYPRE_Int hypre_MPI_Comm; typedef HYPRE_Int hypre_MPI_Group; typedef HYPRE_Int hypre_MPI_Request; typedef HYPRE_Int hypre_MPI_Datatype; typedef void (hypre_MPI_User_function) (); typedef struct { HYPRE_Int hypre_MPI_SOURCE; HYPRE_Int hypre_MPI_TAG; } hypre_MPI_Status; typedef HYPRE_Int hypre_MPI_Op; typedef HYPRE_Int hypre_MPI_Aint; #define hypre_MPI_COMM_SELF 1 #define hypre_MPI_COMM_WORLD 0 #define hypre_MPI_COMM_NULL -1 #define hypre_MPI_BOTTOM 0x0 #define hypre_MPI_FLOAT 0 #define hypre_MPI_DOUBLE 1 #define hypre_MPI_LONG_DOUBLE 2 #define hypre_MPI_INT 3 #define hypre_MPI_CHAR 4 #define hypre_MPI_LONG 5 #define hypre_MPI_BYTE 6 #define hypre_MPI_REAL 7 #define hypre_MPI_COMPLEX 8 #define hypre_MPI_SUM 0 #define hypre_MPI_MIN 1 #define hypre_MPI_MAX 2 #define hypre_MPI_LOR 3 #define hypre_MPI_SUCCESS 0 #define hypre_MPI_STATUSES_IGNORE 0 #define hypre_MPI_UNDEFINED -9999 #define hypre_MPI_REQUEST_NULL 0 #define hypre_MPI_ANY_SOURCE 1 #define hypre_MPI_ANY_TAG 1 #else /****************************************************************************** * MPI stubs to do casting of HYPRE_Int and hypre_int correctly *****************************************************************************/ typedef MPI_Comm hypre_MPI_Comm; typedef MPI_Group hypre_MPI_Group; typedef MPI_Request hypre_MPI_Request; typedef MPI_Datatype hypre_MPI_Datatype; typedef MPI_Status hypre_MPI_Status; typedef MPI_Op hypre_MPI_Op; typedef MPI_Aint hypre_MPI_Aint; typedef MPI_User_function hypre_MPI_User_function; #define hypre_MPI_COMM_WORLD MPI_COMM_WORLD #define hypre_MPI_COMM_NULL MPI_COMM_NULL #define hypre_MPI_BOTTOM MPI_BOTTOM #define hypre_MPI_COMM_SELF MPI_COMM_SELF #define hypre_MPI_FLOAT MPI_FLOAT #define hypre_MPI_DOUBLE MPI_DOUBLE #define hypre_MPI_LONG_DOUBLE MPI_LONG_DOUBLE /* HYPRE_MPI_INT is defined in HYPRE_utilities.h */ #define hypre_MPI_INT HYPRE_MPI_INT #define hypre_MPI_CHAR MPI_CHAR #define hypre_MPI_LONG MPI_LONG #define hypre_MPI_BYTE MPI_BYTE /* HYPRE_MPI_REAL is defined in HYPRE_utilities.h */ #define hypre_MPI_REAL HYPRE_MPI_REAL /* HYPRE_MPI_COMPLEX is defined in HYPRE_utilities.h */ #define hypre_MPI_COMPLEX HYPRE_MPI_COMPLEX #define hypre_MPI_SUM MPI_SUM #define hypre_MPI_MIN MPI_MIN #define hypre_MPI_MAX MPI_MAX #define hypre_MPI_LOR MPI_LOR #define hypre_MPI_SUCCESS MPI_SUCCESS #define hypre_MPI_STATUSES_IGNORE MPI_STATUSES_IGNORE #define hypre_MPI_UNDEFINED MPI_UNDEFINED #define hypre_MPI_REQUEST_NULL MPI_REQUEST_NULL #define hypre_MPI_ANY_SOURCE MPI_ANY_SOURCE #define hypre_MPI_ANY_TAG MPI_ANY_TAG #define hypre_MPI_SOURCE MPI_SOURCE #define hypre_MPI_TAG MPI_TAG #define hypre_MPI_LAND MPI_LAND #endif /****************************************************************************** * Everything below this applies to both ifdef cases above *****************************************************************************/ /*-------------------------------------------------------------------------- * Prototypes *--------------------------------------------------------------------------*/ /* mpistubs.c */ HYPRE_Int hypre_MPI_Init( hypre_int *argc , char ***argv ); HYPRE_Int hypre_MPI_Finalize( void ); HYPRE_Int hypre_MPI_Abort( hypre_MPI_Comm comm , HYPRE_Int errorcode ); HYPRE_Real hypre_MPI_Wtime( void ); HYPRE_Real hypre_MPI_Wtick( void ); HYPRE_Int hypre_MPI_Barrier( hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Comm_create( hypre_MPI_Comm comm , hypre_MPI_Group group , hypre_MPI_Comm *newcomm ); HYPRE_Int hypre_MPI_Comm_dup( hypre_MPI_Comm comm , hypre_MPI_Comm *newcomm ); hypre_MPI_Comm hypre_MPI_Comm_f2c( hypre_int comm ); HYPRE_Int hypre_MPI_Comm_size( hypre_MPI_Comm comm , HYPRE_Int *size ); HYPRE_Int hypre_MPI_Comm_rank( hypre_MPI_Comm comm , HYPRE_Int *rank ); HYPRE_Int hypre_MPI_Comm_free( hypre_MPI_Comm *comm ); HYPRE_Int hypre_MPI_Comm_group( hypre_MPI_Comm comm , hypre_MPI_Group *group ); HYPRE_Int hypre_MPI_Comm_split( hypre_MPI_Comm comm, HYPRE_Int n, HYPRE_Int m, hypre_MPI_Comm * comms ); HYPRE_Int hypre_MPI_Group_incl( hypre_MPI_Group group , HYPRE_Int n , HYPRE_Int *ranks , hypre_MPI_Group *newgroup ); HYPRE_Int hypre_MPI_Group_free( hypre_MPI_Group *group ); HYPRE_Int hypre_MPI_Address( void *location , hypre_MPI_Aint *address ); HYPRE_Int hypre_MPI_Get_count( hypre_MPI_Status *status , hypre_MPI_Datatype datatype , HYPRE_Int *count ); HYPRE_Int hypre_MPI_Alltoall( void *sendbuf , HYPRE_Int sendcount , hypre_MPI_Datatype sendtype , void *recvbuf , HYPRE_Int recvcount , hypre_MPI_Datatype recvtype , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Allgather( void *sendbuf , HYPRE_Int sendcount , hypre_MPI_Datatype sendtype , void *recvbuf , HYPRE_Int recvcount , hypre_MPI_Datatype recvtype , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Allgatherv( void *sendbuf , HYPRE_Int sendcount , hypre_MPI_Datatype sendtype , void *recvbuf , HYPRE_Int *recvcounts , HYPRE_Int *displs , hypre_MPI_Datatype recvtype , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Gather( void *sendbuf , HYPRE_Int sendcount , hypre_MPI_Datatype sendtype , void *recvbuf , HYPRE_Int recvcount , hypre_MPI_Datatype recvtype , HYPRE_Int root , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Gatherv( void *sendbuf , HYPRE_Int sendcount , hypre_MPI_Datatype sendtype , void *recvbuf , HYPRE_Int *recvcounts , HYPRE_Int *displs , hypre_MPI_Datatype recvtype , HYPRE_Int root , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Scatter( void *sendbuf , HYPRE_Int sendcount , hypre_MPI_Datatype sendtype , void *recvbuf , HYPRE_Int recvcount , hypre_MPI_Datatype recvtype , HYPRE_Int root , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Scatterv( void *sendbuf , HYPRE_Int *sendcounts , HYPRE_Int *displs, hypre_MPI_Datatype sendtype , void *recvbuf , HYPRE_Int recvcount , hypre_MPI_Datatype recvtype , HYPRE_Int root , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Bcast( void *buffer , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int root , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Send( void *buf , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int dest , HYPRE_Int tag , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Recv( void *buf , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int source , HYPRE_Int tag , hypre_MPI_Comm comm , hypre_MPI_Status *status ); HYPRE_Int hypre_MPI_Isend( void *buf , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int dest , HYPRE_Int tag , hypre_MPI_Comm comm , hypre_MPI_Request *request ); HYPRE_Int hypre_MPI_Irecv( void *buf , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int source , HYPRE_Int tag , hypre_MPI_Comm comm , hypre_MPI_Request *request ); HYPRE_Int hypre_MPI_Send_init( void *buf , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int dest , HYPRE_Int tag , hypre_MPI_Comm comm , hypre_MPI_Request *request ); HYPRE_Int hypre_MPI_Recv_init( void *buf , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int dest , HYPRE_Int tag , hypre_MPI_Comm comm , hypre_MPI_Request *request ); HYPRE_Int hypre_MPI_Irsend( void *buf , HYPRE_Int count , hypre_MPI_Datatype datatype , HYPRE_Int dest , HYPRE_Int tag , hypre_MPI_Comm comm , hypre_MPI_Request *request ); HYPRE_Int hypre_MPI_Startall( HYPRE_Int count , hypre_MPI_Request *array_of_requests ); HYPRE_Int hypre_MPI_Probe( HYPRE_Int source , HYPRE_Int tag , hypre_MPI_Comm comm , hypre_MPI_Status *status ); HYPRE_Int hypre_MPI_Iprobe( HYPRE_Int source , HYPRE_Int tag , hypre_MPI_Comm comm , HYPRE_Int *flag , hypre_MPI_Status *status ); HYPRE_Int hypre_MPI_Test( hypre_MPI_Request *request , HYPRE_Int *flag , hypre_MPI_Status *status ); HYPRE_Int hypre_MPI_Testall( HYPRE_Int count , hypre_MPI_Request *array_of_requests , HYPRE_Int *flag , hypre_MPI_Status *array_of_statuses ); HYPRE_Int hypre_MPI_Wait( hypre_MPI_Request *request , hypre_MPI_Status *status ); HYPRE_Int hypre_MPI_Waitall( HYPRE_Int count , hypre_MPI_Request *array_of_requests , hypre_MPI_Status *array_of_statuses ); HYPRE_Int hypre_MPI_Waitany( HYPRE_Int count , hypre_MPI_Request *array_of_requests , HYPRE_Int *index , hypre_MPI_Status *status ); HYPRE_Int hypre_MPI_Allreduce( void *sendbuf , void *recvbuf , HYPRE_Int count , hypre_MPI_Datatype datatype , hypre_MPI_Op op , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Reduce( void *sendbuf , void *recvbuf , HYPRE_Int count , hypre_MPI_Datatype datatype , hypre_MPI_Op op , HYPRE_Int root , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Scan( void *sendbuf , void *recvbuf , HYPRE_Int count , hypre_MPI_Datatype datatype , hypre_MPI_Op op , hypre_MPI_Comm comm ); HYPRE_Int hypre_MPI_Request_free( hypre_MPI_Request *request ); HYPRE_Int hypre_MPI_Type_contiguous( HYPRE_Int count , hypre_MPI_Datatype oldtype , hypre_MPI_Datatype *newtype ); HYPRE_Int hypre_MPI_Type_vector( HYPRE_Int count , HYPRE_Int blocklength , HYPRE_Int stride , hypre_MPI_Datatype oldtype , hypre_MPI_Datatype *newtype ); HYPRE_Int hypre_MPI_Type_hvector( HYPRE_Int count , HYPRE_Int blocklength , hypre_MPI_Aint stride , hypre_MPI_Datatype oldtype , hypre_MPI_Datatype *newtype ); HYPRE_Int hypre_MPI_Type_struct( HYPRE_Int count , HYPRE_Int *array_of_blocklengths , hypre_MPI_Aint *array_of_displacements , hypre_MPI_Datatype *array_of_types , hypre_MPI_Datatype *newtype ); HYPRE_Int hypre_MPI_Type_commit( hypre_MPI_Datatype *datatype ); HYPRE_Int hypre_MPI_Type_free( hypre_MPI_Datatype *datatype ); HYPRE_Int hypre_MPI_Op_free( hypre_MPI_Op *op ); HYPRE_Int hypre_MPI_Op_create( hypre_MPI_User_function *function , hypre_int commute , hypre_MPI_Op *op ); #ifdef __cplusplus } #endif #endif
16,426
53.214521
226
h
AMG
AMG-master/utilities/threading.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef hypre_THREADING_HEADER #define hypre_THREADING_HEADER #ifdef HYPRE_USING_OPENMP HYPRE_Int hypre_NumThreads( void ); HYPRE_Int hypre_NumActiveThreads( void ); HYPRE_Int hypre_GetThreadNum( void ); #else #define hypre_NumThreads() 1 #define hypre_NumActiveThreads() 1 #define hypre_GetThreadNum() 0 #endif void hypre_GetSimpleThreadPartition( HYPRE_Int *begin, HYPRE_Int *end, HYPRE_Int n ); #endif
1,338
33.333333
85
h
AMG
AMG-master/utilities/timing.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ /****************************************************************************** * * Header file for doing timing * *****************************************************************************/ #ifndef HYPRE_TIMING_HEADER #define HYPRE_TIMING_HEADER #include <stdlib.h> #include <stdio.h> #include <string.h> #ifdef __cplusplus extern "C" { #endif /*-------------------------------------------------------------------------- * Prototypes for low-level timing routines *--------------------------------------------------------------------------*/ /* timer.c */ HYPRE_Real time_getWallclockSeconds( void ); HYPRE_Real time_getCPUSeconds( void ); HYPRE_Real time_get_wallclock_seconds_( void ); HYPRE_Real time_get_cpu_seconds_( void ); /*-------------------------------------------------------------------------- * With timing off *--------------------------------------------------------------------------*/ #ifndef HYPRE_TIMING #define hypre_InitializeTiming(name) 0 #define hypre_FinalizeTiming(index) #define hypre_IncFLOPCount(inc) #define hypre_BeginTiming(i) #define hypre_EndTiming(i) #define hypre_PrintTiming(heading, comm) #define hypre_ClearTiming() /*-------------------------------------------------------------------------- * With timing on *--------------------------------------------------------------------------*/ #else /*------------------------------------------------------- * Global timing structure *-------------------------------------------------------*/ typedef struct { HYPRE_Real *wall_time; HYPRE_Real *cpu_time; HYPRE_Real *flops; char **name; HYPRE_Int *state; /* boolean flag to allow for recursive timing */ HYPRE_Int *num_regs; /* count of how many times a name is registered */ HYPRE_Int num_names; HYPRE_Int size; HYPRE_Real wall_count; HYPRE_Real CPU_count; HYPRE_Real FLOP_count; } hypre_TimingType; #ifdef HYPRE_TIMING_GLOBALS hypre_TimingType *hypre_global_timing = NULL; #else extern hypre_TimingType *hypre_global_timing; #endif /*------------------------------------------------------- * Accessor functions *-------------------------------------------------------*/ #define hypre_TimingWallTime(i) (hypre_global_timing -> wall_time[(i)]) #define hypre_TimingCPUTime(i) (hypre_global_timing -> cpu_time[(i)]) #define hypre_TimingFLOPS(i) (hypre_global_timing -> flops[(i)]) #define hypre_TimingName(i) (hypre_global_timing -> name[(i)]) #define hypre_TimingState(i) (hypre_global_timing -> state[(i)]) #define hypre_TimingNumRegs(i) (hypre_global_timing -> num_regs[(i)]) #define hypre_TimingWallCount (hypre_global_timing -> wall_count) #define hypre_TimingCPUCount (hypre_global_timing -> CPU_count) #define hypre_TimingFLOPCount (hypre_global_timing -> FLOP_count) /*------------------------------------------------------- * Prototypes *-------------------------------------------------------*/ /* timing.c */ HYPRE_Int hypre_InitializeTiming( const char *name ); HYPRE_Int hypre_FinalizeTiming( HYPRE_Int time_index ); HYPRE_Int hypre_IncFLOPCount( HYPRE_Int inc ); HYPRE_Int hypre_BeginTiming( HYPRE_Int time_index ); HYPRE_Int hypre_EndTiming( HYPRE_Int time_index ); HYPRE_Int hypre_ClearTiming( void ); HYPRE_Int hypre_PrintTiming( const char *heading , MPI_Comm comm ); #endif #ifdef __cplusplus } #endif #endif
4,315
32.71875
81
h
AMG
AMG-master/utilities/umalloc_local.h
/*BHEADER********************************************************************** * Copyright (c) 2017, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * Written by Ulrike Yang ([email protected]) et al. CODE-LLNL-738-322. * This file is part of AMG. See files README and COPYRIGHT for details. * * AMG is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTIBILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the * GNU General Public License for more details. * ***********************************************************************EHEADER*/ #ifndef UMALLOC_LOCAL_HEADER #define UMALLOC_LOCAL_HEADER #ifdef HYPRE_USE_UMALLOC #include <umalloc.h> #define MAX_THREAD_COUNT 10 #define INITIAL_HEAP_SIZE 500000 #define GET_MISS_COUNTS struct upc_struct { Heap_t myheap; }; void *_uinitial_block[MAX_THREAD_COUNT]; struct upc_struct _uparam[MAX_THREAD_COUNT]; HYPRE_Int _uheapReleasesCount=0; HYPRE_Int _uheapGetsCount=0; void *_uget_fn(Heap_t usrheap, size_t *length, HYPRE_Int *clean); void _urelease_fn(Heap_t usrheap, void *p, size_t size); #endif #endif
1,449
29.851064
81
h