cgma
partest.cpp
Go to the documentation of this file.
00001 // Test parallel iGeom
00002 // July 09
00003 // Author : Hong-Jun Kim
00004 // read OCC geometry file and distribute it to remote processors
00005 // with various methods
00006 
00007 #include <iostream>
00008 #include <stdio.h>
00009 #include <string.h>
00010 #include <sys/resource.h>
00011 #include <unistd.h>
00012 #include <fcntl.h>
00013 #include <stdlib.h>
00014 
00015 #include "CGMmpi.h"
00016 #include "iGeom.h"
00017 
00018 #define IGEOM_ASSERT(ierr) if (ierr!=0) printf("igeom assert\n");
00019 #define IGEOM_NULL 0
00020 
00021 #define STRINGIFY(S) XSTRINGIFY(S)
00022 #define XSTRINGIFY(S) #S
00023 
00024 void util_getrusage(struct rusage &r_usage);
00025 
00026 int main(int argc, char* argv[]){
00027   int rank, size;
00028   MPI_Init(&argc, &argv);
00029   MPI_Comm_rank( MPI_COMM_WORLD, &rank );
00030   MPI_Comm_size( MPI_COMM_WORLD, &size );
00031   printf("Hello\n");
00032 
00033   iGeom_Instance igeom;
00034   int ierr;
00035   igeom = IGEOM_NULL;
00036   iGeom_newGeom("PARALLEL", &igeom, &ierr, 8);
00037   IGEOM_ASSERT(ierr);
00038  
00039   // check command line arg
00040   const char* filename = 0;
00041   int nMethod = 1;
00042   std::string options;
00043   
00044   if (argc == 3) {
00045     filename = argv[1];
00046     nMethod = atoi(argv[2]);
00047   }
00048   else {
00049     if (rank == 0) {
00050       printf("Usage: %s [<filename>] [<send_methond>]\n", argv[0]);
00051       printf("No file specified.  Defaulting to: %s\n", "Moto.brep");
00052       printf("No send method specified.  Defaulting to: read_delete\n");
00053     }
00054     filename = STRINGIFY(SRCDIR)"/../test/Moto.brep";
00055     nMethod = 1;
00056   }
00057   
00058   // set geometry send method
00059   if (nMethod == 0) options += "PARALLEL=READ;";
00060   else if (nMethod == 1) options += "PARALLEL=READ_DELETE;";
00061   else if (nMethod == 2) options += "PARALLEL=BCAST;";
00062   else if (nMethod == 3) options += "PARALLEL=BCAST_DELETE;";
00063   else if (nMethod == 4) options += "PARALLEL=SCATTER;";
00064   else if (nMethod == 5) options += "PARALLEL=SCATTER_DELETE;";
00065   else if (nMethod == 6) options += "PARALLEL=READ_PARALLEL;";
00066   else {
00067     printf("Send method %d is not supported. Defaulting to: read_delete\n", nMethod);
00068     options = "READ_DELETE;";
00069   }
00070 
00071   // do body partitioning with round robin distribution
00072   options += "PARTITION=GEOM_DIMENSION;PARTITION_VAL=3;PARTITION_DISTRIBUTE;";
00073 
00074   struct rusage r_usage;
00075   long int rss_before, rss_after, size_before, size_after;
00076   static size_t pagesize = getpagesize();
00077 
00078   if (rank == 0) {
00079     util_getrusage(r_usage);
00080     rss_before = r_usage.ru_maxrss*pagesize;
00081     size_before = r_usage.ru_idrss*pagesize;
00082   }
00083     
00084   double tStart = MPI_Wtime();
00085   iGeom_load(igeom, filename, options.c_str(), &ierr, strlen(filename), options.length());
00086         
00087   MPI_Barrier(MPI_COMM_WORLD); 
00088   double tEnd = MPI_Wtime();
00089 
00090   if (rank == 0) {
00091     util_getrusage(r_usage);
00092     rss_after = r_usage.ru_maxrss*pagesize;
00093     size_after = r_usage.ru_idrss*pagesize;
00094 
00095     printf("proc=%d, rss_before=%ld, size_before=%ld\n", rank, rss_before, size_before);
00096     printf("proc=%d, rss_after=%ld, size_after=%ld\n", rank, rss_after, size_after);
00097   }
00098 
00099   IGEOM_ASSERT(ierr);
00100   
00101   printf("Done. Geometry load time is %f\n", tEnd - tStart);
00102   MPI_Finalize();
00103 }
00104 
00105 void util_getrusage(struct rusage &r_usage)
00106 {
00107   getrusage(RUSAGE_SELF, &r_usage);
00108   
00109   // this machine doesn't return rss - try going to /proc
00110   // print the file name to open
00111   if (r_usage.ru_maxrss == 0) {
00112     char file_str[4096], dum_str[4096];
00113     int file_ptr = -1, file_len;
00114     file_ptr = open("/proc/self/stat", O_RDONLY);
00115     file_len = read(file_ptr, file_str, sizeof(file_str)-1);
00116     if (file_len == 0) return;
00117     close(file_ptr);
00118     file_str[file_len] = '\0';
00119     
00120     // read the preceeding fields and the ones we really want...
00121     int dum_int;
00122     unsigned int dum_uint, vm_size, rss;
00123     static int page_size = getpagesize();
00124     int num_fields = sscanf(file_str, 
00125                 "%d " // pid
00126                 "%s " // comm
00127                 "%c " // state
00128                 "%d %d %d %d %d " // ppid, pgrp, session, tty, tpgid
00129                 "%u %u %u %u %u " // flags, minflt, cminflt, majflt, cmajflt
00130                 "%d %d %d %d %d %d " // utime, stime, cutime, cstime, counter, priority
00131                 "%u %u " // timeout, itrealvalue
00132                 "%d " // starttime
00133                 "%u %u", // vsize, rss
00134                 &dum_int, 
00135                 dum_str, 
00136                 dum_str, 
00137                 &dum_int, &dum_int, &dum_int, &dum_int, &dum_int, 
00138                 &dum_uint, &dum_uint, &dum_uint, &dum_uint, &dum_uint,
00139                 &dum_int, &dum_int, &dum_int, &dum_int, &dum_int, &dum_int, 
00140                 &dum_uint, &dum_uint, 
00141                 &dum_int,
00142                 &vm_size, &rss);
00143     if (num_fields == 24) {
00144       r_usage.ru_maxrss = rss/page_size;
00145       r_usage.ru_idrss = vm_size/page_size;
00146     }
00147   }
00148 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines