示例#1
0
int main(int argc, char ** argv)
{
    char *etreefile;
    dbctl_t *myctl;
    etree_t *ep;

    /* read command line argument */
    if (argc != 2) {
        fprintf(stderr, "Usage: showdbctl etreename\n");
        exit(1);
    }

    etreefile = argv[1];

    if ((ep = etree_open(etreefile, O_RDONLY, 0, 0, 0)) == NULL) {
        fprintf(stderr, "Fail to open the etree\n");
        exit(1);
    }

    myctl = cvm_newdbctl();
    if (myctl == NULL) {
        perror("cvm_newdbctl");
        exit(1);
    }

    if ((myctl = cvm_getdbctl(ep)) == NULL) {
        fprintf(stderr, "Cannot get the material database control data\n");
        exit(1);
    }

    printf("\n");
    printf("create_db_name:               %s\n", ep->pathname);
    printf("create_model_name:            %s\n", myctl->create_model_name);
    printf("create_author:                %s\n", myctl->create_author);
    printf("create_date:                  %s\n", myctl->create_date);
    printf("create_field_count:           %s\n", myctl->create_field_count);
    printf("create_field_names:           %s\n", myctl->create_field_names);
    printf("\n");

    printf("region_origin_latitude_deg:   %f\n", 
           myctl->region_origin_latitude_deg);
    printf("region_origin_longitude_deg:  %f\n", 
           myctl->region_origin_longitude_deg);
    printf("region_length_east_m:         %f\n", myctl->region_length_east_m);
    printf("region_length_north_m:        %f\n", myctl->region_length_north_m);
    printf("region_depth_shallow_m:       %f\n", 
           myctl->region_depth_shallow_m);
    printf("region_depth_deep_m:          %f\n", myctl->region_depth_deep_m);
    printf("\n");

    printf("domain_endpoint_x:            %u\n", myctl->domain_endpoint_x);
    printf("domain_endpoint_y:            %u\n", myctl->domain_endpoint_y);
    printf("domain_endpoint_z:            %u\n", myctl->domain_endpoint_z);

    cvm_freedbctl(myctl);
    
    etree_close(ep);
    
    return 0;
}
示例#2
0
int main(int argc, char **argv)
{
    etree_t *ep;
    etree_addr_t root;
    payload_t payload;
    int count;
    char *filename;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s etree\n", argv[0]);
        exit(0);
    }
    filename = argv[1];

    /* Create an empty 3d etree with an integer record */
    ep = etree_open(filename, O_RDWR|O_CREAT|O_TRUNC, 1, sizeof(payload_t), 3); 
    if (ep == NULL) {
        fprintf(stderr, "Could not open etree file %s\n", filename);
        exit(1);
    }

    /* Register the schema for the etree to make it portable */
    if (etree_registerschema(ep, "int32_t val; char tag;") != 0) {
        fprintf(stderr, "%s\n", etree_strerror(etree_errno(ep)));
        exit(1);
    }

    /* Initialize the tree with a single root octant */
    /* $begin refineinit */
    root.x = root.y = root.z = 0;
    root.level = ETREE_MAXLEVEL - 2;
    root.type = ETREE_LEAF;
    payload.tag = 'A';
    payload.val = 0;

    if (etree_insert(ep, root, &payload) != 0) {
        fprintf(stderr, "%s", etree_strerror(etree_errno(ep)));
        exit(1);
    }
    /* $end refineinit */

    /* Recursively refine the root octant */
    /* $begin callrefine */
    refine(ep, root);
    count = traverse(ep);
    fprintf(stderr, "The tree has %d octants\n", count);
    /* $end callrefine */

    /* Clean up */
    etree_close(ep);
    exit(0);
}
示例#3
0
int main(int argc, char **argv)
{
    etree_t *ep;
    etree_addr_t addr, res_addr;
    value_t res_val;
    char buf[ETREE_MAXBUF];

    /* $end query */
    if (argc != 2) {
        fprintf(stderr, "usage: %s etree\n", argv[0]);
        exit(0);
    }
    /* $begin query */
    /* Open the etree for reading */
    ep = etree_open(argv[1], O_RDONLY, 0, sizeof(value_t), 3); 
    if (ep == NULL) {
        fprintf(stderr, "Could not open etree file %s\n", argv[1]);
        exit(1);
    }

    /* Query each octant specified on stdin */
    printf("Input  (x y z t): ");
    addr.level = ETREE_MAXLEVEL;

    while (fgets(buf, ETREE_MAXBUF, stdin)) {
        sscanf(buf, "%u %u %u %u", &addr.x, &addr.y, &addr.z, &addr.t);
	/* $end query */
        /* Ignore comment or blank lines */
        if ((buf[0] == '#') || 
            (buf[0] == '\n') || 
            (buf[0] == '\t')) {
            continue;
        }
	/* $begin query */
        if (etree_search(ep, addr, &res_addr, &res_val) != 0) {
            fprintf(stderr, "%s\n", etree_strerror(etree_errno(ep)));
            printf("Input  (x y z t): ");
	    continue;
        }

	printf("Output (x y z t): %s = %f %f %f\n\n", 
	       etree_straddr(ep, buf, res_addr), res_val.Vx, res_val.Vy,
           res_val.Vz);
	printf("Input  (x y z t): ");
    }

    etree_close(ep);
    exit(0);
}
示例#4
0
int main( int argc, char** argv )
{
    char*    cvmetree;
    etree_t* cvmEp;
    double east_m, north_m, depth_m;
    cvmpayload_t rawElem;
    int res;

    if (argc != 5) {
	fprintf( stderr, "\nusage: %s cvm_etree_file east_m north_m depth_m\n\n",
		 argv[0] );
	return 1;
    }

    cvmetree = argv[0];
    sscanf( argv[2], "%lf", &east_m  );
    sscanf( argv[3], "%lf", &north_m );
    sscanf( argv[4], "%lf", &depth_m );


    cvmEp = etree_open( cvmetree, O_RDONLY, CVMBUFFERSIZE, 0, 0 );
    if (!cvmEp) {
	perror( "etree_open(...)" );
	fprintf( stderr, "Cannot open CVM material database %s\n", cvmetree );
	return 2;
    }

    res = cvm_query( cvmEp, east_m, north_m, depth_m, &rawElem );

    if (res != 0) {
	fprintf( stderr, "Cannot find the query point\n" );
    } else {
	printf( "\nMaterial property for\n(%f East, %f North, %f Depth)\n",
		east_m, north_m, depth_m );
	printf( "Vp =      %.4f\n", rawElem.Vp );
	printf( "Vs =      %.4f\n", rawElem.Vs );
	printf( "density = %.4f\n", rawElem.rho );
	printf( "\n" );
    }

    etree_close( cvmEp );

    return (res == 0) ? 0 : 3;
}
示例#5
0
int main(int argc, char **argv)
{
    mesh_t *mesh;
    double double_message[5];
    double x, y, z, factor = 0, vscut = 0;
    double elapsedtime;
#ifndef NO_OUTPUT
    int32_t eindex;
    int32_t remains, batch, idx;
    mrecord_t *partTable;
#endif

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &myID);
    MPI_Comm_size(MPI_COMM_WORLD, &theGroupSize);

    /* Read commandline arguments  */
    if (argc != 5) {
	if (myID == 0) {
	    fprintf(stderr, "usage: qmesh cvmdb physics.in numerical.in ");
	    fprintf(stderr, "meshdb\n");
	    fprintf(stderr,
		    "cvmdb: path to an etree database or a flat file.\n");
	    fprintf(stderr, "physics.in: path to physics.in.\n");
	    fprintf(stderr, "numerical.in: path to numerical.in.\n");
	    fprintf(stderr, "meshetree: path to the output mesh etree.\n");
	    fprintf(stderr, "\n");
	}
	MPI_Finalize();
	return -1;
    }

    /* Change the working directory to $LOCAL */
    /*
    localpath = getenv("LOCAL");
    if (localpath == NULL) {
        fprintf(stderr, "Thread %d: Cannot get $LOCAL value\n", myID);
        MPI_Abort(MPI_COMM_WORLD, ERROR);
        exit(1);
    }

    if (chdir(localpath) != 0) {
        fprintf(stderr, "Thread %d: Cannot chdir to %s\n", myID, localpath);
        MPI_Abort(MPI_COMM_WORLD, ERROR);
        exit(1);
    }
    */

    /* Replicate the material database among the processors */
    /*

    if ((theGroupSize - 1) / PROCPERNODE >= 1) {

        MPI_Comm replica_comm;

        if (myID % PROCPERNODE != 0) {
            MPI_Comm_split(MPI_COMM_WORLD, MPI_UNDEFINED, myID, &replica_comm);

        } else {
            int replica_id;
            off_t filesize, remains, batchsize;
            void *filebuf;
            int fd;

            MPI_Comm_split(MPI_COMM_WORLD, 0, myID, &replica_comm);
            MPI_Comm_rank(replica_comm, &replica_id);

            if (replica_id == 0) {

                struct stat statbuf;


                if (stat(argv[1], &statbuf) != 0) {
                    fprintf(stderr, "Thread 0: Cannot get stat of %s\n",
                            argv[1]);
                    MPI_Abort(MPI_COMM_WORLD, ERROR);
                    exit(1);
                }

                filesize = statbuf.st_size;
            }

            MPI_Bcast(&filesize, sizeof(off_t), MPI_CHAR, 0, replica_comm);

            if ((filebuf = malloc(FILEBUFSIZE)) == NULL) {
                fprintf(stderr, "Thread %d: run out of memory while ", myID);
                fprintf(stderr, "preparing to receive material database\n");
                MPI_Abort(MPI_COMM_WORLD, ERROR);
                exit(1);
            }

	    fd = (replica_id == 0) ?
	    open(argv[1], O_RDONLY) :
                open(argv[1], O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);

            if (fd == -1) {
                fprintf(stderr, "Thread %d: Cannot create replica database\n",
                        myID);
                perror("open");
                MPI_Abort(MPI_COMM_WORLD, ERROR);
                exit(1);
            }

            remains = filesize;
            while (remains > 0) {
                batchsize = (remains > FILEBUFSIZE) ? FILEBUFSIZE : remains;

                if (replica_id == 0) {
                    if (read(fd, filebuf, batchsize) !=  batchsize) {
                        fprintf(stderr, "Thread 0: Cannot read database\n");
                        perror("read");
                        MPI_Abort(MPI_COMM_WORLD, ERROR);
                        exit(1);
                    }
                }

                MPI_Bcast(filebuf, batchsize, MPI_CHAR, 0, replica_comm);

                if (replica_id != 0) {
                    if (write(fd, filebuf, batchsize) != batchsize) {
                        fprintf(stderr, "Thread %d: Cannot write replica ",
                                myID);
                        fprintf(stderr, "database\n");
                        MPI_Abort(MPI_COMM_WORLD, ERROR);
                        exit(1);
                    }
                }

                remains -= batchsize;
		}

            if (close(fd) != 0) {
                fprintf(stderr, "Thread %d: cannot close replica database\n",
                        myID);
                perror("close");
                MPI_Abort(MPI_COMM_WORLD, ERROR);
                exit(1);
            }
	    }

        MPI_Barrier(MPI_COMM_WORLD);

	}

    */



    /* Initialize static global varialbes */
    if (myID == 0) {
	/* Processor 0 reads the parameters */
	if (initparameters(argv[2], argv[3], &x, &y, &z) != 0) {
	    fprintf(stderr, "Thread %d: Cannot init parameters\n", myID);
	    MPI_Abort(MPI_COMM_WORLD, ERROR);
	    exit(1);
	}

	factor = theFactor;
	vscut = theVsCut;
	double_message[0] = x;
	double_message[1] = y;
	double_message[2] = z;
	double_message[3] = factor;
	double_message[4] = vscut;

	/*
          fprintf(stderr, "&double_message[0] = %p\n", &double_message[0]);
          fprintf(stderr, "&double_message[4] = %p\n", &double_message[4]);
	  fprintf(stderr, "Thread 0: %f %f %f %f %f\n", x, y, z, factor, vscut);
        */
    }

    MPI_Bcast(double_message, 5, MPI_DOUBLE, 0, MPI_COMM_WORLD);

    x = double_message[0];
    y = double_message[1];
    z = double_message[2];
    factor = double_message[3];
    vscut  = double_message[4];

    theNorth_m = x;
    theEast_m = y;
    theDepth_m = z;

    /*
      printf("Thread %d: %f %f %f %f %f\n", myID, x, y, z, factor, vscut);
    */

    theFactor = factor;
    theVsCut = vscut;

    MPI_Barrier(MPI_COMM_WORLD);
    elapsedtime = -MPI_Wtime();


    if (myID == 0) {
	fprintf(stdout, "PE = %d, Freq = %.2f\n", theGroupSize, theFreq);
	fprintf(stdout, "-----------------------------------------------\n");
    }


    /*----  Generate and partition an unstructured octree mesh ----*/
    if (myID == 0) {
	fprintf(stdout, "octor_newtree ... ");
    }

    /*
     * RICARDO: Carful with new_octree parameters (cutoff_depth)
     */

    myOctree = octor_newtree(x, y, z, sizeof(edata_t), myID, theGroupSize, MPI_COMM_WORLD, 0);
    if (myOctree == NULL) {
	fprintf(stderr, "Thread %d: fail to create octree\n", myID);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    }
    MPI_Barrier(MPI_COMM_WORLD);

    elapsedtime += MPI_Wtime();

    if (myID == 0) {
	fprintf(stdout, "done.... %.2f seconds\n", elapsedtime);
    }

#ifdef USECVMDB
    /* Open my copy of the material database */
    theCVMEp = etree_open(argv[1], O_RDONLY, CVMBUFSIZE, 0, 0);
    if (!theCVMEp) {
	fprintf(stderr, "Thread %d: Cannot open CVM etree database %s\n",
		myID, argv[1]);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    }

#else

    /* Use flat data record file and distibute the data in memories */
    elapsedtime = -MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "slicing CVM database ...");
    }

    theCVMRecord = sliceCVM(argv[1]);

    MPI_Barrier(MPI_COMM_WORLD);
    elapsedtime += MPI_Wtime();
    if (theCVMRecord == NULL) {
	fprintf(stderr, "Thread %d: Error obtaining the CVM records from %s\n",
		myID, argv[1]);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    };
    if (myID == 0) {
	fprintf(stdout, "done.... %.2f seconds\n", elapsedtime);
    }

#endif

    elapsedtime = -MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "octor_refinetree ...");
    }
    if (octor_refinetree(myOctree, toexpand, setrec) != 0) {
	fprintf(stderr, "Thread %d: fail to refine octree\n", myID);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    }

    MPI_Barrier(MPI_COMM_WORLD);
    elapsedtime += MPI_Wtime();

    if (myID == 0) {
	fprintf(stdout, "done.... %.2f seconds\n", elapsedtime);
    }


    elapsedtime = -MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "octor_balancetree ... ");
    }
    if (octor_balancetree(myOctree, setrec, 0) != 0) { /* no progressive meshing (ricardo) */
	fprintf(stderr, "Thread %d: fail to balance octree\n", myID);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    }
    MPI_Barrier(MPI_COMM_WORLD);

    elapsedtime += MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "done.... %.2f seconds\n", elapsedtime);
    }

#ifdef USECVMDB
    /* Close the material database */
    etree_close(theCVMEp);
#else
    free(theCVMRecord);

#endif /* USECVMDB */

    elapsedtime = -MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "octor_partitiontree ...");
    }
    if (octor_partitiontree(myOctree, NULL) != 0) {
	fprintf(stderr, "Thread %d: fail to balance load\n", myID);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    }
    MPI_Barrier(MPI_COMM_WORLD);

    elapsedtime +=  MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "done.... %.2f seconds\n", elapsedtime);
    }

    elapsedtime = - MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "octor_extractmesh ... ");
    }
    mesh = octor_extractmesh(myOctree, NULL);
    if (mesh == NULL) {
	fprintf(stderr, "Thread %d: fail to extract mesh\n", myID);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    }
    MPI_Barrier(MPI_COMM_WORLD);

    elapsedtime += MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "done.... %.2f seconds\n", elapsedtime);
    }

    /* We can do without the octree now */
    octor_deletetree(myOctree);


    /*---- Obtain and print the statistics of the mesh ----*/
    if (myID == 0) {
	int64_t etotal, ntotal, dntotal;
	int32_t received, procid;
	int32_t *enumTable, *nnumTable, *dnnumTable;
	int32_t rcvtrio[3];

	/* Allocate the arrays to hold the statistics */
	enumTable = (int32_t *)malloc(sizeof(int32_t) * theGroupSize);
	nnumTable = (int32_t *)malloc(sizeof(int32_t) * theGroupSize);
	dnnumTable = (int32_t *)malloc(sizeof(int32_t) * theGroupSize);

	if ((enumTable == NULL) ||
	    (nnumTable == NULL) ||
	    (dnnumTable == NULL)) {
	    fprintf(stderr, "Thread 0: out of memory\n");
	    MPI_Abort(MPI_COMM_WORLD, ERROR);
	    exit(1);
	}

	/* Fill in my counts */
	enumTable[0] = mesh->lenum;
	nnumTable[0] = mesh->lnnum;
	dnnumTable[0] = mesh->ldnnum;

	/* Initialize sums */
	etotal = mesh->lenum;
	ntotal = mesh->lnnum;
	dntotal = mesh->ldnnum;

	/* Fill in the rest of the tables */
	received = 0;
	while (received < theGroupSize - 1) {
	    int32_t fromwhom;
	    MPI_Status status;

	    MPI_Probe(MPI_ANY_SOURCE, STAT_MSG, MPI_COMM_WORLD, &status);

	    fromwhom = status.MPI_SOURCE;

	    MPI_Recv(rcvtrio, 3, MPI_INT, fromwhom, STAT_MSG, MPI_COMM_WORLD,
		     &status);

	    enumTable[fromwhom] = rcvtrio[0];
	    nnumTable[fromwhom] = rcvtrio[1];
	    dnnumTable[fromwhom] = rcvtrio[2];

	    etotal += rcvtrio[0];
	    ntotal += rcvtrio[1];
	    dntotal += rcvtrio[2];

	    received++;
	}

	fprintf(stdout, "Mesh statistics:\n");
	fprintf(stdout, "                 Elements     Nodes    Danglings\n");
#ifdef ALPHA_TRU64UNIX_CC
	fprintf(stdout, "Total     :   %10ld%10ld   %10ld\n\n",
		etotal, ntotal, dntotal);
	for (procid = 0; procid < theGroupSize; procid++) {
	    fprintf(stdout, "Proc %5d:   %10d%10d   %10d\n", procid,
		    enumTable[procid], nnumTable[procid], dnnumTable[procid]);
	}

#else
	fprintf(stdout, "Total      :    %10qd%10qd   %10qd\n\n",
		etotal, ntotal, dntotal);
	for (procid = 0; procid < theGroupSize; procid++) {
	    fprintf(stdout, "Proc %5d:   %10d%10d   %10d\n", procid,
		    enumTable[procid], nnumTable[procid], dnnumTable[procid]);
	}
#endif

	free(enumTable);
	free(nnumTable);
	free(dnnumTable);

    } else {
	int32_t sndtrio[3];

	sndtrio[0] = mesh->lenum;
	sndtrio[1] = mesh->lnnum;
	sndtrio[2] = mesh->ldnnum;

	MPI_Send(sndtrio, 3, MPI_INT, 0, STAT_MSG, MPI_COMM_WORLD);
    }

