突突唧之家

我的疑问 & 我的解决方案

Use the set -e builtin:

#!/bin/bash

set -e
# Any subsequent(*) commands which fail will cause the shell script to exit immediately

Alternatively, you can pass -e on the command line:

bash -e my_script.sh

You can also disable this behavior with set +e.

You may also want to employ all or some of the the -e -u -x and -o pipefail options like so:

set -euxo pipefail

-e exits on error, -u errors on undefined variables, and -o (for option) pipefail exits on command pipe failures.

The shell does not exit if the command that fails is part of the command list immediately following a while or until keyword, part of the test following the if or elif reserved words, part of any command executed in a && or || list except the command following the final && or ||, any command in a pipeline but the last, or if the command's return value is being inverted with !.

Try mkdir -p:

mkdir -p foo

Note that this will also create any intermediate directories that don't exist; for instance,

mkdir -p foo/bar/baz

will create directories foo, foo/bar, and foo/bar/baz if they don't exist.

Some implementation like GNU mkdir include mkdir --parents as a more readable alias, but this is not specified in POSIX/Single Unix Specification. It is also not available on many common platforms like macOS, various BSDs, and various commercial Unixes, so it should be avoided.

According to MPI_AllReduce man page and MPI doc MPI_IN_PLACE can be used to specify the same buffer for sendbuf and recvbuf as long as you are working inside the same group.

The call would look like:

// Some operations to calculate `rho` for each process.
double rho[1024] = ...;

MPI_Allreduce(MPI_IN_PLACE, rho, 1024, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);

1
2
3
4
5
6
7
8
9
10
11
cmake_minimum_required(VERSION 3.17)
project(MPITest)

find_package(MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH})

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_COMPILER mpicxx)
set(CMAKE_C_COMPILER mpicc)

add_executable(${PROJECT_NAME} main.cpp)

Windows will keep a history of the items you have searched over time. So, each time you type in a search query, you will see a list of recently searched items. You might want to clear this from time to time, especially if you're on a shared PC or if you just want a fresh start. We already showed you how to turn off autocomplete in File Explorer. For even more control over file navigation, here is a look at how to clear recent File Explorer search history or disable it altogether.

阅读全文 »

The following is a step-by-step process as to how you can use wireless internet without taking out your ethernet cable out.

  1. Open Network and Sharing Centre ("Network Status" in Windows 10).
  2. Go to "Change Adapter Settings" ("Change adapter options" in Windows 10).
  3. Go to properties of Local Area Network.
  4. Click on Internet Protocol version 4 and go to its properties.
  5. Click on Advanced. You will see a block checked there by the name of "Automatic Metric".
  6. Uncheck it and then enter 2 in that section.
  7. Now, Do the same for the wireless network but enter 1.

Save the setting, and you'll be able to use Wi-Fi even when your ethernet cable is connected to the LAN.

"Automatic metric" works by prioritizing the connection with the highest link speed. Manually changing the setting means you can specify which connection you want to give priority to. See "An explanation of the Automatic Metric feature for IPv4 routes".

In Chrome & Firefox (+31) you can add CSS in console.log messages:

console.log('%cHello, world!', 'background: red; color: green')

The same can be applied for adding multiple CSS to a command:

console.log('%c<str1> %c<str2>', '<css-for-str1>', '<css-for-str2>')

Chrome Console API Reference: Console API Reference.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}

async function demo() {
console.log('Taking a break...')
await sleep(2000)
console.log('Two seconds later, showing sleep in a loop...')

// Sleep in loop
for (let i = 0; i < 5; i++) {
if (i === 3)
await sleep(2000)
console.log(i)
}
}

demo()

This is it. await sleep(<duration>).

Or as a one-liner:

await new Promise(r => setTimeout(r, 2000))

Note

await can only be executed in functions prefixed with the async keyword, or at the top level of your script in some environments (e.g., the Chrome DevTools console, or Runkit).

await only pauses the current async function

Two new JavaScript features helped write this "sleep" function:

When working with Git, you might encounter a situation where you need to edit a commit message. There are many reasons you would want to make the change, such as fixing a typo, removing sensitive information, or adding additional information.

This guide explains how to change the message of the most recent or older Git commits.

阅读全文 »