#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:
returnsizeof(char);
case MPI_SHORT:
case MPI_UNSIGNED_SHORT:
returnsizeof(short);
case MPI_INT:
case MPI_UNSIGNED:
returnsizeof(int);
case MPI_LONG:
case MPI_UNSIGNED_LONG:
returnsizeof(long);
case MPI_FLOAT:
returnsizeof(float);
case MPI_DOUBLE:
returnsizeof(double);
case MPI_FLOAT_INT:
returnsizeof(float)+sizeof(int);
case MPI_LONG_INT:
returnsizeof(long)+sizeof(int);
case MPI_DOUBLE_INT:
returnsizeof(double)+sizeof(int);
case MPI_SHORT_INT:
returnsizeof(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){
#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
}