我想将C函数与Fortran中的相应结构相链接
struct ovf_file {
bool found;
bool is_ovf;
int n_segments;
struct ovf_file_handle *_file_handle;
};
DLLEXPORT struct ovf_file * ovf_open(const char *filename);
Run Code Online (Sandbox Code Playgroud)
这是我尝试这样做的:
module ovf
use, intrinsic :: iso_c_binding
implicit none
type, bind(c) :: ovf_file
logical(c_bool) :: found
logical(c_bool) :: is_ovf
integer(c_int) :: n_segments
type(c_ptr) :: file_handle
end type ovf_file
end module ovf
program main
use ovf
use, intrinsic :: iso_c_binding
implicit none
type(ovf_file) :: file_handle
interface
function ovf_open(filename) bind ( C, name = "ovf_open" ) result(handle)
character(len=1, kind=c_char), intent(in) :: …Run Code Online (Sandbox Code Playgroud) 我有一个很大的代码,它因以下错误而崩溃:
Fatal error in PMPI_Comm_split: Other MPI error, error stack:
PMPI_Comm_split(532)................: MPI_Comm_split(comm=0xc4027cf0, color=0, key=0, new_comm=0x7ffdb50f2bd0) failed
PMPI_Comm_split(508)................: fail failed
MPIR_Comm_split_impl(260)...........: fail failed
MPIR_Get_contextid_sparse_group(676): Too many communicators (0/16384 free on this process; ignore_id=0)
Fatal error in PMPI_Comm_split: Other MPI error, error stack:
PMPI_Comm_split(532)................: MPI_Comm_split(comm=0xc401bcf1, color=1, key=0, new_comm=0x7ffed5aa4fd0) failed
PMPI_Comm_split(508)................: fail failed
MPIR_Comm_split_impl(260)...........: fail failed
MPIR_Get_contextid_sparse_group(676): Too many communicators (0/16384 free on this process; ignore_id=0)
Fatal error in PMPI_Comm_split: Other MPI error, error stack:
PMPI_Comm_split(532)................: MPI_Comm_split(comm=0xc4027ce9, color=0, key=0, new_comm=0x7ffe37e477d0) failed
PMPI_Comm_split(508)................: fail …Run Code Online (Sandbox Code Playgroud) 我使用分配时的自动分配来计算两个数组的差异,边界从 0 开始:
program main
implicit none
integer, allocatable :: a(:), b(:), c(:)
allocate(a(0:10))
allocate(b(0:10))
a = 1
b = 2
write (*,*) lbound(a)
write (*,*) lbound(b)
c = b - a
write (*,*) lbound(c)
end program main
Run Code Online (Sandbox Code Playgroud)
gfortran 和 ifort 都给出输出:
0
0
1
Run Code Online (Sandbox Code Playgroud)
为什么 c 与 a 和 b 的界限不同?是否有一种简短(没有显式分配)的方法来确保 c 具有相同的界限?
我在Python中有以下布尔语句:
db_connection.query(
'select storage_time from traces where id=' + trace_id
).dictresult()[0]['storage_time'] == None
Run Code Online (Sandbox Code Playgroud)
它基本上检查是否有值storage_time,我想在Matlab中做同样的事情,但我找不到任何等同于None的东西.
你能帮帮我吗?
谢谢
我正在尝试在我的标签的xlabel中使用希腊字母.互联网上的每个解决方案都说Matlab会接受tex.但是代替delta符号,我的x轴简单地标记为'D'
a = plot(0:40, y);
hold on
plot(delta_T,brechkraft, 'x')
errorbar(delta_T, brechkraft,delta_b,'x');
title('2mm Oelschicht');
xlabel('\Delta');
ylabel('Brechkraft D in 1/cm');
annotation('textbox', [.2 .8 .1 .1],...
'String', {'Fit: f(x) = m*x + b', ['m = ', num2str(p(1)) ], ['b = ', num2str(p(2)) ]});
shg
hold off
saveas(a, 'abc1.png','png');
Run Code Online (Sandbox Code Playgroud) 我想根据某些条件从地图中删除一些元素:
#include <unordered_map>
#include <ranges>
#include <iostream>
int main() {
std::unordered_map<int, int> numbers = {{1,2}, {2,1}, {3,2}, {4,5}};
auto even = [](auto entry){return entry.second %2 == 0;};
for(auto& [key, val] : numbers | std::views::filter(even)) {
numbers.erase(val);
}
for(auto& [key, val] : numbers) {
std::cout << key << " " << val << "\n";
}
}
Run Code Online (Sandbox Code Playgroud)
但似乎我正在使基于范围的循环所需的迭代器无效:
4 5
3 2
1 2
Run Code Online (Sandbox Code Playgroud)
我知道如何使用迭代器显式地执行此操作,但是是否有一种基于范围的简洁方法来删除基于过滤器的元素?
在python中这样的声明:
from module import function354
Run Code Online (Sandbox Code Playgroud)
有道理,因为Python是一种解释器语言,我不希望python加载所有353个其他函数.
Fortran有一个类似的结构:
use module, only : function354
Run Code Online (Sandbox Code Playgroud)
我为什么要用这个?编译器无论如何都会创建一个*.mod文件,编译所有函数.如果我指定only-statement,是否有任何性能优势(在编译或运行时)?
我可以看到避免命名冲突可能会有所帮助,但除此之外,我并没有真正看到这一点.
我有一个代码,我在几个不同的集群上运行,它们都有不同的MPI和LAPACK组合.
这可能会导致问题.例如,我目前使用ifort的"-i8"选项,它可以正常使用LAPACK,但现在所有的MPI调用都被破坏了,因为它期望integer(4),而不是integer(8).
是否有一种优雅灵活的方式来根据本地MPI和LAPACK安装来调整整数类型?
硬编码每个特定呼叫的类型似乎只是非常麻烦和不灵活.
我沿着这个线创建了一个情节:
http://www.buildingwidgets.com/blog/2015/7/2/week-26-sunburstr
# devtools::install_github("timelyportfolio/sunburstR")
library(sunburstR)
# read in sample visit-sequences.csv data provided in source
# https://gist.github.com/kerryrodden/7090426#file-visit-sequences-csv
sequence_data <- read.csv(
paste0(
"https://gist.githubusercontent.com/kerryrodden/7090426/"
,"raw/ad00fcf422541f19b70af5a8a4c5e1460254e6be/visit-sequences.csv"
)
,header=F
,stringsAsFactors = FALSE
)
Run Code Online (Sandbox Code Playgroud)
在 Rstudio 中,我可以在查看器中单击:“导出 > 另存为网页...”
然后将绘图保存为交互式 html 文档。我想将此作为代码的一部分。如何使用 R 代码将绘图保存到 html?PDF/jpg 等有很多示例,但没有 html。
我有兴趣学习D.然而我有点被DMD所转变,因为它不是完全开源的.这就是我考虑使用LDC的原因,但我不确定它的状态是什么.在debian包中它说:
Version: 1:0.14.0.dfsg-1
LDC already compiles a lot of D code, but should still be considered beta quality. Take a look at the
tickets to get a better impression on what still needs to be implemented.
Run Code Online (Sandbox Code Playgroud)
我知道Debian存储库有时可能有点古老,但1.0.0似乎是最新的LDC版本.
我打算使用C语言编写的库.哪个编译器更适合这个目的?LDC还是DMD?我知道之前已经问过这个问题,但我发现的所有问题都比较陈旧,我想知道当前的状态.