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
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Test parallel iGeom
// July 09
// Author : Hong-Jun Kim
// read OCC geometry file and distribute it to remote processors
// with various methods

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <sys/resource.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>

#include "CGMmpi.h"
#include "iGeom.h"

#define IGEOM_ASSERT(ierr) if (ierr!=0) printf("igeom assert\n");
#define IGEOM_NULL 0

#define STRINGIFY(S) XSTRINGIFY(S)
#define XSTRINGIFY(S) #S

void util_getrusage(struct rusage &r_usage);

int main(int argc, char* argv[]){
  int rank, size;
  MPI_Init(&argc, &argv);
  MPI_Comm_rank( MPI_COMM_WORLD, &rank );
  MPI_Comm_size( MPI_COMM_WORLD, &size );
  printf("Hello\n");

  iGeom_Instance igeom;
  int ierr;
  igeom = IGEOM_NULL;
  iGeom_newGeom("PARALLEL", &igeom, &ierr, 8);<--- Skipping configuration 'CGM_FC_FUNC_' since the value of 'CGM_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
  IGEOM_ASSERT(ierr);
 
  // check command line arg
  const char* filename = 0;
  int nMethod = 1;
  std::string options;
  
  if (argc == 3) {
    filename = argv[1];
    nMethod = atoi(argv[2]);
  }
  else {
    if (rank == 0) {
      printf("Usage: %s [<filename>] [<send_methond>]\n", argv[0]);
      printf("No file specified.  Defaulting to: %s\n", "Moto.brep");
      printf("No send method specified.  Defaulting to: read_delete\n");
    }
    filename = STRINGIFY(SRCDIR)"/../test/Moto.brep";
    nMethod = 1;
  }
  
  // set geometry send method
  if (nMethod == 0) options += "PARALLEL=READ;";
  else if (nMethod == 1) options += "PARALLEL=READ_DELETE;";
  else if (nMethod == 2) options += "PARALLEL=BCAST;";
  else if (nMethod == 3) options += "PARALLEL=BCAST_DELETE;";
  else if (nMethod == 4) options += "PARALLEL=SCATTER;";
  else if (nMethod == 5) options += "PARALLEL=SCATTER_DELETE;";
  else if (nMethod == 6) options += "PARALLEL=READ_PARALLEL;";
  else {
    printf("Send method %d is not supported. Defaulting to: read_delete\n", nMethod);
    options = "READ_DELETE;";
  }

  // do body partitioning with round robin distribution
  options += "PARTITION=GEOM_DIMENSION;PARTITION_VAL=3;PARTITION_DISTRIBUTE;";

  struct rusage r_usage;
  long int rss_before, rss_after, size_before, size_after;
  static size_t pagesize = getpagesize();

  if (rank == 0) {
    util_getrusage(r_usage);
    rss_before = r_usage.ru_maxrss*pagesize;
    size_before = r_usage.ru_idrss*pagesize;
  }
    
  double tStart = MPI_Wtime();
  iGeom_load(igeom, filename, options.c_str(), &ierr, strlen(filename), options.length());<--- Skipping configuration 'CGM_FC_FUNC_' since the value of 'CGM_FC_FUNC_' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
	    
  MPI_Barrier(MPI_COMM_WORLD); 
  double tEnd = MPI_Wtime();

  if (rank == 0) {
    util_getrusage(r_usage);
    rss_after = r_usage.ru_maxrss*pagesize;
    size_after = r_usage.ru_idrss*pagesize;

    printf("proc=%d, rss_before=%ld, size_before=%ld\n", rank, rss_before, size_before);
    printf("proc=%d, rss_after=%ld, size_after=%ld\n", rank, rss_after, size_after);
  }

  IGEOM_ASSERT(ierr);
  
  printf("Done. Geometry load time is %f\n", tEnd - tStart);
  MPI_Finalize();
}

void util_getrusage(struct rusage &r_usage)
{
  getrusage(RUSAGE_SELF, &r_usage);
  
  // this machine doesn't return rss - try going to /proc
  // print the file name to open
  if (r_usage.ru_maxrss == 0) {
    char file_str[4096], dum_str[4096];
    int file_ptr = -1, file_len;
    file_ptr = open("/proc/self/stat", O_RDONLY);
    file_len = read(file_ptr, file_str, sizeof(file_str)-1);
    if (file_len == 0) return;
    close(file_ptr);
    file_str[file_len] = '\0';
    
    // read the preceeding fields and the ones we really want...
    int dum_int;
    unsigned int dum_uint, vm_size, rss;
    static int page_size = getpagesize();
    int num_fields = sscanf(file_str, 
			    "%d " // pid
			    "%s " // comm
			    "%c " // state
			    "%d %d %d %d %d " // ppid, pgrp, session, tty, tpgid
			    "%u %u %u %u %u " // flags, minflt, cminflt, majflt, cmajflt
			    "%d %d %d %d %d %d " // utime, stime, cutime, cstime, counter, priority
			    "%u %u " // timeout, itrealvalue
			    "%d " // starttime
			    "%u %u", // vsize, rss
			    &dum_int, 
			    dum_str, 
			    dum_str, 
			    &dum_int, &dum_int, &dum_int, &dum_int, &dum_int, 
			    &dum_uint, &dum_uint, &dum_uint, &dum_uint, &dum_uint,
			    &dum_int, &dum_int, &dum_int, &dum_int, &dum_int, &dum_int, 
			    &dum_uint, &dum_uint, 
			    &dum_int,
			    &vm_size, &rss);
    if (num_fields == 24) {
      r_usage.ru_maxrss = rss/page_size;
      r_usage.ru_idrss = vm_size/page_size;
    }
  }
}