gpt4 book ai didi

c - METIS:不同操作系统的不同结果

转载 作者:太空宇宙 更新时间:2023-11-04 03:37:32 25 4
gpt4 key购买 nike

C program电话 METIS划分网格。

编辑: New version考虑到 WeatherVane 和 PaulOgilvie 的评论的 C 程序。

在我的 GNU/Linux 上,我得到了结果:

objval: 14
epart: 0 0 0 0 0 1 2 2 1 0 0 1 2 2 1 2 2 1
npart: 0 0 0 2 0 0 1 1 2 2 2 1 2 2 1 1
8

在我的 OSX 上我得到:

objval: 17
epart: 0 1 1 0 1 0 2 2 0 1 1 1 2 2 1 2 2 0
npart: 0 1 1 1 0 1 0 1 2 2 2 0 2 2 0 0
8

是什么导致结果不同?

如何修复它,我的意思是,无论操作系统/架构/编译器是什么,总是得到相同的结果?

注意:idx_tint64_t,在我的GNU/Linux上是long,但是 long long 在我的 OSX 上。

我的 GNU/Linux

$ cat /etc/issue
Ubuntu 12.04.4 LTS \n \l

$ gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ uname -s -r -v -p -i -o
Linux 3.5.0-45-generic #68~precise1-Ubuntu SMP Wed Dec 4 16:18:46 UTC 2013 x86_64 x86_64 GNU/Linux

我的操作系统

$ sw_vers 

ProductName: Mac OS X
ProductVersion: 10.9.5
BuildVersion: 13F34

$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

$ uname -m -p -r -s -v
Darwin 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64 i386

METIS 安装

METIS 版本为 5.1.0

我已经用 miniconda 安装了 METIS .

包裹是here(文件 linux-64/metis-5.1.0-0.tar.bz2osx-64/metis-5.1.0-2.tar.bz2)。

这些包是用这个 recipe 构建的.

最佳答案

METIS 使用伪随机数。

伪随机数由 GKlib 函数生成。 (GKlib 嵌入在 METIS tarbarll 中)。

默认情况下,GKlib使用C标准库中的rand函数,在不同的平台上可能会产生不同的数字。 (参见:Consistent pseudo-random numbers across platforms)。

但是 GKlib 也可以用标志 -DUSE_GKRAND 编译。它没有使用 rand 函数,而是使用它自己的函数,它始终为不同的平台提供相同的随机数。

使用 -DUSE_GKRAND 编译函数中的 C 代码在我的 GNU/Linux 和我的 OSX 上给出相同的结果:

objval: 18
epart: 0 0 0 2 1 1 2 2 1 0 0 1 0 1 1 2 2 1
npart: 0 0 0 0 2 0 1 1 2 1 2 1 2 2 1 1
8

我用过这个 conda recipe构建 METIS

关于c - METIS:不同操作系统的不同结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31299159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com