Binary &Op是什么
前言
在并行开发时我们经常会用到Pstream::gather()函数或是全局函数reduce()或者其他,需要输入参数Binary &Op,本篇主要讨论Binary &Op是什么
template<class T, class BinaryOp>
void reduce
(
T& Value,
const BinaryOp& bop, // 这里要输入什么参数
const int tag,
const label comm,
label& request
)
{
NotImplemented;
}
Binary &Op
单从名字上看,猜是一个二进制的操作,类似一组操作返回一个二进制的标记
然后去openfoam官网去找,找不到Binary &Op的任何释义
去网上找,发现了一点端倪
c++标准库中有应用Binary &Op这个输入参数,使用的函数也叫reduce,详情可见该网页
这里顺便说几个学习C++不错的网址,查询起来很方便
https://en.cppreference.com/w/
https://learncpp-cn.github.io/
https://cplusplus.com/
https://www.tutorialspoint.com/index.htm
https://awesome-cpp.readthedocs.io/en/latest/README.html#
https://stackoverflow.org.cn/
标准库对输入参数binary_op的解释是:
将以未指定顺序应用于解引用输入迭代器结果、其他 binary_op 结果及 init 上的二元函数对象 (FunctionObject) 。
我们再看下类似的std::transform,详情可见该网页
可能实现的版本有
template<class InputIt1, class InputIt2,
class OutputIt, class BinaryOperation>
OutputIt transform(InputIt1 first1, InputIt1 last1, InputIt2 first2,
OutputIt d_first, BinaryOperation binary_op)
{
while (first1 != last1) {
*d_first++ = binary_op(*first1++, *first2++);
}
return d_first;
}
在这个程序中我们看到输入的参数可以传的参数可以函数指针,也可以是仿函数,而且这个仿函数需要传两个参数,按要求送达至返回值中
但按照C++的风格更喜欢是仿函数了
所以我们经常能看到类似这样的函数使用模式
#include <iostream>
#include <functional>
#include <algorithm>
int main () {
bool foo[] = {true,true,false,false};
bool bar[] = {true,false,true,false};
bool result[4];
std::transform (foo, foo+4, bar, result, std::logical_or<bool>());
std::cout << std::boolalpha << "Logical OR example as shown below:\n";
for (int i=0; i<4; i++)
std::cout << foo[i] << " OR " << bar[i] << " = " << result[i] << "\n";
return 0;
}
以下是输出结果:
Logical OR example as shown below:
true OR true = true
true OR false = true
false OR true = true
false OR false = false
那么我类似的把std::logical_or()放到openfoam的reduce函数里可不可以呢
答案是可以的
当然啊,std::logical_or()放到reduce函数中是没什么意义的,但是我们这就可以清楚,我们需要写怎么样的函数,或者函数指针传送到Binary &Op参数中
对于reduce而言,在ops.H中内置了很丰富的仿函数以供调用
Op(sum, x + y)
Op(plus, x + y)
Op(minus, x - y)
Op(multiply, x * y)
Op(divide, x / y)
Op(cmptMultiply, cmptMultiply(x, y))
Op(cmptPow, cmptPow(x, y))
Op(cmptDivide, cmptDivide(x, y))
Op(stabilise, stabilise(x, y))
Op(max, max(x, y))
Op(min, min(x, y))
Op(minMagSqr, (magSqr(x)<=magSqr(y) ? x : y))
Op(maxMagSqr, (magSqr(x)>=magSqr(y) ? x : y))
Op(minMod, minMod(x, y))
Op(and, x && y)
Op(or, x || y)
Op(not, x != y)
Op(eqEq, x == y)
Op(less, x < y)
Op(lessEq, x <= y)
Op(greater, x > y)
Op(greaterEq, x >= y)
如果想写自己的Binary &Op操作,可以在ops.H的基础上去创建,要轻松很多
结语
一起探索openfoam也是相当有趣的一件事,非常欢迎私信讨论
指正的价值要比打赏更重要,下面是个人联系方式,希望能结交到志同道合的朋友

