所以我有一些代码,我使用MPI_Bcast将信息从根节点发送到所有节点,但我想让我的P0将数组的块发送到各个进程.
如何使用MPI_Send和MPI_Receive执行此操作?
我以前从未使用过它们,我不知道是否需要循环使用MPI_Receive来有效地发送所有内容或内容.
我把巨型大写锁定注释放在我需要替换我的MPI_Bcast()的代码中,抱歉提前代码的瀑布.
码:
#include "mpi.h"
#include <stdio.h>
#include <math.h>
#define MAXSIZE 10000000
int add(int *A, int low, int high)
{
int res = 0, i;
for(i=low; i<=high; i++)
res += A[i];
return(res);
}
int main(argc,argv)
int argc;
char *argv[];
{
int myid, numprocs, x;
int data[MAXSIZE];
int i, low, high, myres, res;
double elapsed_time;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
if (myid == 0)
{
for(i=0; i<MAXSIZE; i++)
data[i]=1;
}
/* star the timer */
elapsed_time = -MPI_Wtime();
//THIS IS WHERE …Run Code Online (Sandbox Code Playgroud) 我有两个ArrayLists.
第一个包含一组带有大写和标点符号的单词.
另一个包含同一组词,但删除了大写和标点符号.
.
ArrayList1 ..... ArrayList2
MURDER! ........ murder
It's ........... its
Hello .......... hello
Yes-Man ........ yesman
ON ............. on
Run Code Online (Sandbox Code Playgroud)
第二个数组具有按字母顺序排列的所有单词,并且每个单词中的所有字母都按字母顺序排列.它看起来像这样:
aemnsy
demrru
ehllo
ist
no
Run Code Online (Sandbox Code Playgroud)
我想这样做,以便当我将ArrayList中的单词排列成字母顺序时,所有来自ArrayList的单词都遵循套件:
ArrayList1 ..... ArrayList2
Yes-Man ........ aemnsy
MURDER! ........ demrru
Hello .......... ehllo
It's ........... ist
ON ............. no
Run Code Online (Sandbox Code Playgroud)
我尝试用一个或两个for语句创建一个循环,但它最终没有工作并变得很长.我该怎么做呢?我该如何有效地做到这一点?
在很多帮助下,我开发了一种制作字谜的方法,然后将它们添加到一个ArrayList.
public void f(String s, String anagram, ArrayList<String> array)
{
if(s.length() == 0)
{
array.add(anagram);
return;
}
for(int i = 0 ; i < s.length() ; i++)
{
char l = s.charAt(i);
anagram = anagram + l;
s = s.substring(0, i) + s.substring(i+l, s.length());
f(s,anagram,array);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我尝试使用此函数ArrayList在循环中将s添加String到一个ArrayList到另一个时,我得到一个错误,说我不能使用void,并且该方法f()是无效的.
List<String> Lists = new ArrayList<String>(); //makes new array list
for(String List : words)
{ //takes values from old array list
List.trim();
Lists.add(f(List,"",new …Run Code Online (Sandbox Code Playgroud) 我在java中创建一个程序,它将读取一个文件并将每个单词放入一个数组中,这样我就可以在将每个单词排序为默认数组之后制作一个单词.我很清楚如何做到这一点,除了我的.txt文件没有被读取.我在src中有一个名为"input.txt"的文件,其中包含我正在编写的"anagram.java"程序,但是当代码为文件条目提供时,在输入文件名"input.txt"时,我的代码说文件不存在我得到这个:
Enter file name:
input.txt
Exception in thread "main" java.io.FileNotFoundException: input.txt (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at java.io.FileInputStream.<init>(FileInputStream.java:79)
at java.io.FileReader.<init>(FileReader.java:41)
at anagram.main(anagram.java:23)
Java Result: 1
BUILD SUCCESSFUL (total time: 6 seconds)
Run Code Online (Sandbox Code Playgroud)
这是乱七八糟的行的代码:
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter file name: ");
String fileName = br.readLine();
File file = new File(fileName);
if(file.length() == 0)
{
System.out.println("File is empty");
System.exit(1);
}
Run Code Online (Sandbox Code Playgroud)
显然输入"input.txt"的信息还不够,我不确定.我删除了
if(file.length() == 0)
{
System.out.println("File is …Run Code Online (Sandbox Code Playgroud)