Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
#include
using namespace std; const int m = 1000; //предел массива от - m/2 до + m/2 в int create_num(int A) //рандомное число (переменная rank) { int number; srand(time(NULL) + A); number = (rand() % m) - m / 2; return number; } int file_read() // считываем количество потоков { ifstream fileout; fileout.open("run.bat");//открытие файла int max = -1; if (fileout.is_open())//Если открытие файла прошло успешно { string line; getline(fileout, line); getline(fileout, line); line = line.substr(line.find("n ") + 2); line = line.substr(0, line.find(" ")); fileout.close(); //Закрываем файл max = stoi(line); } else { cout << "file not open" << endl; } return max; } int main(int argc, char** argv) { int rank, size, n = 0; int max = file_read() ; // считываем количество вызовов int* rbuf = new int[max]; for (int i = 0; i < max; i++) rbuf[i] = 0; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); n = create_num(rank); MPI_Gather(&n, 1, MPI_INT, rbuf, 1, MPI_INT, 0, MPI_COMM_WORLD); cout << "Rank: " << rank << " Number: " << n << endl; if (rank == 0) { if (max != -1) //проверка считалось ли значение из файла { int sum = 0; for (int i = 0; i < max; i++) sum += rbuf[i]; cout << "summ = " << sum << endl; } else { cout << "value undefined"; } } MPI_Finalize(); return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)