简体   繁体   English

此代码传输的是1kb还是以位为单位? 有点困惑

[英]is this code transferring 1kb or in bits ? a little confused

i have been trying to test network performance, but have a question 我一直在尝试测试网络性能,但是有一个问题

static public void main(String[] args) 
{
    MPI.Init(args);
    int myrank = MPI.COMM_WORLD.Rank();
    int tag = 99;
    int maxlen = 104857600; 
    int minlen = 1; //1kb ?
    char [] sendbuff = new char [maxlen];
    char [] recvbuff = new char [maxlen];
    long speedKbps;
    long speedMbps;
    if (myrank == 0) 
    {
        for (int len = minlen; len <= maxlen; len *= 2) 
        { //len=*2 doubles the ping size each time
            long startTime = System.nanoTime();                  
            MPI.COMM_WORLD.Send(sendbuff, 0, len, MPI.CHAR, 1, tag);
            MPI.COMM_WORLD.Recv(recvbuff, 0, len, MPI.CHAR, 1, tag);
            long endTime = System.nanoTime();
            long duration = endTime - startTime;
            System.out.println("Time for the ping to be sent and recived of " + len + " kb is " + duration + " nanoseconds");
            double transferRate = (len/ duration ) ; //amount of data in kilobytes transferred in 1 second
            System.out.println("transferRate: " + transferRate + "KB per second");
        }
    }
}

The minlen = 1 , what size is this, is it 1 KB, 1 bit, 1 byte? minlen = 1 ,它的大小是1 KB,1位,1字节?

Thanks 谢谢

由于您的发送缓冲区使用char作为数据类型,因此它是字节。

Since you're sending items from a character array, len in each iteration of the loop is the number of characters to send. 由于您要从字符数组发送项目,因此循环的每次迭代中的len是要发送的字符数。 So the size of minlen=1 is the size of 1 character, which in Java is 2 bytes. 因此minlen = 1的大小为1个字符的大小,在Java中为2个字节。

Source for the size of a Java char Java char大小的来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM