切换数量不是整数 [英] Switch quantity not an integer

查看:102
本文介绍了切换数量不是整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试编译以下程序,但它给了我很多错误:



Hi,
I am trying to compile the following program but its giving me lots of errors:

#include <iostream>
#include <fstream>
#include <cmath>
#include <mpi.h>
#include <ctime>
#include <vector>

#define MYBUFFERLENGTH 1024
char myinbuffer[MYBUFFERLENGTH];
char myoutbuffer[MYBUFFERLENGTH];

extern "C" {
  int mikes_MPI_SIZE (MPI_Datatype datatype) {
    /* sizeof doesn't work for MPI_Datatype, thus this function */
    /* I probably should do this with a table, but then error
       checking is harder */
    /* see man MPI_COMM_WORLD */
    switch (datatype){
    case MPI_CHAR:
    case MPI_BYTE:
    case MPI_UNSIGNED_CHAR:
      return sizeof(char);
    case MPI_SHORT:
    case MPI_UNSIGNED_SHORT:
      return sizeof(short);
    case MPI_INT:
    case MPI_UNSIGNED:
      return sizeof(int);
    case MPI_LONG:
    case MPI_UNSIGNED_LONG:
      return sizeof(long);
    case MPI_FLOAT:
      return sizeof(float);
    case MPI_DOUBLE:
      return sizeof(double);
    case MPI_FLOAT_INT:
      return sizeof(float)+sizeof(int);
    case MPI_LONG_INT:
      return sizeof(long)+sizeof(int);
    case MPI_DOUBLE_INT:
      return sizeof(double)+sizeof(int);
    case MPI_SHORT_INT:
      return sizeof(short)+sizeof(int);
    case MPI_2INT:
      return 2*sizeof(int);
    default:
      die("need to insert size for new datatype in mikes_MPI_SIZE()");
    }
    return -1;
  }
int MMPI_Reduce(void * sendbuf, void * recvbuf, int count, 
		 MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) {
   
    int bit,processor1,i;
  
    int *iaccum1;
    int *iaccum2;
    double *daccum1;
    double *daccum2;
    int * locaccum1;
    int * locaccum2;
    iaccum1=(int *) myinbuffer;
    iaccum2=(int *)(myinbuffer+mikes_MPI_SIZE(datatype));
    daccum1=(double *) myinbuffer;
    daccum2=(double *)(myinbuffer+mikes_MPI_SIZE(datatype));
    locaccum1=(int*)(myinbuffer+mikes_MPI_SIZE(datatype)-sizeof(int));
    locaccum2=(int*)(myinbuffer+2*mikes_MPI_SIZE(datatype)-sizeof(int));
    *locaccum1=*locaccum2=processor;
   return MPI_SUCCESS;
  }







我收到了几个错误,但我想删除以下错误:






I am getting several errors but I want to remove the following one:

$ mpic++ mpiBlkProb3.cpp
mpiBlkProb3.cpp: In function ‘int mikes_MPI_SIZE(MPI_Datatype)’:
mpiBlkProb3.cpp:43:21: error: switch quantity not an integer
     switch (datatype){







有些人请指导我。



Zulfi。



什么我试过了:



我无法理解这个错误。




Some body please guide me.

Zulfi.

What I have tried:

I can't understand this error.

推荐答案

mpic ++ mpiBlkProb3.cpp
mpiBlkProb3.cpp:在函数'int mikes_MPI_SIZE(MPI_Datatype)'中:
mpiBlkProb3.cpp:43:21:错误:切换数量不是整数
switch(datatype){
mpic++ mpiBlkProb3.cpp mpiBlkProb3.cpp: In function ‘int mikes_MPI_SIZE(MPI_Datatype)’: mpiBlkProb3.cpp:43:21: error: switch quantity not an integer switch (datatype){







有些人请指导我。



Zulfi。



我尝试了什么:



我可以不明白这个错误或。




Some body please guide me.

Zulfi.

What I have tried:

I can't understand this error.


我也不知道 - 我找到的 mpi.h 的版本( http://www.bu.edu/tech/files/text/mpi.h.txt [ ^ ])使用 typedef 定义 MPI_Datatype 作为 int 的别名 - 所以开关应该是无缝的。



检查 mpi.h 内容,并尝试创建一个生成相同错误的更简单的使用代码版本 - 可能更容易从中解决并扩展到您的代码。
Nor do I - the version of mpi.h that I found (http://www.bu.edu/tech/files/text/mpi.h.txt[^]) uses typedef to define MPI_Datatype as an alias for int - so the switch should be seamless.

Check the mpi.h content, and try creating a "simpler" version of your use code that generates the same error - it may be easier to work out from that and scale up to your code.


根据MPI_Datatype枚举 - 消息传递接口| Microsoft Docs [ ^ ], MPI_Datatype 是枚举,因此您可能需要将其强制转换为 int 切换到工作。
According to MPI_Datatype enumeration - Message Passing Interface | Microsoft Docs[^], MPI_Datatype is an enum, so you probably need to cast it to an int for the switch to work.


这篇关于切换数量不是整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