当前位置: 首页 > wzjs >正文

南通做网站公司网站建设对电子商务的意义

南通做网站公司,网站建设对电子商务的意义,为什么企业需要建设网站?,metro网站模板文章目录 MPI Status & Probe动态的接收1 MPI_Status结构体查询的范例2 use MPI_Probe找出消息大小 MPI Status & Probe动态的接收 MPI_Recv将MPI_Status结构体的地址作为参数,可以使用MPI_STATUS_IGNORE 忽略。如果我们将 MPI_Status 结构体传递给 MPI_Re…

文章目录

    • MPI Status & Probe动态的接收
      • 1 MPI_Status结构体查询的范例
      • 2 use MPI_Probe找出消息大小

MPI Status & Probe动态的接收

MPI_RecvMPI_Status结构体的地址作为参数,可以使用MPI_STATUS_IGNORE 忽略。如果我们将 MPI_Status 结构体传递给 MPI_Recv 函数,则操作完成后将在该结构体中填充有关接收操作的其他信息。 三个主要的信息包括:

  • 发送端的rank,发送端的rank存储在结构体MPI_SOURCE元素中,如果声明一个MPI_Status state对象,则可以通过state.MPI_SOURCE访问rank。

    typedef struct MPI_Status {int count_lo;                  // 低位的计数值,表示接收到的数据量的低32位(可能与 count_hi_and_cancelled 组合成完整的 64 位计数)int count_hi_and_cancelled;    // 高位的计数值(如果存在高32位),同时包含一个“取消标志”位int MPI_SOURCE;                // 消息的源进程的 rank(表示接收消息是从哪个进程来的)int MPI_TAG;                   // 消息的标签(与发送时指定的标签对应,用于标识消息的类型)int MPI_ERROR;                 // 错误码(用于存储接收操作的返回状态,MPI_SUCCESS 表示成功)
    } MPI_Status;
    
  • 消息的标签,同上访问方式,访问MPI_TAG

  • 消息的长度,它在在结构体中没有预定义的元素。我们必须使用 MPI_Get_count 找出消息的长度。

    MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype, int *count)
    

    MPI_Get_count中需要传递 MPI_Status 结构体,消息的 datatype(数据类型),并返回 count。 变量 count 是已接收的 datatype 元素的数目。

1 MPI_Status结构体查询的范例

// mpicc mpi_status.cc -o mpi_status
// mpirun -np 2 ./mpi_status
#include <mpi.h>
#include <iostream>
#include <stdio.h>int main(int argc, char** argv) {MPI_Init(NULL, NULL);int world_size;MPI_Comm_size(MPI_COMM_WORLD, &world_size);if (world_size != 2) {fprintf(stderr, "Must use two processes for this example\n");MPI_Abort(MPI_COMM_WORLD, 1);}int world_rank;MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);const int MAX_NUMBERS = 100;int numbers[MAX_NUMBERS];int number_amount;if (world_rank == 0) {// Pick a random amount of integers to send to process onesrand(time(NULL));number_amount = (rand() / (float)RAND_MAX) * MAX_NUMBERS;// Send the amount of integers to process oneMPI_Send(numbers, number_amount, MPI_INT, 1, 0, MPI_COMM_WORLD);printf("0 sent %d numbers to 1\n", number_amount);} else if (world_rank == 1) {MPI_Status status;// Receive at most MAX_NUMBERS from process zeroMPI_Recv(numbers, MAX_NUMBERS, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);// After receiving the message, check the status to determine how many// numbers were actually receivedMPI_Get_count(&status, MPI_INT, &number_amount);// Print off the amount of numbers, and also print additional information// in the status objectprintf("1 received %d numbers from 0. Message source = %d, tag = %d\n",number_amount, status.MPI_SOURCE, status.MPI_TAG);}MPI_Barrier(MPI_COMM_WORLD);MPI_Finalize();return 0;
}
/******************************************************************
0 sent 91 numbers to 1
0 sent 91 numbers to 1
*******************************************************************/

2 use MPI_Probe找出消息大小

在库文件中的定义如下,可以看到与MPI_Recv很类似。可以使用 MPI_Probe 在实际接收消息之前查询消息大小。除了不接收消息之外,MPI_Probe会阻塞具有匹配标签和发送端的消息。消息可用时,会填充Status。然后,用户可以使用 MPI_Recv 接收实际的消息。

MPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status *status)
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>int main (int argc, char** argv) {MPI_Init(NULL, NULL);int world_size;MPI_Comm_size(MPI_COMM_WORLD, &world_size); // Get the number of processesif (world_size != 2) {fprintf(stderr, "Error: This program requires exactly 2 processes.\n");MPI_Abort(MPI_COMM_WORLD, 1);}int world_rank;MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); // Get the rank of the current processint number_of_amount = 0;if (world_rank == 0) {int MAX_NUMBERS = 100;int numbers[MAX_NUMBERS];srand(time(NULL));number_of_amount = (rand() / (float)RAND_MAX) * MAX_NUMBERS;MPI_Send(numbers, number_of_amount, MPI_INT, 1, 0, MPI_COMM_WORLD);printf("Process %d sent %d numbers to process %d.\n", world_rank, number_of_amount, 1);} else if (world_rank == 1) {MPI_Status status;MPI_Probe(0, 0, MPI_COMM_WORLD, &status);MPI_Get_count(&status, MPI_INT, &number_of_amount);int* number_buffer = (int*)malloc(sizeof(int) * number_of_amount);MPI_Recv(number_buffer, number_of_amount, MPI_INT, 0, 0, MPI_COMM_WORLD,MPI_STATUS_IGNORE);printf("1 dynamically received %d numbers from 0.\n",number_of_amount);free(number_buffer);}MPI_Finalize();
}
/******************************************************************
Process 0 sent 29 numbers to process 1.
1 dynamically received 29 numbers from 0.
*******************************************************************/

MPI_Probe 构成了许多动态 MPI 应用程序的基础。 例如,控制端/执行子程序在交换变量大小的消息时通常会大量使用 MPI_Probe。 作为练习,对 MPI_Recv 进行包装,将 MPI_Probe 用于您可能编写的任何动态应用程序。 它将使代码看起来更美好:-)
下一节将通过完整的代码例子说明send和recv为什么是阻塞通信。


文章转载自:

http://P1saulVI.ynbyk.cn
http://7Lu0xaNd.ynbyk.cn
http://Ii6bi9Vr.ynbyk.cn
http://kp5ZeJ5z.ynbyk.cn
http://ggegmMh7.ynbyk.cn
http://xSKvxYg8.ynbyk.cn
http://hlzNe1ZY.ynbyk.cn
http://fQu8Z5XI.ynbyk.cn
http://mgABDgG6.ynbyk.cn
http://4Bx2Cccl.ynbyk.cn
http://HhzPWKs9.ynbyk.cn
http://SnkWZ7AJ.ynbyk.cn
http://xrtRQ73t.ynbyk.cn
http://WTqVUmfK.ynbyk.cn
http://0HzmyDnU.ynbyk.cn
http://GF98amnL.ynbyk.cn
http://HoXOAq3T.ynbyk.cn
http://180SWsmO.ynbyk.cn
http://fGdkYiMZ.ynbyk.cn
http://o8twFDkZ.ynbyk.cn
http://wx7cbUWS.ynbyk.cn
http://BJlUSwrb.ynbyk.cn
http://poSNMKzT.ynbyk.cn
http://5bUFDqV9.ynbyk.cn
http://RhBvP9G1.ynbyk.cn
http://EEUXfDf8.ynbyk.cn
http://6EWZ1NO6.ynbyk.cn
http://BSTrwHbN.ynbyk.cn
http://tL5rqEw0.ynbyk.cn
http://FFp6H0uz.ynbyk.cn
http://www.dtcms.com/wzjs/638171.html

相关文章:

  • 网站项目上线流程网站 tag标签
  • 兰州网站建设和推广安阳 做网站
  • 英文网站的外部链接 建设广州网站优化工具服务
  • 无代码建站WordPress对象储存
  • 做婚介打么网站好批量导文章到wordpress
  • 在网站和网页的区别全景效果图网站
  • 机械加工网站推广有效果吗html制作网站
  • 做羽毛球网站网络推广的几种主要方法
  • 北京南站附近景点网站里的横幅怎么做
  • 中山的网站建设公司淮南网约车平台
  • 一键建站系统有哪些如何自学网站建设书籍
  • wordpress建站邮件搜索引擎推广的简称是
  • 网站开发手机自适应深圳工业设计公司哪家好
  • 酒店网站模板wordpress 获取网址
  • 如何自己创建网站手机站喝茶影视
  • 专业seo网站优化石家庄又封了
  • 自己的电脑做网站会收录吗浙江省建设部网站
  • 做彩票网站服务器做出网站
  • 济南 论坛网站建设龙岩有什么公司
  • 三位数的域名网站网站页面大小
  • 推广网站的方法有搜索引擎网站开发与设计难嘛
  • 模板网站建设公司 东莞做微信公众号的是哪个网站
  • wordpress 分享 网站公司在选择网站时应考虑什么
  • 网站前端设计培训电商网站开发平台哪个好
  • 济南网站建设选聚搜网络如何在电脑上制作网页
  • 深圳建筑网站企业网站制作 西安
  • 万户做网站怎么样培训公司网站建设
  • 建设网站郑州h5视频
  • 做视频网站要多大带宽怎么建设h5网站
  • 哈尔滨网站建设优化怎样建立自己的微信公众号