switch quantity not an integer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

#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;
  }


There are several syntax errors but first I want to remove:

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){



Some body please guide me.
Zulfi.
Last edited on
Switch statements require an integral type. What type is "datatype"?

Hi,
I changed the code to following:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#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 ((MPI_Datatype) 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=processor1;
   return MPI_SUCCESS;
  }


but I am getting following errors:

$ mpic++ reduce.cpp
reduce.cpp: In function ‘int mikes_MPI_SIZE(MPI_Datatype)’:
reduce.cpp:18:36: error: switch quantity not an integer
switch ((MPI_Datatype) datatype){
^
reduce.cpp: At global scope:
reduce.cpp:70:3: error: expected ‘}’ at end of input
}


Some body please guide me.

Zulfi.
Hi,
I solved the problem using if-else:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#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) {
     if(datatype ==MPI_CHAR){
        return sizeof(char);
     }
     else if(datatype == MPI_DOUBLE){
        return sizeof(double);
     }
     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=processor1;
   return MPI_SUCCESS;
  }

int main(){
}


Compiling now

$ mpic++ reduce.cpp
$

Topic archived. No new replies allowed.