00001 
00002 
00003 
00004 
00005 
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <string.h>
00009 #include "ccs-client.h"
00010 #include "pup.h"
00011 #include "pup_toNetwork4.h"
00012 #include "conv-config.h"
00013 #include "netfem_data.h"
00014 
00015 
00016 void printStats(const double *data,int rows,int cols)
00017 {
00018     double *max=new double[cols];
00019     double *min=new double[cols];
00020     double *sum=new double[cols];
00021     int c;
00022     for (c=0;c<cols;c++) {
00023         max[c]=-1.0e30;
00024         min[c]=1.0e30;
00025         sum[c]=0.0;
00026     }
00027     for (int r=0;r<rows;r++) {
00028         for (c=0;c<cols;c++) {
00029             double v=data[r*cols+c];
00030             if (v<min[c]) min[c]=v;
00031             if (v>max[c]) max[c]=v;
00032             sum[c]+=v;
00033         }
00034     }
00035     printf(" Summary statistics:\n");
00036     for (c=0;c<cols;c++) {
00037         printf("   [%d]: min=%.3g, max=%.3g, ave=%.3g\n",
00038             c,min[c],max[c],sum[c]/rows);
00039     }
00040     delete[] max; delete[] min; delete[] sum;
00041     
00042 }
00043 
00044 void print(const NetFEM_item &t) {
00045     printf("%d items, %d fields\n",t.getItems(),t.getFields());
00046     int nf=t.getFields();
00047     for (int fn=0;fn<nf;fn++) {
00048         const NetFEM_item::doubleField &f=t.getField(fn);
00049         int wid=f.getDoublesPerItem();
00050         int n=f.getItems();
00051         printf(" Field '%s': %d x %d  (%s)\n",
00052             f.getName(),n,wid,
00053             f.getSpatial()?"spatial":"list");
00054         
00055         printStats(f.getData(0),n,wid);
00056         printf("\n");
00057     }
00058 }
00059 
00060 
00061 void print(const NetFEM_update &u) {
00062     printf("------- Timestep %d, Chunk %d ----------------\n",
00063         u.getTimestep(),u.getChunk());
00064     printf("Nodes: ---------------\n");
00065     print(u.getNodes());
00066     for (int i=0;i<u.getElems();i++)
00067     {
00068         printf("Element type %d: ---------------\n",i);
00069         print(u.getElem(i));
00070     }
00071 }
00072 
00073 
00074 int main(int argc,char *argv[]) {
00075     if (argc<3) {
00076         fprintf(stderr,"Usage: %s <host> <port> ...\n",argv[0]);
00077         exit(1);
00078     }
00079     const char *host=argv[1];
00080     int port=atoi(argv[2]);
00081     CcsServer svr;
00082     printf("Connecting to %s:%d\n",host,port);
00083     CcsConnect(&svr,host,port,NULL);
00084 
00085     int totNodes=0,totElem=0;
00086     int pe,nPe=CcsNumPes(&svr);
00087     for (pe=0;pe<nPe;pe++) {
00088         
00089         printf("Sending request to PE %d...\n",pe);
00090         CcsSendRequest(&svr,"NetFEM_current",pe,0,NULL);
00091         char *reply; unsigned int replySize;
00092         printf("Receiving response from PE %d...\n",pe);
00093         CcsRecvResponseMsg(&svr,&replySize,&reply,60);
00094         
00095         
00096         printf("Unpacking %d-byte response:\n",(int)replySize);
00097         NetFEM_update u(0,0);
00098         {PUP_toNetwork4_unpack p(reply); u.pup(p);}
00099         
00100         totNodes+=u.getNodes().getItems();
00101         totElem+=u.getElem(0).getItems();       
00102 
00103         print(u);
00104         
00105     }
00106 }
00107 
00108 
00109 
00110