#ifndef NO_OUTPUT

    /*---- Join elements and nodes, and send to Thread 0 for output */

    /* Allocate a fixed size buffer space to store the join results */
    partTable = (mrecord_t *)calloc(BATCH, sizeof(mrecord_t));
    if (partTable == NULL) {
	fprintf(stderr,	 "Thread %d: out of memory\n", myID);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    }

    if (myID == 0) {
	char *mEtree;
	etree_t *mep;
	int32_t procid;

	mEtree = argv[4];
	mep = etree_open(mEtree, O_CREAT|O_RDWR|O_TRUNC, 0, sizeof(mdata_t),3);
	if (mep == NULL) {
	    fprintf(stderr, "Thread 0: cannot create mesh etree\n");
	    MPI_Abort(MPI_COMM_WORLD, ERROR);
	    exit(1);
	}

	/* Begin an appending operation */
	if (etree_beginappend(mep, 1) != 0) {
	    fprintf(stderr, "Thread 0: cannot begin an append operation\n");
	    MPI_Abort(MPI_COMM_WORLD, ERROR);
	    exit(1);
	}

	eindex = 0;
	while (eindex < mesh->lenum) {
	    remains = mesh->lenum - eindex;
	    batch = (remains < BATCH) ? remains : BATCH;

	    for (idx = 0; idx < batch; idx++) {
		mrecord_t *mrecord;
		int32_t whichnode;
		int32_t localnid0;

		mrecord = &partTable[idx];

		/* Fill the address field */
		localnid0 = mesh->elemTable[eindex].lnid[0];

		mrecord->addr.x = mesh->nodeTable[localnid0].x;
		mrecord->addr.y = mesh->nodeTable[localnid0].y;
		mrecord->addr.z = mesh->nodeTable[localnid0].z;
		mrecord->addr.level = mesh->elemTable[eindex].level;
		mrecord->addr.type = ETREE_LEAF;

		/* Find the global node ids for the vertices */
		for (whichnode = 0; whichnode < 8; whichnode++) {
		    int32_t localnid;
		    int64_t globalnid;

		    localnid = mesh->elemTable[eindex].lnid[whichnode];
		    globalnid = mesh->nodeTable[localnid].gnid;

		    mrecord->mdata.nid[whichnode] = globalnid;
		}

		memcpy(&mrecord->mdata.edgesize, mesh->elemTable[eindex].data,
		       sizeof(edata_t));

		eindex++;
	    } /* for a batch */

	    if (bulkload(mep, partTable, batch) != 0) {
		fprintf(stderr, "Thread 0: Error bulk-loading data\n");
		MPI_Abort(MPI_COMM_WORLD, ERROR);
		exit(1);
	    }
	} /* for all the elements Thread 0 has */

	/* Receive data from other processors */
	for (procid = 1; procid < theGroupSize; procid++) {
	    MPI_Status status;
	    int32_t rcvbytecount;

	    /* Signal the next processor to go ahead */
	    MPI_Send(NULL, 0, MPI_CHAR, procid, GOAHEAD_MSG, MPI_COMM_WORLD);

	    while (1) {
		MPI_Probe(procid, MESH_MSG, MPI_COMM_WORLD, &status);
		MPI_Get_count(&status, MPI_CHAR, &rcvbytecount);

		batch = rcvbytecount / sizeof(mrecord_t);
		if (batch == 0) {
		    /* Done */
		    break;
		}

		MPI_Recv(partTable, rcvbytecount, MPI_CHAR, procid,
			 MESH_MSG, MPI_COMM_WORLD, &status);

		if (bulkload(mep, partTable, batch) != 0) {
		    fprintf(stderr, "Thread 0: Cannot bulk-load data from ");
		    fprintf(stderr, "Thread %d\n", procid);
		    MPI_Abort(MPI_COMM_WORLD, ERROR);
		    exit(1);
		}
	    } /* while there is more data to be received from procid */
	} /* for all the processors */

	/* End the appending operation */
	etree_endappend(mep);

	/* Close the mep to ensure the data is on disk */
	if (etree_close(mep) != 0) {
	    fprintf(stderr, "Thread 0: Cannot close the etree database\n");
	    MPI_Abort(MPI_COMM_WORLD, ERROR);
	    exit(1);
	}

    } else {
	/* Processors other than 0 needs to send data to 0 */
	int32_t sndbytecount;
	MPI_Status status;

	/* Wait for my turn */
	MPI_Recv(NULL, 0, MPI_CHAR, 0, GOAHEAD_MSG, MPI_COMM_WORLD, &status);

	eindex = 0;
	while (eindex < mesh->lenum) {
	    remains = mesh->lenum - eindex;
	    batch = (remains < BATCH) ? remains : BATCH;

	    for (idx = 0; idx < batch; idx++) {
		mrecord_t *mrecord;
		int32_t whichnode;
		int32_t localnid0;

		mrecord = &partTable[idx];

		/* Fill the address field */
		localnid0 = mesh->elemTable[eindex].lnid[0];

		mrecord->addr.x = mesh->nodeTable[localnid0].x;
		mrecord->addr.y = mesh->nodeTable[localnid0].y;
		mrecord->addr.z = mesh->nodeTable[localnid0].z;
		mrecord->addr.level = mesh->elemTable[eindex].level;
		mrecord->addr.type = ETREE_LEAF;

		/* Find the global node ids for the vertices */
		for (whichnode = 0; whichnode < 8; whichnode++) {
		    int32_t localnid;
		    int64_t globalnid;

		    localnid = mesh->elemTable[eindex].lnid[whichnode];
		    globalnid = mesh->nodeTable[localnid].gnid;

		    mrecord->mdata.nid[whichnode] = globalnid;
		}

		memcpy(&mrecord->mdata.edgesize, mesh->elemTable[eindex].data,
		       sizeof(edata_t));

		eindex++;
	    } /* for a batch */

	    /* Send data to proc 0 */
	    sndbytecount = batch * sizeof(mrecord_t);
	    MPI_Send(partTable, sndbytecount, MPI_CHAR, 0, MESH_MSG,
		     MPI_COMM_WORLD);
	} /* While there is data left to be sent */

	/* Send an empty message to indicate the end of my transfer */
	MPI_Send(NULL, 0, MPI_CHAR, 0, MESH_MSG, MPI_COMM_WORLD);
    }

    /* Free the memory for the partial join results */
    free(partTable);