Binary &Op是什么的更多相关文章
- 变动性算法源代码分析与使用示例(copy_backward、 transform、 replace_copy_if 等)
首先回顾前面的文章,我们把for_each 归类为非变动性算法,实际上它也可以算是变动性算法,取决于传入的第三个参数,即函数 指针.如果在函数内对容器元素做了修改,那么就属于变动性算法. 变动性算法源 ...
- smali语句类的静态成员查看,invoke-virtual、invoke-direct、invoke-super解释
smali举例: .class public Lcom/dataviz/dxtg/common/android/DocsToGoApp; .super Landroid/app/Application ...
- 07. Go 语言接口
Go 语言接口 接口本身是调用方和实现方均需要遵守的一种协议,大家按照统一的方法命名参数类型和数量来协调逻辑处理的过程. Go 语言中使用组合实现对象特性的描述.对象的内部使用结构体内嵌组合对象应该具 ...
- tensorflow 升级到1.9-rc0,生成静态图frozen graph.pb本地测试正常, 在其他版本(eg1.4版本)或者android下运行出错NodeDef mentions attr 'dilations' not in Op<name=Conv2D; signature=input:T, filter:T -> output:T; attr=T:type,allowed=[DT_
这时节点定义找不到NodeDef attr 'dilations' not in,说明执行版本的NodeDef不在节点定义上,两个不一致,分别是执行inference的代码和生成静态图节点不一致(当然 ...
- LeetCode: Validate Binary Search Tree 解题报告
Validate Binary Search Tree Given a binary tree, determine if it is a valid binary search tree (BST) ...
- Latest SQLite binary for January 2015
Latest SQLite binary for January 2015 Well I went through quite a few threads to find an updated, de ...
- [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法
二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...
- ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id
出现场景:当点击"分类"再返回"首页"时,发生error退出 BUG描述:Caused by: java.lang.IllegalArgumentExcep ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
- Leetcode 笔记 99 - Recover Binary Search Tree
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...
随机推荐
- ArcGIS QGIS学习二:图层如何只显示需要的部分几何面数据(附最新坐标边界下载全国省市区县乡镇)
目录 前言 准备SHP数据 ArcMap 的筛选 QGIS 的筛选 如何编写查询条件 前言 当我们用GIS软件打开一个SHP文件的时候,会显示出里面全部的几何图形,假如我只想要其中的一部分数据显示出来 ...
- 安装mySql 出现 one more product requirements have not been satisified
安装mySql 出现 one more product requirements have not been satisified 原因是缺少一些依赖环境. 在弹出的对话框中点击 否. 然后点击执行, ...
- 1.1 大数据简介-hadoop-最全最完整的保姆级的java大数据学习资料
目录 1 hadoop-最全最完整的保姆级的java大数据学习资料 1.1 大数据简介 1.1.1 大数据的定义 1.1.2 大数据的特点 1.1.3 大数据的应用场景 1.1.4 大数据的发展趋势及 ...
- 【每日一题】【动态规划,递推式与公共子串的区别】2022年1月31日-NC92 最长公共子序列(二)
描述 给定两个字符串str1和str2,输出两个字符串的最长公共子序列.如果最长公共子序列为空,则返回"-1".目前给出的数据,仅仅会存在一个最长的公共子序列 方法1: impor ...
- org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint = character varying
1.报错信息 org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: org.post ...
- 第三方模块 request openpyxl
目录 第三方模块的下载 pip工具 简介 pip使用注意 pip位置和环境变量设置 pip安装第三方模块 使用pip下载可能会遇到的问题 pycharm的第三方模块下载功能 request模块 req ...
- Jmeter在结果树中查看响应数据为空
今天遇到了一个比较尴尬的问题,吭哧吭哧了大半天,后来咨询了开发SO的一下解决了. 问题: 在调用接口时取样器结果中显示response code:200, response message:OK,但是 ...
- JavaScript:原型(prototype)
面向对象有一个特征是继承,即重用某个已有类的代码,在其基础上建立新的类,而无需重新编写对应的属性和方法,继承之后拿来即用: 在其他的面向对象编程语言比如Java中,通常是指,子类继承父类的属性和方法: ...
- 将git仓库从submodule转换为subtree
三个脚本 Alexander Mikhailian cat .gitmodules |while read i do if [[ $i == \[submodule* ]]; then mpath=$ ...
- Springcloud源码学习笔记1—— Zuul网关原理
系列文章目录和关于我 源码基于 spring-cloud-netflix-zuul-2.2.6.RELEASE.jar 需要具备SpringMVC源码功底 推荐学习https://www.cnblog ...