Beispiel #1
0
INITFUNC (void)
{
    PyObject *m;
    PyObject *d;

    _Ny_RootStateStruct.ob_type = &NyRootState_Type;

    NyNodeTuple_Type.tp_base = &PyTuple_Type;
    NYFILL(NyNodeTuple_Type);
    NYFILL(NyRelation_Type);
    NYFILL(NyHeapView_Type);
    NYFILL(NyObjectClassifier_Type);
    NYFILL(NyHorizon_Type);
    NYFILL(NyNodeGraph_Type);
    NYFILL(NyNodeGraphIter_Type);
    NYFILL(NyRootState_Type);

    m = Py_InitModule(MODNAME, module_methods);
    if (!m)
      goto error;
    if (import_sets() == -1)
      goto error;
    this_module = m;
    d = PyModule_GetDict(m);
    PyDict_SetItemString(d, "__doc__", PyString_FromString(heapyc_doc));
    PyDict_SetItemString(d, "HeapView",
			 (PyObject *)&NyHeapView_Type);
    PyDict_SetItemString(d, "Horizon",
			 (PyObject *)&NyHorizon_Type);
    PyDict_SetItemString(d, "ObjectClassifier",
			 (PyObject *)&NyObjectClassifier_Type);
    PyDict_SetItemString(d, "NodeGraph",
			 (PyObject *)&NyNodeGraph_Type);
    PyDict_SetItemString(d, "Relation",
			 (PyObject *)&NyRelation_Type);
    PyDict_SetItemString(d, "RootState", Ny_RootState);
    PyDict_SetItemString(d, "RootStateType", (PyObject *)&NyRootState_Type);
    _hiding_tag__name = PyString_FromString("_hiding_tag_");
    NyStdTypes_init();
    if (NyNodeGraph_init() == -1)
      goto error;
#ifdef WITH_MALLOC_HOOKS
    sethooks();
#endif
    return 0;
  error:
    fprintf(stderr, "Error at initialization of module heapyc");
    return -1;
}
Beispiel #2
0
int main(int argc, char *argv[]) {
  char infname[256], outfname[256], attfname[256], setfname[256];
  Mesh_ptr mesh;
  int len, ok=0;
  int build_classfn=1, partition=0, weave=0, use_geometry=0, parallel_check=0;
  int num_ghost_layers=0, partmethod=0, attfile_given=0, setfile_given=0;
  MshFmt inmeshformat, outmeshformat;

  if (argc < 3) {
    fprintf(stderr,"\n");
    fprintf(stderr,"usage: mpirun -n NP %s <--partition=y|1|n|0> <--partition-method=0|1|2> <--parallel-check=y|1|n|0> <--attfile=attfilename> <--setfile=setfilename> infilename outfilename\n\n",progname);
    fprintf(stderr,"partition-method = 0, METIS\n");
    fprintf(stderr,"                 = 1, ZOLTAN with GRAPH partioning\n");
    fprintf(stderr,"                 = 2, ZOLTAN with RCB partitioning\n");
    fprintf(stderr,"Choose 2 if you want to avoid partitioning models\n");
    fprintf(stderr,"with high aspect ratio along the short directions\n");
    fprintf(stderr,"\n");
    fprintf(stderr,"infilename   = Input Exodus II File\n");
    fprintf(stderr,"outfilename  = Output Exodus II file name\n");
    fprintf(stderr,"attfilename  = Auxiliary file with real valued attributes\n");
    fprintf(stderr,"setfilename  = Auxiliary file with entity set specifications\n");
    fprintf(stderr,"\n");
    exit(-1);
  }

#ifdef MSTK_HAVE_MPI
  MPI_Init(&argc,&argv);
#endif


  MSTK_Init();


  int rank=0, numprocs=1;
#ifdef MSTK_HAVE_MPI

  MSTK_Comm comm = MPI_COMM_WORLD;

  MPI_Comm_rank(comm,&rank);
  MPI_Comm_size(comm,&numprocs);

#else
  MSTK_Comm comm = NULL;
#endif
  

  if (argc > 3) {
    int i;
    for (i = 1; i < argc-2; i++) {
      if (strncmp(argv[i],"--partition=",12) == 0) {
        if (strncmp(argv[i]+12,"y",1) == 0 ||
            strncmp(argv[i]+12,"1",1) == 0)
          partition = 1;
        else if (strncmp(argv[i]+12,"n",1) == 0 ||
                 strncmp(argv[i]+12,"0",1) == 0) 
          partition = 0;
        else
          MSTK_Report(progname,
                      "--partition option should be y, n, 1 or 0",
                      MSTK_FATAL);          
      }
      else if (strncmp(argv[i],"--partition-method",18) == 0 ||
               strncmp(argv[i],"--partition_method",18) == 0) {
        sscanf(argv[i]+19,"%d",&partmethod);
        partition = 1;
      }
      else if (strncmp(argv[i],"--parallel-check",16) == 0 ||
               strncmp(argv[i],"--parallel_check",16) == 0) {
        if (strncmp(argv[i]+17,"y",1) == 0 ||
            strncmp(argv[i]+17,"1",1) == 1)
          parallel_check = 1;
        else if (strncmp(argv[i]+17,"n",13) == 0 ||
                 strncmp(argv[i]+17,"0",13) == 0) 
          parallel_check = 0;
      }
      else if (strncmp(argv[i],"--attfile",9) == 0) {
        sscanf(argv[i]+10,"%s",attfname);
        attfile_given=1;
      }
      else if (strncmp(argv[i],"--setfile",9) == 0) {
        sscanf(argv[i]+10,"%s",setfname);
        setfile_given=1;
      }
      else
        fprintf(stderr,"Unrecognized option...Ignoring\n");
    }

    /* If running on multiple processors, but partition is 0, assume
       that you are partitioning a serial mesh */

    if (numprocs > 1 && partition == 0) {
      MSTK_Report(progname,
                  "Running on multiple processors but partition option not specified",
                  MSTK_WARN);
      MSTK_Report(progname,
                  "Output mesh will be partitioned into as many parts as processors",
                  MSTK_WARN);
      partition = 1; 
    }
  }

  strcpy(infname,argv[argc-2]);
  strcpy(outfname,argv[argc-1]);


  len = strlen(infname);
  if (len > 4 && strncmp(&(infname[len-4]),".exo",4) == 0)
    inmeshformat = EXODUSII;
  else
    MSTK_Report(progname,"Input file must have .exo extension", MSTK_FATAL);

  len = strlen(outfname);
  if (len > 4 && strncmp(&(outfname[len-4]),".exo",4) == 0)
    outmeshformat = EXODUSII;
  else if (len > 4 && strncmp(&(outfname[len-4]),".par",4) == 0)
    outmeshformat = EXODUSII;
  else
    MSTK_Report(progname,"Output file must have .exo or .par extension", MSTK_FATAL);



  /* Import the Exodus II mesh */

  mesh = MESH_New(F1);

#ifdef MSTK_HAVE_MPI
  if (rank == 0) {
#endif

    int opts[5]={0,0,0,0,0};
  
    ok = 0;
    fprintf(stderr,"Importing mesh from ExodusII file...");
    opts[0] = 0; /* don't partition while importing - do it later */
    opts[1] = 0;
    opts[2] = 0; /* no ghost layers */  
    opts[3] = 0;
    ok = MESH_ImportFromFile(mesh,infname,"exodusii",opts,comm);
    if (ok)
      fprintf(stderr,"done\n\n");
    else {
      MSTK_Report(progname,"Failed\n",MSTK_FATAL);
    }
    

    /* Read in the attributes only on rank 0 and attach it to the mesh */
    if (attfile_given)
      import_attributes(mesh, attfname);


    /* Import element set definitions and create in the mesh */
    if (setfile_given)
      import_sets(mesh, setfname);

#ifdef MSTK_HAVE_MPI
  }
#endif


#ifdef MSTK_HAVE_MPI

  if (partition) {

    /* Need to make sure that we have a mesh only on processor 0 */
    /* For now we cannot repartition                             */

    int prepartitioned = 0, mesh_present = 0;

    int dim = 3;
    if (rank > 0) {
      if (mesh && MESH_Num_Vertices(mesh) != 0)
        mesh_present = 1;
    }
    
    MPI_Reduce(&mesh_present,&prepartitioned,1,MPI_INT,MPI_MAX,0,comm);
    MPI_Bcast(&prepartitioned,1,MPI_INT,0,comm);

    if (!prepartitioned) {
    
      Mesh_ptr mesh0=NULL;
      if (rank == 0) {
        fprintf(stderr,"Partitioning mesh into %d parts...",numprocs);
        
        if (MESH_Num_Regions(mesh))
          dim = 3;
        else if (MESH_Num_Faces(mesh))
          dim = 2;
        else {
          fprintf(stderr,"Partitioning possible only for 2D or 3D meshes\n");
          exit(-1);
        }
        
        mesh0 = mesh;
        mesh = NULL;
      }
      
      int ring = 0; /* No ghost ring of elements */
      int with_attr = 1; /* Do allow exchange of attributes */
      int del_inmesh = 1; /* Delete input mesh after partitioning */

      ok = MSTK_Mesh_Distribute(mesh0, &mesh, &dim, ring, with_attr,
                                    partmethod, del_inmesh, comm);
      
      if (rank == 0) {
        if (ok)
          fprintf(stderr,"done\n");
        else {
          fprintf(stderr,"failed\n");
          exit(-1);
        }
      }

      /*      if (rank == 0)
	      MESH_Delete(mesh0);
      */

    }    
  }

#endif /* MSTK_HAVE_MPI */


#ifdef MSTK_HAVE_MPI
  if (numprocs > 1 && parallel_check == 1) {

    /* Do a parallel consistency check too */

    ok = ok && MESH_Parallel_Check(mesh,comm);
    
  }
#endif

  fprintf(stderr,"\nExporting mesh to ExodusII format...");
  ok = MESH_ExportToFile(mesh,outfname,"exodusii",-1,NULL,NULL,comm);

  if (ok)
    fprintf(stderr,"Done\n");
  else {
    fprintf(stderr,"Failed\n");
    exit(-1);
  }


  MESH_Delete(mesh);
 
  // while (1);

#ifdef MSTK_HAVE_MPI
  MPI_Finalize();
#endif

  return 1;
}