Skip to content

Instantly share code, notes, and snippets.

Для выбора ответа в {} написать +.
В каждом вопросе только один верный ответ.
# Threads, processes
1. Каким вызовом создастся новый поток?
{} A. CreateThread
{} B. vfork
// with exact num of chans
func waitAllChans(chans [3]chan int) {
for {
select {
case a, ok := <-chans[0]:
if !ok {
chans[0] = nil
break
}
fmt.Println("chan", 0, "return val", a)
// with exact num of chans
func waitAllChans(chans [3]chan int) {
for {
select {
case a, ok := <-chans[0]:
if !ok {
chans[0] = nil
break
}
fmt.Println("chan", 0, "return val", a)
// with random num of chans
func waitAllChans(chans []chan int) {
for {
closedChans := 0
for _, currCh := range chans {
select {
case val, ok := <-currCh:
if !ok {
closedChans += 1
break
def fib(n: int):
if n <= 0:
return 0
if n == 1:
return 1
return fib(n - 1) + fib(n - 2)
n = int(input())
result = fib(n)
def fib(n: int):
if n <= 0:
return 0
if n == 1:
return 1
return fib(n - 1) + fib(n - 2)
n = int(input())
result = fib(n)
B1="/home/am/dev/cpp/playground/bench/1000_1.txt"
B2="/home/am/dev/cpp/playground/bench/1000_2.txt"
OUTFILE="/home/am/dev/cpp/playground/res.txt"
MATRIX_SIZE=1440
ALGORITHM="-r" # "-c" "-s"
LOG_DIR="home/am/dev/cpp/playground/logs/"
mpirun --hostfile hostfile -np 8 ./prog -- "${ALGORITHM}" "${OUTFILE}" "${LOG_DIR}" "${B1}" "${B2}" ${MATRIX_SIZE}
# check correctness
python3 ./check.py
// #include <cstdint>
#include <fstream>
#include <iostream>
#include <vector>
#include <chrono>
#include <mpi.h>
#include <cmath>
inline void show(const std::vector<int> &v)
{
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
int main(int argc, char **argv)
{
if (argc != 2)
{
import numpy as np
n = int(input())
matrix1 = np.loadtxt("/home/am/dev/cpp/playground/bench/1000_1.txt")
matrix2 = np.loadtxt("/home/am/dev/cpp/playground/bench/1000_2.txt")
matrix3 = np.loadtxt("/home/am/dev/cpp/playground/res.txt")
result = matrix1 @ matrix2