#endif

    octor_deletemesh(mesh);

    MPI_Finalize();

    return 0;
}
示例#6
0
int main(int argc, char **argv)
{
    char    *meshetree, *robIn, *robOut, *cmuOut, *diffile, *diffileA;
    etree_t *meshEp = NULL;
    double   east_m, north_m, depth_m, robVs, robVp, robRho, vsDiff;
    mdata_t  rawElem;
    int      rres=0, mres;//, i=0;

    FILE    *fpRobIn, *fpRobOut, *fpCmuOut, *fpDiff, *fpDiffA;

    double   lon, lat;
    double   domainLengthEta = 600e3;
    double   domainLengthCsi = 300e3;

    double   lonCorners[4] ={-121.0 ,-118.951292, -113.943965, -116.032285};
    double   latCorners[4] ={  34.5 ,  36.621696,   33.122341,   31.082920};

    vector2d_t meshCoords;

    domainLengthEta=600e3;
    domainLengthCsi=300e3;

    /* Capturing input data */

    if (argc != 7) {
        fprintf(stderr, 
            "\nusage: mirrorslice meshetree robfile cmuout robout diffile absfile\n");
        exit(1);
    }

    meshetree = argv[1];
    robIn     = argv[2];
    cmuOut    = argv[3];
    robOut    = argv[4];
    diffile   = argv[5];
    diffileA  = argv[6];

    /* Openning files */

    meshEp = etree_open(meshetree, O_RDONLY, CVMBUFFERSIZE, 0, 0);
    if (!meshEp) {
        fprintf(stderr, "Cannot open mesh etree %s\n", meshetree);
        exit(1);
    }

    fpRobIn = fopen(robIn,"r");
    if ( fpRobIn == NULL ) {
        fprintf(stderr, "Cannot open the Rob input file");
        exit(1);
    }

    fpRobOut = fopen(robOut,"w");
    if ( fpRobOut == NULL ) {
        fprintf(stderr, "Cannot open the Rob output file\n");
        exit(1);
    }

    fpCmuOut = fopen(cmuOut,"w");
    if ( fpCmuOut == NULL ) {
        fprintf(stderr, "Cannot open the CMU output file\n");
        exit(1);
    }

    fpDiff = fopen(diffile,"w");
    if ( fpDiff == NULL ) {
        fprintf(stderr, "Cannot open the Diff output file\n");
        exit(1);
    }
    
    fpDiffA = fopen(diffileA,"w");
    if ( fpDiffA == NULL ) {
        fprintf(stderr, "Cannot open the Diff output file\n");
        exit(1);
    }

    while ( rres != EOF ) {
  //for ( i = 0; i < 10; i++ ) {

        rres = fscanf(fpRobIn,"%lf %lf %lf %lf %lf", 
		      &lon, &lat, &robVp, &robVs, &robRho);

	robVs = robVs * 1000;

	meshCoords = compute_domain_coords_bilin( 
		       lon, lat, 
                       lonCorners, latCorners,
                       domainLengthEta, domainLengthCsi);

	north_m = meshCoords.x[0];
	east_m  = meshCoords.x[1];
	depth_m = 0;

	mres = mesh_query(meshEp, east_m, north_m, depth_m, 
			  NULL, &rawElem.nid[0]);

	if (mres != 0) {
	    fprintf(stderr, "Cannot find the query point\n");
	    exit(1);
	}

	vsDiff = rawElem.Vs - robVs;

	fprintf(fpRobOut, "%12.0f %12.0f %12.4f\n",east_m, north_m, robVs);
	fprintf(fpCmuOut, "%12.0f %12.0f %12.4f\n",east_m, north_m, rawElem.Vs);
	fprintf(fpDiff,   "%12.0f %12.0f %12.4f\n",east_m, north_m, vsDiff);
	fprintf(fpDiffA,  "%12.0f %12.0f %12.4f\n",east_m, north_m, fabs(vsDiff));

    }
    
    /* Closing files */

    fclose(fpRobIn);
    fclose(fpRobOut);
    fclose(fpCmuOut);
    fclose(fpDiff);
    fclose(fpDiffA);
    etree_close(meshEp);

    return 0;
}
示例#7
0
int main(int argc, char **argv)
{
    char *cvmetree, *outputfile, *outformat;
    FILE *outfp;
    etree_t *cvmEp;
    cvmpayload_t rawElem;
    int64_t totalcount;
    struct timeval starttime, endtime;
    int scantime;
    endian_t myformat, targetformat;
    float outVp, outVs, outrho;
    int outi, outj, outk;

    if (argc != 4) {
        printf("\nusage: dumpcvm cvmetree output format\n");
        printf("cvmetree: pathname to the CVM etree\n");
        printf("output: pathname to the flat output file\n");
        printf("format: little or big\n");
        exit(1);
    }

    cvmetree = argv[1];
    cvmEp = etree_open(cvmetree, O_RDONLY, 0, 0, 0);
    if (!cvmEp) {
        fprintf(stderr, "Cannot open CVM material database %s\n", cvmetree);
        exit(1);
    }


    outputfile = argv[2];
    outfp = fopen(outputfile, "w+");
    if (outfp == NULL) {
        perror("fopen");
        exit(1);
    }
        
    outformat = argv[3];
    if (strcmp(outformat, "little") == 0) {
        targetformat = little;
    } else if (strcmp(outformat, "big") == 0) {
        targetformat = big;
    } else {
        fprintf(stderr, "Unknown target data format\n");
        exit(1);
    }

    myformat = xplatform_testendian();

    /* go through all the records stored in the underlying btree */
    gettimeofday(&starttime, NULL);

    totalcount = 0;
    memset(cvmEp->key, 0, KEYSIZE);

    if (btree_initcursor(cvmEp->bp, cvmEp->key) != 0) {
        fprintf(stderr, "Cannot set cursor in the underlying database\n");
        exit(1);
    }

    do {
        etree_tick_t i, j, k;

        if (btree_getcursor(cvmEp->bp, cvmEp->hitkey, "*", &rawElem) != 0) {
            fprintf(stderr, "Read cursor error\n");
            exit(1);
        } 

        code_morton2coord(ETREE_MAXLEVEL + 1, (char *)cvmEp->hitkey + 1,
                          &i, &j, &k);
                

        /* Write to the output file, do format conversion if necessary */
        if (myformat == targetformat) {
            outi = i; 
            outj = j;
            outk = k;
            outVp = rawElem.Vp;
            outVs = rawElem.Vs;
            outrho = rawElem.rho;
        } else {
            xplatform_swapbytes(&outi, &i, 4);
            xplatform_swapbytes(&outj, &j, 4);
            xplatform_swapbytes(&outk, &k, 4);
            xplatform_swapbytes(&outVp, &rawElem.Vp, 4);
            xplatform_swapbytes(&outVs, &rawElem.Vs, 4);
            xplatform_swapbytes(&outrho, &rawElem.rho, 4);
        }

        if ((fwrite(&outi, 4, 1, outfp) != 1) ||
            (fwrite(&outj, 4, 1, outfp) != 1) ||
            (fwrite(&outk, 4, 1, outfp) != 1) ||
            (fwrite(&outVp, 4, 1, outfp) != 1) ||
            (fwrite(&outVs, 4, 1, outfp) != 1) ||
            (fwrite(&outrho, 4, 1, outfp) != 1)) {
            fprintf(stderr, "Error writing CVM record\n");
            perror("fwrite");
            exit(1);
        }

        
        totalcount++;
    } while (btree_advcursor(cvmEp->bp) == 0);

    if (fclose(outfp) != 0) {
        perror("fclose");
        exit(1);
    }
    etree_close(cvmEp);


    gettimeofday(&endtime, NULL);
    scantime = (endtime.tv_sec - starttime.tv_sec);

    printf("Dump the CVM database in %d seconds\n", scantime);
    printf("Dump %qd octants\n", totalcount);
    printf("Output format is %s-endian", outformat);
    printf("Output file is %s\n", outputfile);
 
    return 0;
}