static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data) { struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; struct nlattr *nla_table, *nla_entry; struct rd *rd = data; const char *name; uint32_t idx; mnl_attr_parse(nlh, 0, rd_attr_cb, tb); if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || !tb[RDMA_NLDEV_ATTR_RES_PD]) return MNL_CB_ERROR; name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); nla_table = tb[RDMA_NLDEV_ATTR_RES_PD]; mnl_attr_for_each_nested(nla_entry, nla_table) { uint32_t local_dma_lkey = 0, unsafe_global_rkey = 0; struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; char *comm = NULL; uint32_t pid = 0; uint64_t users; int err; err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); if (err != MNL_CB_OK) return MNL_CB_ERROR; if (!nla_line[RDMA_NLDEV_ATTR_RES_USECNT] || (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { return MNL_CB_ERROR; } if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]) local_dma_lkey = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]); users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); if (rd_check_is_filtered(rd, "users", users)) continue; if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]) unsafe_global_rkey = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]); if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); } if (rd_check_is_filtered(rd, "pid", pid)) continue; if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) /* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str( nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); if (rd->json_output) jsonw_start_array(rd->jw); print_dev(rd, idx, name); if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]) print_key(rd, "local_dma_lkey", local_dma_lkey); print_users(rd, users); if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]) print_key(rd, "unsafe_global_rkey", unsafe_global_rkey); print_pid(rd, pid); print_comm(rd, comm, nla_line); if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) free(comm); print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); newline(rd); }
static int res_pd_line(struct rd *rd, const char *name, int idx, struct nlattr **nla_line) { uint32_t local_dma_lkey = 0, unsafe_global_rkey = 0; char *comm = NULL; uint32_t ctxn = 0; uint32_t pid = 0; uint32_t pdn = 0; uint64_t users; if (!nla_line[RDMA_NLDEV_ATTR_RES_USECNT] || (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { return MNL_CB_ERROR; } if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]) local_dma_lkey = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]); users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); if (rd_is_filtered_attr(rd, "users", users, nla_line[RDMA_NLDEV_ATTR_RES_USECNT])) goto out; if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]) unsafe_global_rkey = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]); if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); } if (rd_is_filtered_attr(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID])) goto out; if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN]) ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); if (rd_is_filtered_attr(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN])) goto out; if (nla_line[RDMA_NLDEV_ATTR_RES_PDN]) pdn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PDN]); if (rd_is_filtered_attr(rd, "pdn", pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN])) goto out; if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) /* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str( nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); if (rd->json_output) jsonw_start_array(rd->jw); print_dev(rd, idx, name); res_print_uint(rd, "pdn", pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN]); print_key(rd, "local_dma_lkey", local_dma_lkey, nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]); res_print_uint(rd, "users", users, nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); print_key(rd, "unsafe_global_rkey", unsafe_global_rkey, nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]); res_print_uint(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]); print_comm(rd, comm, nla_line); print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); newline(rd); out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) free(comm); return MNL_CB_OK; }
static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data) { struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; struct nlattr *nla_table, *nla_entry; struct rd *rd = data; const char *name; uint32_t idx; mnl_attr_parse(nlh, 0, rd_attr_cb, tb); if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || !tb[RDMA_NLDEV_ATTR_RES_MR]) return MNL_CB_ERROR; name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); nla_table = tb[RDMA_NLDEV_ATTR_RES_MR]; mnl_attr_for_each_nested(nla_entry, nla_table) { struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; uint32_t rkey = 0, lkey = 0; uint64_t iova = 0, mrlen; char *comm = NULL; uint32_t pid = 0; int err; err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); if (err != MNL_CB_OK) return MNL_CB_ERROR; if (!nla_line[RDMA_NLDEV_ATTR_RES_MRLEN] || (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { return MNL_CB_ERROR; } if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY]) rkey = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_RKEY]); if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY]) lkey = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_LKEY]); if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA]) iova = mnl_attr_get_u64( nla_line[RDMA_NLDEV_ATTR_RES_IOVA]); mrlen = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]); if (rd_check_is_filtered(rd, "mrlen", mrlen)) continue; if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); } if (rd_check_is_filtered(rd, "pid", pid)) { free(comm); continue; } if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) /* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str( nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); if (rd->json_output) jsonw_start_array(rd->jw); print_dev(rd, idx, name); if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY]) print_key(rd, "rkey", rkey); if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY]) print_key(rd, "lkey", lkey); if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA]) print_iova(rd, iova); print_mrlen(rd, mrlen); print_pid(rd, pid); print_comm(rd, comm, nla_line); if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) free(comm); print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); newline(rd); } return MNL_CB_OK; }
static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data) { struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; struct nlattr *nla_table, *nla_entry; struct rd *rd = data; const char *name; uint32_t idx; mnl_attr_parse(nlh, 0, rd_attr_cb, tb); if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || !tb[RDMA_NLDEV_ATTR_RES_CQ]) return MNL_CB_ERROR; name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ]; mnl_attr_for_each_nested(nla_entry, nla_table) { struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; char *comm = NULL; uint32_t pid = 0; uint8_t poll_ctx = 0; uint64_t users; uint32_t cqe; int err; err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); if (err != MNL_CB_OK) return MNL_CB_ERROR; if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] || !nla_line[RDMA_NLDEV_ATTR_RES_USECNT] || (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { return MNL_CB_ERROR; } cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]); users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); if (rd_check_is_filtered(rd, "users", users)) continue; if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) { poll_ctx = mnl_attr_get_u8( nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]); if (rd_check_is_string_filtered(rd, "poll-ctx", poll_ctx_to_str(poll_ctx))) continue; } if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); } if (rd_check_is_filtered(rd, "pid", pid)) { free(comm); continue; } if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) /* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str( nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); if (rd->json_output) jsonw_start_array(rd->jw); print_dev(rd, idx, name); print_cqe(rd, cqe); print_users(rd, users); if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) print_poll_ctx(rd, poll_ctx); print_pid(rd, pid); print_comm(rd, comm, nla_line); if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) free(comm); print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); newline(rd); } return MNL_CB_OK; }
static int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data) { struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; struct nlattr *nla_table, *nla_entry; struct rd *rd = data; const char *name; int idx; mnl_attr_parse(nlh, 0, rd_attr_cb, tb); if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || !tb[RDMA_NLDEV_ATTR_RES_CM_ID]) return MNL_CB_ERROR; name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); nla_table = tb[RDMA_NLDEV_ATTR_RES_CM_ID]; mnl_attr_for_each_nested(nla_entry, nla_table) { struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; char src_addr_str[INET6_ADDRSTRLEN]; char dst_addr_str[INET6_ADDRSTRLEN]; uint16_t src_port, dst_port; uint32_t port = 0, pid = 0; uint8_t type = 0, state; uint32_t lqpn = 0, ps; char *comm = NULL; int err; err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); if (err != MNL_CB_OK) return -EINVAL; if (!nla_line[RDMA_NLDEV_ATTR_RES_STATE] || !nla_line[RDMA_NLDEV_ATTR_RES_PS] || (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { return MNL_CB_ERROR; } if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]) port = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]); if (port && port != rd->port_idx) continue; if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN]) { lqpn = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_LQPN]); if (rd_check_is_filtered(rd, "lqpn", lqpn)) continue; } if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE]) { type = mnl_attr_get_u8( nla_line[RDMA_NLDEV_ATTR_RES_TYPE]); if (rd_check_is_string_filtered(rd, "qp-type", qp_types_to_str(type))) continue; } ps = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PS]); if (rd_check_is_string_filtered(rd, "ps", cm_id_ps_to_str(ps))) continue; state = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_STATE]); if (rd_check_is_string_filtered(rd, "state", cm_id_state_to_str(state))) continue; if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR]) { if (ss_ntop(nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR], src_addr_str, &src_port)) continue; if (rd_check_is_string_filtered(rd, "src-addr", src_addr_str)) continue; if (rd_check_is_filtered(rd, "src-port", src_port)) continue; } if (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR]) { if (ss_ntop(nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR], dst_addr_str, &dst_port)) continue; if (rd_check_is_string_filtered(rd, "dst-addr", dst_addr_str)) continue; if (rd_check_is_filtered(rd, "dst-port", dst_port)) continue; } if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32( nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); } if (rd_check_is_filtered(rd, "pid", pid)) { free(comm); continue; } if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) { /* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str( nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); } if (rd->json_output) jsonw_start_array(rd->jw); print_link(rd, idx, name, port, nla_line); if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN]) print_lqpn(rd, lqpn); if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE]) print_qp_type(rd, type); print_cm_id_state(rd, state); print_ps(rd, ps); print_pid(rd, pid); print_comm(rd, comm, nla_line); if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR]) print_ipaddr(rd, "src-addr", src_addr_str, src_port); if (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR]) print_ipaddr(rd, "dst-addr", dst_addr_str, dst_port); if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) free(comm); print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); newline(rd); } return MNL_CB_OK; }
static int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data) { struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; struct nlattr *nla_table, *nla_entry; struct rd *rd = data; const char *name; uint32_t idx; mnl_attr_parse(nlh, 0, rd_attr_cb, tb); if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || !tb[RDMA_NLDEV_ATTR_RES_QP]) return MNL_CB_ERROR; name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); nla_table = tb[RDMA_NLDEV_ATTR_RES_QP]; mnl_attr_for_each_nested(nla_entry, nla_table) { struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; uint32_t lqpn, rqpn = 0, rq_psn = 0, sq_psn; uint8_t type, state, path_mig_state = 0; uint32_t port = 0, pid = 0; char *comm = NULL; int err; err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); if (err != MNL_CB_OK) return MNL_CB_ERROR; if (!nla_line[RDMA_NLDEV_ATTR_RES_LQPN] || !nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN] || !nla_line[RDMA_NLDEV_ATTR_RES_TYPE] || !nla_line[RDMA_NLDEV_ATTR_RES_STATE] || (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { return MNL_CB_ERROR; } if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]) port = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]); if (port != rd->port_idx) continue; lqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LQPN]); if (rd_check_is_filtered(rd, "lqpn", lqpn)) continue; if (nla_line[RDMA_NLDEV_ATTR_RES_RQPN]) { rqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_RQPN]); if (rd_check_is_filtered(rd, "rqpn", rqpn)) continue; } else { if (rd_check_is_key_exist(rd, "rqpn")) continue; } if (nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN]) { rq_psn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN]); if (rd_check_is_filtered(rd, "rq-psn", rq_psn)) continue; } else { if (rd_check_is_key_exist(rd, "rq-psn")) continue; } sq_psn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN]); if (rd_check_is_filtered(rd, "sq-psn", sq_psn)) continue; if (nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE]) { path_mig_state = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE]); if (rd_check_is_string_filtered(rd, "path-mig-state", path_mig_to_str(path_mig_state))) continue; } else { if (rd_check_is_key_exist(rd, "path-mig-state")) continue; } type = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_TYPE]); if (rd_check_is_string_filtered(rd, "type", qp_types_to_str(type))) continue; state = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_STATE]); if (rd_check_is_string_filtered(rd, "state", qp_states_to_str(state))) continue; if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); } if (rd_check_is_filtered(rd, "pid", pid)) { free(comm); continue; } if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) /* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str(nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); if (rd->json_output) jsonw_start_array(rd->jw); print_link(rd, idx, name, port, nla_line); print_lqpn(rd, lqpn); print_rqpn(rd, rqpn, nla_line); print_type(rd, type); print_state(rd, state); print_rqpsn(rd, rq_psn, nla_line); print_sqpsn(rd, sq_psn); print_pathmig(rd, path_mig_state, nla_line); print_pid(rd, pid); print_comm(rd, comm, nla_line); if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) free(comm); print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); newline(rd); } return MNL_CB_OK; }
int main (int argc, char* argv[]) { int color, key; double start, end; MPI_Comm newcomm; MPI_Init(&argc, &argv); int rank, ranks; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &ranks); int size; int* members = (int*) malloc(ranks * sizeof(int)); lwgrp_ring group; lwgrp_ring_build_from_comm(MPI_COMM_WORLD, &group); lwgrp_ring group_split; lwgrp_ring_split_bin(2, (rank%2), &group, &group_split); lwgrp_logring logring; lwgrp_logring_build_from_ring(&group, &logring); int* inbuf = (int*) malloc(ranks * sizeof(int)); int* outbuf = (int*) malloc(ranks * sizeof(int)); int i; for (i = 0; i < ranks; i++) { inbuf[i] = rank * ranks + i; outbuf[i] = -1; } lwgrp_logring_barrier(&group, &logring); int bcastbuf = rank; lwgrp_logring_bcast(&bcastbuf, 1, MPI_INT, 0, &group, &logring); lwgrp_logring_allgather_brucks(&rank, members, 1, MPI_INT, &group, &logring); lwgrp_logring_alltoall_brucks(inbuf, outbuf, 1, MPI_INT, &group, &logring); int sum = -1; #if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2 lwgrp_logring_allreduce(&rank, &sum, 1, MPI_INT, MPI_SUM, &group, &logring); lwgrp_logring_scan(&rank, &sum, 1, MPI_INT, MPI_SUM, &group, &logring); lwgrp_logring_exscan(&rank, &sum, 1, MPI_INT, MPI_SUM, &group, &logring); #endif #if 0 #if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2 int myval = rank*2 + 1; int allval; lwgrp_chain_allreduce(&myval, &allval, 1, MPI_INT, MPI_SUM, &group); printf("rank=%d input=%d output=%d\n", rank, myval, allval); fflush(stdout); int ltr_send = 1; int rtl_send = -1; int ltr_recv = 100; int rtl_recv = 100; lwgrp_chain_double_exscan(<r_send, <r_recv, &rtl_send, &rtl_recv, 1, MPI_INT, MPI_SUM, &group); printf("rank=%d ltr_send=%d ltr_recv=%d rtl_send=%d rtl_recv=%d\n", rank, ltr_send, ltr_recv, rtl_send, rtl_recv ); fflush(stdout); #endif #endif lwgrp_ring_free(&group); MPI_Finalize(); return 0; int tag1 = 0; int tag2 = 1; color = 0; key = rank; start = MPI_Wtime(); lwgrp_comm_split_members(MPI_COMM_WORLD, color, key, tag1, tag2, &size, members); end = MPI_Wtime(); print_members(1, rank, size, members); if (rank == 0) { printf("lwgrp_comm_split_members time %f secs\n", end - start); } #if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2 start = MPI_Wtime(); lwgrp_comm_split_create(MPI_COMM_WORLD, color, key, tag1, tag2, &newcomm); end = MPI_Wtime(); print_comm(2, rank, newcomm); if (newcomm != MPI_COMM_NULL) { MPI_Comm_free(&newcomm); } if (rank == 0) { printf("lwgrp_comm_split_create time %f secs\n", end - start); } #endif start = MPI_Wtime(); MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm); end = MPI_Wtime(); if (newcomm != MPI_COMM_NULL) { MPI_Comm_free(&newcomm); } if (rank == 0) { printf("MPI_Comm_split time %f secs\n", end - start); } color = 0; key = -rank; start = MPI_Wtime(); lwgrp_comm_split_members(MPI_COMM_WORLD, color, key, tag1, tag2, &size, members); end = MPI_Wtime(); print_members(3, rank, size, members); if (rank == 0) { printf("lwgrp_comm_split_members time %f secs\n", end - start); } #if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2 start = MPI_Wtime(); lwgrp_comm_split_create(MPI_COMM_WORLD, color, key, tag1, tag2, &newcomm); end = MPI_Wtime(); print_comm(4, rank, newcomm); if (newcomm != MPI_COMM_NULL) { MPI_Comm_free(&newcomm); } if (rank == 0) { printf("lwgrp_comm_split_create time %f secs\n", end - start); } #endif start = MPI_Wtime(); MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm); end = MPI_Wtime(); if (newcomm != MPI_COMM_NULL) { MPI_Comm_free(&newcomm); } if (rank == 0) { printf("MPI_Comm_split time %f secs\n", end - start); } color = rank; key = -rank; start = MPI_Wtime(); lwgrp_comm_split_members(MPI_COMM_WORLD, color, key, tag1, tag2, &size, members); end = MPI_Wtime(); print_members(5, rank, size, members); if (rank == 0) { printf("lwgrp_comm_split_members time %f secs\n", end - start); } #if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2 start = MPI_Wtime(); lwgrp_comm_split_create(MPI_COMM_WORLD, color, key, tag1, tag2, &newcomm); end = MPI_Wtime(); print_comm(6, rank, newcomm); if (newcomm != MPI_COMM_NULL) { MPI_Comm_free(&newcomm); } if (rank == 0) { printf("lwgrp_comm_split_create time %f secs\n", end - start); } #endif start = MPI_Wtime(); MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm); end = MPI_Wtime(); if (newcomm != MPI_COMM_NULL) { MPI_Comm_free(&newcomm); } if (rank == 0) { printf("MPI_Comm_split time %f secs\n", end - start); } color = (rank % 2) ? 0 : MPI_UNDEFINED; key = -rank; start = MPI_Wtime(); lwgrp_comm_split_members(MPI_COMM_WORLD, color, key, tag1, tag2, &size, members); end = MPI_Wtime(); print_members(7, rank, size, members); if (rank == 0) { printf("lwgrp_comm_split_members time %f secs\n", end - start); } #if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2 start = MPI_Wtime(); lwgrp_comm_split_create(MPI_COMM_WORLD, color, key, tag1, tag2, &newcomm); end = MPI_Wtime(); print_comm(8, rank, newcomm); if (newcomm != MPI_COMM_NULL) { MPI_Comm_free(&newcomm); } if (rank == 0) { printf("lwgrp_comm_split_create time %f secs\n", end - start); } #endif start = MPI_Wtime(); MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm); end = MPI_Wtime(); if (newcomm != MPI_COMM_NULL) { MPI_Comm_free(&newcomm); } if (rank == 0) { printf("MPI_Comm_split time %f secs\n", end - start); } color = rank % 2; key = rank; start = MPI_Wtime(); lwgrp_comm_split_members(MPI_COMM_WORLD, color, key, tag1, tag2, &size, members); end = MPI_Wtime(); print_members(9, rank, size, members); if (rank == 0) { printf("lwgrp_comm_split_members time %f secs\n", end - start); } #if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2 start = MPI_Wtime(); lwgrp_comm_split_create(MPI_COMM_WORLD, color, key, tag1, tag2, &newcomm); end = MPI_Wtime(); print_comm(10, rank, newcomm); if (newcomm != MPI_COMM_NULL) { MPI_Comm_free(&newcomm); } if (rank == 0) { printf("lwgrp_comm_split_create time %f secs\n", end - start); } #endif start = MPI_Wtime(); MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm); end = MPI_Wtime(); if (newcomm != MPI_COMM_NULL) { MPI_Comm_free(&newcomm); } if (rank == 0) { printf("MPI_Comm_split time %f secs\n", end - start); } color = rank / 4; key = rank; start = MPI_Wtime(); lwgrp_comm_split_members(MPI_COMM_WORLD, color, key, tag1, tag2, &size, members); end = MPI_Wtime(); print_members(11, rank, size, members); if (rank == 0) { printf("lwgrp_comm_split_members time %f secs\n", end - start); } #if MPI_VERSION >= 2 && MPI_SUBVERSION >= 2 start = MPI_Wtime(); lwgrp_comm_split_create(MPI_COMM_WORLD, color, key, tag1, tag2, &newcomm); end = MPI_Wtime(); print_comm(12, rank, newcomm); if (newcomm != MPI_COMM_NULL) { MPI_Comm_free(&newcomm); } if (rank == 0) { printf("lwgrp_comm_split_create time %f secs\n", end - start); } #endif start = MPI_Wtime(); MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm); end = MPI_Wtime(); if (newcomm != MPI_COMM_NULL) { MPI_Comm_free(&newcomm); } if (rank == 0) { printf("MPI_Comm_split time %f secs\n", end - start); } free(members); MPI_Finalize(); return 0; }