0

こんにちはすべて私はこのコードを作成しました:

import mpi.* ;

class Hello {

  static public void main(String[] args) {
    MPI.Init(args);



int myrank = MPI.COMM_WORLD.Rank();
long startTime = System.currentTimeMillis();
if (myrank == 0) {
        String s = "111";
        byte[] bytes = s.getBytes();
        StringBuilder binary = new StringBuilder();
        for (byte b : bytes) {
            int val = b;
            for (int i = 0; i < 8; i++) {
                binary.append((val & 128) == 0 ? 0 : 1);
                val <<= 1;
            }
            binary.append(' ');
        }
        System.out.println("'" + s + "' to binary: " + binary);

//int i = 54564;  
//String text = String.format("%15d", i);
//System.out.println(message);  //testing

    char[] mess = binary.toCharArray();
    MPI.COMM_WORLD.Send(mess, 0, mess.length, MPI.CHAR, 1, 99);
} else {
    char[] mess = new char[20];
    MPI.COMM_WORLD.Recv(mess, 0, 200, MPI.CHAR, 0, 99);
    System.out.println("received:" + new String(mess));
}

long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
System.out.println(duration);
    MPI.Finalize();
  }
}   

111入力からバイナリ形式で3バイトを作成し、これらの3バイトをネットワーク上の別のマシンに送信します(基本的なピンポンプログラム)。

しかし、私はそれをコンパイルすることができません

これらのエラーが発生します:

Hello.java:28: error: cannot find symbol
    char[] mess = binary.toCharArray();
                        ^
  symbol:   method toCharArray()
  location: variable binary of type StringBuilder
1 error

C:\Users\Richard\Dropbox\Year 3\DISPARP\Coursework>javac Hello.java
Hello.java:30: error: cannot find symbol
    char[] mess = binary.toCharArray();
                        ^
  symbol:   method toCharArray()
  location: variable binary of type StringBuilder
1 error

また別の質問は

111' to binary: 00110001 00110001 00110001 

3バイト?

編集 :

に変更されましたchar[] mess = binary.toString().toCharArray();

しかし、今ではより多くのエラーが発生します:(

MPJ Express (0.35) is started in the cluster configuration
Starting process <0> on <Raptor>
Starting process <1> on <Predator>
'111' to binary: 00110001 00110001 00110001
340
mpi.MPIException: java.lang.ArrayIndexOutOfBoundsException: Out of bounds in des
t array: 26
        at mpi.SimplePackerChar.unpack(SimplePackerChar.java:112)
        at mpi.Comm.recv(Comm.java:1305)
        at mpi.Comm.Recv(Comm.java:1255)
        at Hello.main(Hello.java:34)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at runtime.daemon.Wrapper.execute(Wrapper.java:165)
        at runtime.daemon.Wrapper.main(Wrapper.java:180)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Out of bounds in dest array
: 26
        at mpjbuf.Buffer.readCheckArgs(Buffer.java:3650)
        at mpjbuf.Buffer.read(Buffer.java:3333)
        at mpi.SimplePackerChar.unpack(SimplePackerChar.java:110)
        ... 9 more
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at runtime.daemon.Wrapper.execute(Wrapper.java:165)
        at runtime.daemon.Wrapper.main(Wrapper.java:180)
Caused by: mpi.MPIException: mpi.MPIException: mpi.MPIException: java.lang.Array
IndexOutOfBoundsException: Out of bounds in dest array: 26
        at mpi.Comm.Recv(Comm.java:1259)
        at Hello.main(Hello.java:34)
        ... 6 more
Caused by: mpi.MPIException: mpi.MPIException: java.lang.ArrayIndexOutOfBoundsEx
ception: Out of bounds in dest array: 26
        at mpi.Comm.recv(Comm.java:1317)
        at mpi.Comm.Recv(Comm.java:1255)
        ... 7 more
Caused by: mpi.MPIException: java.lang.ArrayIndexOutOfBoundsException: Out of bo
unds in dest array: 26
        at mpi.SimplePackerChar.unpack(SimplePackerChar.java:112)
        at mpi.Comm.recv(Comm.java:1305)
        ... 8 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: Out of bounds in dest array
: 26
        at mpjbuf.Buffer.readCheckArgs(Buffer.java:3650)
        at mpjbuf.Buffer.read(Buffer.java:3333)
        at mpi.SimplePackerChar.unpack(SimplePackerChar.java:110)
        ... 9 more
4

1 に答える 1

2

のメソッドtoCharArrayは定義されていませんStringBuilder。ただし、String返された from のメソッドを使用できtoStringます。

char[] mess = binary.toString().toCharArray();

編集:私は慣れていませんMPIが、char配列バッファーを大きくして、より多くのデータを受け入れるようにしてRecvください:

char[] mess = new char[2000];
MPI.COMM_WORLD.Recv(...);
于 2013-03-23T21:40:15.270 に答える