Basic Communication Operations(基本通信操作)

下文所讨论的所有通信操作都是使用直通路由选择而不是存储转发机制

一对多广播以及多对一规约

一对多广播:广播结束后会有p个原始数据的副本。
多对一规约:所有进程的数据通过一个相关的操作符结合起来,累加到一个目标进程中的缓冲区。

环或线性阵列

使用一种递归加倍的技术,在logp步广播完成。每一步都要仔细选择消息发送的目标节点,以免出现阻塞。
这里写图片描述

格网

行和列分别看成线性阵列
这里写图片描述

超立方体

看成一个d维的格网
这里写图片描述

平衡二叉树

每一个中间节点是开关节点。

这里写图片描述

算法实现

算法是在所有节点上跑的,通信从最高维向最低维进行。只有节点标号的i位最低有效位全为0的节点才参与

### Linux C++ Serial Port Communication Tutorial In the context of developing applications that require serial communication on a Linux system using C++, several key points must be addressed to ensure successful implementation. The focus here is not only on writing efficient code but also understanding how to interact with hardware through software interfaces. #### Understanding Basic Concepts Serial communication under Linux involves interacting directly with device files typically found in `/dev`. These devices can represent physical or virtual ports such as `ttyS0` (standard UART), `ttyUSB0` (for USB-to-serial adapters), etc.[^1] To establish communication over these channels, one needs to open, configure, read from/write to, and close the respective file descriptors associated with each port. This process requires familiarity with POSIX I/O functions like `open()`, `close()`, `read()`, `write()`, along with termios structures used for setting up baud rates, parity bits, stop bits, flow control parameters among others[^2]. #### Example Code Demonstrating Serial Communication Below demonstrates basic operations required when working with serial ports: ```cpp #include <iostream> #include <fcntl.h> /* File Control Definitions */ #include <termios.h> /* POSIX Terminal Control Definitions */ #include <unistd.h> /* UNIX Standard Definitions */ int main(){ int fd; // File descriptor for the port struct termios tty; // Open the port fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY); if(fd < 0){ std::cerr << "Error opening serial port." << std::endl; return -1; } // Get current attributes of the port tcgetattr(fd, &tty); // Set Baud Rate cfsetospeed(&tty, B9600); cfsetispeed(&tty, B9600); // Setting other Port Stuff tty.c_cflag &= ~PARENB; // No Parity tty.c_cflag &= ~CSTOPB; // One Stop Bit tty.c_cflag &= ~CSIZE; // Clear all size bits tty.c_cflag |= CS8; // Select 8 data bits // Enable receiver and set local mode tty.c_cflag |= (CLOCAL | CREAD); // Disable hardware flow control tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Timeouts tty.c_cc[VTIME] = 10; // Wait for up to 1s (10 deciseconds) tty.c_cc[VMIN] = 0; // Apply settings immediately without waiting for pending input/output tcsetattr(fd, TCSANOW, &tty); char buffer[32]; memset(buffer, '\0', sizeof(buffer)); // Read data from the port ssize_t n = read(fd, buffer, sizeof(buffer)-1); if(n > 0){ printf("Read %ld bytes: '%s'\n", n, buffer); }else{ perror("Failed to read"); } close(fd); } ``` This program opens a connection to a specified serial port (`/dev/ttyUSB0`) at 9600 bps, configures it according to standard requirements, reads any available incoming message into a buffer, prints out its content, then closes the connection properly afterwards.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值