add pup support
[charm.git] / src / util / pup_util.C
index 3bdd4bc11a979ce72443d3f7731820abfa61a530..d0fc07e7a3147d0666a84226aff3a294fead4ddf 100644 (file)
@@ -17,6 +17,7 @@ virtual functions are defined here.
 #include <string.h>
 #include <ctype.h>
 #include <errno.h>
+#include <math.h>
 
 #include "converse.h"
 #include "pup.h"
@@ -137,6 +138,76 @@ void PUP::fromMem::bytes(void *p,int n,size_t itemSize,dataType t)
        buf+=n;
 }
 
+void PUP::checker::bytes(void * p,int n,size_t itemSize,dataType t)
+{
+       n*=itemSize;
+       memcpy(p,(const void *)origBuf,n); 
+       if(!_skip){
+               //get the data work for certain type
+               switch(t){
+                       case Tdouble:
+                               {
+                                       double * p1 = new double[n/itemSize];
+                                       double * p2 = new double[n/itemSize];
+                                       p1 = (double*)p;
+                                       memcpy((char *)p2,(const void *)buf,n); 
+                                       for(int i=0;i<n/itemSize;i++){
+                                               if(fabs(p1[i]-p2[i])>accuracy){
+                                                       if(result)
+                                                               printf("found incorrect double %lf %lf\n",p1[i],p2[i]);
+                                                       result = result && false;
+                                               }
+                                       }
+                               }       
+                               break;  
+                       case Tint:
+                               {
+                                       int * p1 = new int[n/itemSize];
+                                       int * p2 = new int[n/itemSize];
+                                       p1 = (int *)p;
+                                       memcpy((char *)p2,(const void *)buf,n); 
+                                       for(int i=0;i<n/itemSize;i++){
+                                               if(fabs(p1[i]-p2[i])>accuracy){
+                                                       if(result)
+                                                               printf("found incorrect int %d %d\n",p1[i],p2[i]);
+                                                       result = result && false;
+                                               }
+                                               //printf("p1 %d\n",p1[i]);
+                                               //printf("p2 %d\n",p2[i]);
+                                       }
+                                       //printf("p %d\n",*(int *)p);
+                               }
+                               break;
+                       case Tchar:
+                               {
+                                       char * p1 = new char[n/itemSize];
+                                       char * p2 = new char[n/itemSize];
+                                       p1 = (char *)p;
+                                       memcpy((char *)p2,(const void *)buf,n); 
+                                       for(int i=0;i<n/itemSize;i++){
+                                               if(fabs(p1[i]-p2[i])>accuracy){
+                                                       if(result)
+                                                               printf("found incorrect char %c %c\n",p1[i],p2[i]);
+                                                       result = result && false;
+                                               }
+                                               //printf("p1 %d\n",p1[i]);
+                                               //printf("p2 %d\n",p2[i]);
+                                       }
+                                       //printf("p %d\n",*(int *)p);
+                               }
+                               break;
+                       default:
+                               break;
+               }
+       }
+       if(reset){
+               _skip = false;
+               reset = false;
+       }
+       origBuf+=n;
+       buf+=n;
+}
+
 // dealing with short write
 size_t CmiFwrite(const void *ptr, size_t size, size_t nmemb, FILE *f)
 {