我正在玩图像docker CentOS,发现/usr/bin/env bash -x在终端中执行“”命令是可以的:
bash-4.1# /usr/bin/env bash -x
bash-4.1# exit
+ exit
exit
Run Code Online (Sandbox Code Playgroud)
但是把这个命令写成脚本执行后却不起作用,提示“ No such file or directory”:
bash-4.1# ls -lt a.sh
-rwxr-xr-x. 1 root root 23 May 20 04:27 a.sh
bash-4.1# cat a.sh
#!/usr/bin/env bash -x
bash-4.1# ./a.sh
/usr/bin/env: bash -x: No such file or directory
Run Code Online (Sandbox Code Playgroud)
两种方法有什么区别吗?
我正在阅读专业CUDA C编程,并在GPU架构概述部分:
CUDA采用单指令多线程(SIMT)架构来管理和执行32个被称为warp的组中的线程.warp中的所有线程同时执行相同的指令.每个线程都有自己的指令地址计数器和寄存器状态,并对自己的数据执行当前指令.每个SM将分配给它的线程块分区为32线程warp,然后调度它以便在可用的硬件资源上执行.
SIMT架构类似于SIMD(单指令,多数据)架构.SIMD和SIMT都通过向多个执行单元广播相同的指令来实现并行性.一个关键的区别是SIMD要求向量中的所有向量元素在一个统一的同步组中一起执行,而SIMT允许同一warp中的多个线程独立执行.即使warp中的所有线程在同一程序地址处一起启动,单个线程也可能具有不同的行为.SIMT使您能够为独立的标量线程编写线程级并行代码,以及为协调线程编写数据并行代码.SIMT模型包括SIMD不具备的三个关键功能:
➤每个线程都有自己的指令地址计数器.
➤每个线程都有自己的寄存器状态.
➤每个线程都可以有一个独立的执行路径.
第一段提到" All threads in a warp execute the same instruction at the same time.",而在第二段则提到" Even though all threads in a warp start together at the same program address, it is possible for individual threads to have different behavior.".这让我感到困惑,上述陈述似乎是矛盾的.任何人都可以解释一下吗?
在第85页,专业的CUDA C编程:
int main()
{
......
// run a warmup kernel to remove overhead
size_t iStart,iElaps;
cudaDeviceSynchronize();
iStart = seconds();
warmingup<<<grid, block>>> (d_C);
cudaDeviceSynchronize();
iElaps = seconds() - iStart;
printf("warmup <<< %4d %4d >>> elapsed %d sec \n",grid.x,block.x, iElaps );
// run kernel 1
iStart = seconds();
mathKernel1<<<grid, block>>>(d_C);
cudaDeviceSynchronize();
iElaps = seconds() - iStart;
printf("mathKernel1 <<< %4d %4d >>> elapsed %d sec \n",grid.x,block.x,iElaps );
// run kernel 3
iStart = seconds();
mathKernel2<<<grid, block>>>(d_C);
cudaDeviceSynchronize();
iElaps = seconds …Run Code Online (Sandbox Code Playgroud) 我的要求是这样的:每个线程自己分配内存,然后处理它:
typedef struct
{
......
}A;
A *p[N];
#pragma omp parallel
{
#pragma omp for
for (int i = 0; i < N; i++) {
p[i] = (A*)calloc(sizeof(*p[i]), N);
if (NULL == p[i]) {
return;
}
......
}
}
Run Code Online (Sandbox Code Playgroud)
但编译器会抱怨:
error: invalid exit from OpenMP structured block
return;
Run Code Online (Sandbox Code Playgroud)
所以除了把分配内存代码放在#pragma omp parallel:
for (int i = 0; i < N; i++) {
p[i] = (A*)calloc(sizeof(*p[i]), N);
if (NULL == p[i]) {
return;
}
}
#pragma omp parallel
{
#pragma …Run Code Online (Sandbox Code Playgroud) 从std::iter::Iterator文档中,我可以看到只next需要方法:
所需方法
Run Code Online (Sandbox Code Playgroud)fn next(&mut self) -> Option<Self::Item>
但是从源代码中删除注释后:
pub trait Iterator {
/// The type of the elements being iterated over.
#[stable(feature = "rust1", since = "1.0.0")]
type Item;
......
#[stable(feature = "rust1", since = "1.0.0")]
fn next(&mut self) -> Option<Self::Item>;
......
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn size_hint(&self) -> (usize, Option<usize>) { (0, None) }
......
}
Run Code Online (Sandbox Code Playgroud)
我可以看到,除了#[inline]属性,必需方法和提供的方法之间没有区别.Rust如何知道需要或提供哪种方法?
我运行以下 Go 代码 10 次:
package main
import (
"fmt"
"time"
)
func main() {
go fmt.Println("Hello")
fmt.Println("World")
time.Sleep(1 * time.Millisecond)
}
Run Code Online (Sandbox Code Playgroud)
输出总是“ World”在前:
World
Hello
Run Code Online (Sandbox Code Playgroud)
它是否表明例程goroutine中存在块将执行单元main?的执行时间点是什么goroutine?
在Lua 5.3.0,我运行" true and print("Hi")":
> true and print("Hi")
Hi
nil
Run Code Online (Sandbox Code Playgroud)
为什么程序输出nil?
我遇到了一个关于内存使用的麻烦错误,所以我想在 Solaris 10 上使用 Dtrace 来检查 malloc 和 free。
我使用以下命令
dtrace -l | grep malloc
Run Code Online (Sandbox Code Playgroud)
输出是:
7000 fbt unix prom_malloc entry
7001 fbt unix prom_malloc return
7141 fbt genunix cacl_malloc entry
7142 fbt genunix cacl_malloc return
12319 fbt genunix rmallocmap_wait entry
12320 fbt genunix rmallocmap_wait return
13078 fbt genunix rmalloc_wait entry
13079 fbt genunix rmalloc_wait return
13526 fbt genunix rmallocmap entry
13527 fbt genunix rmallocmap return
16846 fbt genunix rmalloc entry
16847 fbt genunix rmalloc return
25931 fbt tmpfs tmp_memalloc …Run Code Online (Sandbox Code Playgroud) 我在Solaris中编写了一个简单的C程序,并希望检查以下的汇编代码dup:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int pdes[2];
if(-1 != (pipe(pdes)))
{
//printf("%d\n", dup(pdes[0]));
dup(pdes[0]);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
(1)我使用gdb,并gdb输出汇编代码:
(gdb) disassemble dup
Dump of assembler code for function dup:
0xff2cda44 <+0>: mov 0x29, %g1 ! 0x29
0xff2cda48 <+4>: ta 8
0xff2cda4c <+8>: bcs 0xff223be0 <_cerror>
0xff2cda50 <+12>: nop
0xff2cda54 <+16>: retl
0xff2cda58 <+20>: nop
End of assembler dump.
Run Code Online (Sandbox Code Playgroud)
(2)我使用mdb,并mdb输出汇编代码:
> dup::dis
PLT:dup: …Run Code Online (Sandbox Code Playgroud) 我们的软件密码存储在网页中,并且喜欢这样:
Last month: suilwoid
This month: suewkhud
Next month: guenkhid
Run Code Online (Sandbox Code Playgroud)
我想编写一个Bash脚本来获取本月的密码,简单的脚本喜欢这样:
wget http://passwd.xxx.com/~perf/passwd.php &
wait
echo `grep "This month" passwd.php | awk '{ print $3 }'`
Run Code Online (Sandbox Code Playgroud)
这个脚本可以满足我的要求,但我想知道如何更优雅地实现这个脚本.
例如,是否可以使用管道来连接命令?除了awk,是否有更好的命令来解析密码?
以下Go代码运行正常:
package main
import "fmt"
func main() {
if j := 9; j > 0 {
fmt.Println(j)
}
}
Run Code Online (Sandbox Code Playgroud)
但在条件中添加括号后:
package main
import "fmt"
func main() {
if (j := 9; j > 0) {
fmt.Println(j)
}
}
Run Code Online (Sandbox Code Playgroud)
有编译错误:
.\Hello.go:7: syntax error: unexpected :=, expecting )
.\Hello.go:11: syntax error: unexpected }
Run Code Online (Sandbox Code Playgroud)
为什么编译器会抱怨它?
#include <iostream>
#include <sstream>
// base case
void doPrint(std::ostream &out) {}
template <typename T, typename... Args>
void doPrint(std::ostream &out, T t, Args... args)
{
out << t; // add comma here, see below
doPrint(out, args...);
}
int main() {
// See how it works even better than varargs?
doPrint(std::cout, "Hola", " mundo ");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是如果我从参考中更改功能参数
void doPrint(std::ostream &out)
......
template <typename T, typename... Args>
void doPrint(std::ostream &out, T t, Args... args)
Run Code Online (Sandbox Code Playgroud)
值:
void …Run Code Online (Sandbox Code Playgroud)