Esempio n. 1
0
void test_phase4(void){
	struct pptoken *token;
	struct list *source;
	struct list *p1;
	struct list *p2;
	struct list *p3;
	struct list *p4;
	struct hash_table *macros;

	//source = sourceCharsFromFile("tests/trigraphs.c");
	//source = sourceCharsFromFile("tests/doubledefine.c");
	//source = sourceCharsFromFile("tests/recursivedefine.c");
	source = sourceCharsFromFile("tests/functionmacro.c");
	p1 = phase1(source);
	p2 = phase2(p1);
	p3 = phase3(p2);

	macros = newHashTable();
	assert(macros != NULL);

	p4 = phase4(macros, p3);

	while(listDequeue(p4, (void**)&token) == 0){
		fputs(token->whiteSpace, stdout);
		if(token->name != PPTN_EOF){
			putchar('{');
			printf("\033[35m");
			fputs(token->lexeme, stdout);
			printf("\033[39m");
			putchar('}');
		} else {
			break;
		}
	}
}
Esempio n. 2
0
int main(void) {
	if (phase1() == 0) {
		printf("Phase 1: End of Phase 1 for File Server 2.\n");
	}

	phase3();

	exit(0);
}
int main()
{
	int sockfd, numbytes;
	char buf[MAXDATASIZE];
	char *mes="File_Server3 43010";

	struct addrinfo hints, *servinfo, *p,*servFile,*res;
	int rv,rs;
	int y=1;

	memset(&hints, 0, sizeof hints);
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_DGRAM;
	if ((rv = getaddrinfo("nunki.usc.edu", SIDPORT, &hints, &servinfo)) != 0) {
		fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
		return 1;
	}
	if ((rv = getaddrinfo("nunki.usc.edu", SIDFPORT, &hints, &servFile)) != 0) {
		fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
		return 1;
	}
	struct hostent *lh = gethostbyname("nunki.usc.edu");
	printf("The File Server 3 has UDP port number %s",SIDFPORT);
	printf(" and IP address  %s .\n",inet_ntoa(*((struct in_addr *)lh->h_addr)));
	// loop through all the results and connect to the first we can
	for(p = servinfo; p != NULL; p = p->ai_next) {
		if ((sockfd = socket(p->ai_family, p->ai_socktype,p->ai_protocol)) == -1) {
			perror("client: socket");
			continue;
		}
		if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &y,sizeof(int)) == -1){
			perror("setsockopt");
			exit(1);
		}
		res=servFile;
		if (bind(sockfd, res->ai_addr,res->ai_addrlen) == -1){
			close(sockfd);
			perror("listener: bind");
			continue;
		}
		break;
	}

	if (p == NULL) {
		fprintf(stderr, "client: failed to connect\n");
		return 2;
	}

	if ((numbytes = sendto(sockfd, mes, strlen(mes), 0,p->ai_addr, p->ai_addrlen)) == -1) {
		printf("hello\n");
		perror("talker: sendto");
		exit(1);
	}
	printf("The registration request from File Server 3 has been sent to the Directory Server.\n ");
	printf("End of Phase 2 for File Server 3.\n ");
	close(sockfd);
	freeaddrinfo(servinfo); // all done with this structure
	freeaddrinfo(servFile);
	phase3();
	return 0;
}
void gen_schedule_plan(){	
	
#ifdef DEVELOPING
	numVcore = 8;
	numPcore = 6;
#else
	// get from hypervisor
	// numVcore =;
	// numPcore =;
#endif
	
	vcoreContainer = (VIRT_CORE**)malloc(sizeof(VIRT_CORE*)*numVcore);
	pcoreContainer = (PHYS_CORE**)malloc(sizeof(PHYS_CORE*)*numPcore);

#ifdef DEVELOPING
	VIRT_CORE* temp_c;
	for(int i=0;i<numVcore;i++){
		temp_c = (VIRT_CORE*)malloc(sizeof(VIRT_CORE));
		temp_c->domain = i/4;
		temp_c->num = i%4;
		temp_c->requ = 100000*(i+1);
		temp_c->code = i;
		vcoreContainer[i] = temp_c;
	}

	PHYS_CORE* temp_p;
	for(int i=0;i<numPcore;i++){
		temp_p = (PHYS_CORE*)malloc(sizeof(PHYS_CORE));
		(i<2)?(temp_p->freq = 1200000):(temp_p->freq = 600000);
		(i<2)?(temp_p->type = TYPE_BIG):(temp_p->type = TYPE_LITTLE);
		temp_p->efficient = temp_p->type;
		temp_p->load = 0;
		temp_p->num = i;
		temp_p->workload = (int*)malloc(sizeof(int)*numVcore);
		for(int j=0;j<numVcore;j++){
			temp_p->workload[j] = 0;
		}
		pcoreContainer[i] = temp_p;
	}
#else
	// fetch vcpu and pcpu info
#endif


#ifdef DEVELOPING
	clock_t t;
	t = clock();
	// phase 1
	phase1();
	t = clock() - t;
	fprintf(stderr, "phase 1: %d ticks (%.3lf seconds).\n", t, ((double)t)/CLOCKS_PER_SEC);
	
	t = clock();
	// phase 2
	eSlice.next = NULL;
	phase2();
	t = clock() - t;
	fprintf(stderr, "phase 2: %d ticks (%.3lf seconds).\n", t, ((double)t)/CLOCKS_PER_SEC);

	t = clock();
	// phase 3
	phase3();
	t = clock() - t;
	fprintf(stderr, "phase 3: %d ticks (%.3lf seconds).\n", t, ((double)t)/CLOCKS_PER_SEC);
#else
	// phase 1
	phase1();

	// phase 2
	eSlice.next = NULL;
	phase2();

	// phase 3
	phase3();
#endif

	// clean up
	ExecutionSlice* target;
	while(exePlan.next != NULL){
		target = exePlan.next;
		exePlan.next = exePlan.next->next;
		free(target);
	};

	for(int i=0;i<numPcore;i++){
		free(pcoreContainer[i]);
	}
	free(pcoreContainer);

	for(int i=0;i<numVcore;i++){
		free(vcoreContainer[i]);
	}
	free(vcoreContainer);
}
Esempio n. 5
0
int SubdivideExtrudedMesh(GModel *m)
{
  // get all non-recombined extruded regions and vertices; also,
  // create a vector of quadToTri regions that have NOT been meshed
  // yet
  std::vector<GRegion*> regions, regions_quadToTri;
  MVertexRTree pos(CTX::instance()->geom.tolerance * CTX::instance()->lc);
  for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); it++){
    ExtrudeParams *ep = (*it)->meshAttributes.extrude;
    if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY &&
       !ep->mesh.Recombine){
      regions.push_back(*it);
      insertAllVertices(*it, pos);
    }
    // create vector of valid quadToTri regions...not all will necessarily be meshed here.
    if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY &&
       ep->mesh.Recombine && ep->mesh.QuadToTri){
      regions_quadToTri.push_back(*it);
    }
  }

  if(regions.empty()) return 0;
  Msg::Info("Subdividing extruded mesh");

  // create edges on lateral sides of "prisms"
  std::set<std::pair<MVertex*, MVertex*> > edges;
  for(unsigned int i = 0; i < regions.size(); i++)
    phase1(regions[i], pos, edges);

  // swap lateral edges to make them "tet-compatible"
  int j = 0, swap;
  std::set<std::pair<MVertex*, MVertex*> > edges_swap;
  do {
    swap = 0;
    for(unsigned int i = 0; i < regions.size(); i++)
      phase2(regions[i], pos, edges, edges_swap, swap);
    Msg::Info("Swapping %d", swap);
    if(j && j == swap) {
      Msg::Error("Unable to subdivide extruded mesh: change surface mesh or");
      Msg::Error("recombine extrusion instead");
      return -1;
    }
    j = swap;
  } while(swap);

  // delete volume elements and create tetrahedra instead
  for(unsigned int i = 0; i < regions.size(); i++){
    GRegion *gr = regions[i];

    for(unsigned int i = 0; i < gr->tetrahedra.size(); i++)
      delete gr->tetrahedra[i];
    gr->tetrahedra.clear();
    for(unsigned int i = 0; i < gr->hexahedra.size(); i++)
      delete gr->hexahedra[i];
    gr->hexahedra.clear();
    for(unsigned int i = 0; i < gr->prisms.size(); i++)
      delete gr->prisms[i];
    gr->prisms.clear();
    for(unsigned int i = 0; i < gr->pyramids.size(); i++)
      delete gr->pyramids[i];
    gr->pyramids.clear();
    phase3(gr, pos, edges);

    // re-Extrude bounding surfaces using edges as constraint
    std::list<GFace*> faces = gr->faces();
    for(std::list<GFace*>::iterator it = faces.begin(); it != faces.end(); it++){
      ExtrudeParams *ep = (*it)->meshAttributes.extrude;
      if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY &&
        !ep->mesh.Recombine){
        GFace *gf = *it;
        Msg::Info("Remeshing surface %d", gf->tag());
        for(unsigned int i = 0; i < gf->triangles.size(); i++)
          delete gf->triangles[i];
        gf->triangles.clear();
        for(unsigned int i = 0; i < gf->quadrangles.size(); i++)
          delete gf->quadrangles[i];
        gf->quadrangles.clear();
        MeshExtrudedSurface(gf, &edges);
      }
    }
  }

  // now mesh the QuadToTri regions. Everything can be done locally
  // for each quadToTri region, but still use edge set from above just
  // to make sure laterals get remeshed properly (
  // QuadToTriEdgeGenerator detects if the neighbor has been meshed or
  // if a lateral surface should remain static for any other reason).
  // If this function detects allNonGlobalSharedLaterals, it won't
  // mesh the region (should already be done in ExtrudeMesh).
  for(unsigned int i = 0; i < regions_quadToTri.size(); i++){
    GRegion *gr = regions_quadToTri[i];
    MVertexRTree pos_local(CTX::instance()->geom.tolerance * CTX::instance()->lc);
    insertAllVertices(gr, pos_local);
    meshQuadToTriRegionAfterGlobalSubdivide(gr, &edges, pos_local);
  }

  // carve holes if any
  // TODO: update extrusion information
  for(unsigned int i = 0; i < regions.size(); i++){
    GRegion *gr = regions[i];
    ExtrudeParams *ep = gr->meshAttributes.extrude;
    if(ep->mesh.Holes.size()){
      std::map<int, std::pair<double, std::vector<int> > >::iterator it;
      for(it = ep->mesh.Holes.begin(); it != ep->mesh.Holes.end(); it++)
        carveHole(gr, it->first, it->second.first, it->second.second);
    }
  }
  for(unsigned int i = 0; i < regions_quadToTri.size(); i++){
    GRegion *gr = regions_quadToTri[i];
    ExtrudeParams *ep = gr->meshAttributes.extrude;
    if(ep->mesh.Holes.size()){
      std::map<int, std::pair<double, std::vector<int> > >::iterator it;
      for(it = ep->mesh.Holes.begin(); it != ep->mesh.Holes.end(); it++)
        carveHole(gr, it->first, it->second.first, it->second.second);
    }
  }

  return 1;
}
Esempio n. 6
0
int main(int argc, char **argv)
{
    if (argc != 4) {
        printf("usage: %s <server-address> <server-port> <phase[-1 - 6]>\n",
                argv[0]);
        return EXIT_FAILURE;
    }
    int start_phase = atoi(argv[3]);

    bool res;

    test_state_t *state = NULL;
    rvm_cfg_t *cfg;
    if(start_phase >= 0) {
        /* Try to recover from server */
        cfg = initialize_rvm(argv[1], argv[2], true,
                create_rmem_layer);

        /* Recover the state (if any) */
        state = (test_state_t*)rvm_get_usr_data(cfg);
    } else {
        /* Starting from scratch */
        cfg = initialize_rvm(argv[1], argv[2], false,
                create_rmem_layer);
        CHECK_ERROR(cfg == NULL, ("Failed to initialize rvm\n"));

        state = NULL;
    }

    rvm_txid_t txid;
    /*====================================================================
     * TX 0 - Allocate and Initialize Arrays
     *===================================================================*/
    /* If state is NULL then we are starting from scratch or recovering from
       an early error */
    if(state == NULL) {
        LOG(1,("Phase 0:\n"));
        TX_START;

        /* Allocate a "state" structure to test pointers */
        state = (test_state_t*)rvm_alloc(cfg, sizeof(test_state_t));
        CHECK_ERROR(state == NULL, ("FAILURE: Couldn't allocate state\n"));

        /* Initialize the arrays */ 
        res = phase0(cfg, state);
        CHECK_ERROR(!res, ("FAILURE: Phase 0 Failure\n"));

        if(start_phase == -1) {
            LOG(1, ("SUCCESS: Phase 0, simulating failure\n"));
            return EXIT_SUCCESS;
        }

        /* End of first txn */
        state->phase = PHASE1;
        TX_COMMIT;
    }

    switch(state->phase) {
    case PHASE1:
        /*====================================================================
         * TX 1 Increment arrays, don't mess with LL
         *===================================================================*/
        LOG(1, ("Phase 1:\n"));
        TX_START;
        
        res = phase1(cfg, state);
        CHECK_ERROR(!res, ("FAILURE: Phase 1 failed\n"));

        /* Simulate Failure */
        if(start_phase == 0) {
            LOG(1, ("SUCCESS: Phase 1, simulating failure\n"));
            return EXIT_SUCCESS;
        }

        state->phase = PHASE2;
        TX_COMMIT;
    
    case PHASE2: //Fallthrough
        /*====================================================================
         * TX 2 Free Arrays
         *===================================================================*/
        LOG(1, ("Phase 2:\n"));
        TX_START;

        res = phase2(cfg, state);
        CHECK_ERROR(!res, ("FAILURE: Phase 2 failed\n"));

        /* Simulate Failure */
        if(start_phase == 1) {
            LOG(1, ("SUCCESS: Phase 2, simulating failure\n"));
            return EXIT_SUCCESS;
        }

        state->phase = PHASE3;
        TX_COMMIT;

    case PHASE3: //Fallthrough
        /*====================================================================
         * TX 3 Fill in Linked list
         *===================================================================*/
        LOG(1, ("Phase 3:\n"));
        TX_START;

        res = phase3(cfg, state);
        CHECK_ERROR(!res, ("FAILURE: Phase 3 failed\n"));

        /* Simulate Failure */
        if(start_phase == 2) {
            LOG(1, ("SUCCESS: Phase 3, simulating failure\n"));
            return EXIT_SUCCESS;
        }

        state->phase = PHASE4;
        TX_COMMIT;

    case PHASE4:
        /*====================================================================
         * TX 4 Free Half the linked list
         *===================================================================*/
        LOG(1, ("Phase 4:\n"));
        TX_START;

        res = phase4(cfg, state);
        CHECK_ERROR(!res, ("FAILURE: Phase 4 failed\n"));

         /* Simulate Failure */
        if(start_phase == 3) {
            LOG(1, ("SUCCESS: Phase 4, simulating failure\n"));
            return EXIT_SUCCESS;
        }

        state->phase = PHASE5;
        TX_COMMIT;

    case PHASE5:
        /*====================================================================
         * TX 5 Re-allocate half of the linked list
         *===================================================================*/
        LOG(1, ("Phase 5:\n"));
        TX_START;

        res = phase5(cfg, state);
        CHECK_ERROR(!res, ("FAILURE: Phase 5 failed\n"));

         /* Simulate Failure */
        if(start_phase == 4) {
            LOG(1, ("SUCCESS: Phase5, simulating failure\n"));
            return EXIT_SUCCESS;
        }

       state->phase = PHASE6;
        TX_COMMIT;

    case PHASE6:
        /*====================================================================
         * TX 6 Free whole linked list
         *===================================================================*/
        LOG(1, ("Phase 6:\n"));
        TX_START;

        res = phase6(cfg, state);
        CHECK_ERROR(!res, ("FAILURE: Phase 6 failed\n"));

        /* Simulate Failure */
        if(start_phase == 5) {
            LOG(1, ("SUCCESS: Phase 6, simulating failure\n"));
            return EXIT_SUCCESS;
        }

        state->phase = DONE;
        TX_COMMIT;

    case DONE:
        res = rvm_cfg_destroy(cfg);
        CHECK_ERROR(!res, ("FAILURE: Failed to destroy rvm state\n"));

        LOG(1, ("SUCCESS: Got through all phases\n"));
        break;

    default:
        LOG(1, ("FAILURE: Corrupted State, tried phase %d\n", state->phase));
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
Esempio n. 7
0
void
psrs(int size, int rank, int nInts, int *toSort, char *fname)
{
	char hname[256];
	double start, end, total = 0, algStart;
	int i, *privateInts, *regularSamples, *collectedSamples, *pivots, 
	    *partitionIndices, *localPartitionSizes, *incomingPartitionSizes, 
	    **partitions, *mergedPartitions, *partitionSizes, *sortedArray; 

	FILE *fptr = NULL;
	if (rank == MASTER) fptr = fopen(fname, "a");
	
	memset (hname, '\0', sizeof(unsigned char)*256);
	gethostname(hname, 255);

	DBPRINT(("%d of %d running on pid %d %s\n", rank, size, getpid(), 
	    hname));

	if (rank == MASTER) {
		collectedSamples = calloc(1, sizeof(int)*size*size);
		if (!collectedSamples) {
			err(1,"Failed to allocate memory for collected samples "
			   "array for master process");
			MPI_Finalize();
			exit(1);
		}				
	}
	MPI_Barrier(MPI_COMM_WORLD);

	if (nInts < VALIDATION_THRESHOLD) validateResults = 1;

	/* 
	 * "Phase 0" in which the array is split into contiguous chunks
	 * distributed amongst the processes.
	 */
	phase0(size, rank, nInts, toSort, &privateInts);

	/* Phase 1 */

	algStart = MPI_Wtime();
	START_TIMER((start));
	phase1(size, rank, nInts, toSort, privateInts, &regularSamples);
	MPI_Barrier(MPI_COMM_WORLD);
	STOP_TIMER((1), (start), (end), (total), (rank), (fptr));

	/* Phase 2 */
	START_TIMER((start));
	phase2(size, rank, regularSamples, &collectedSamples, &pivots);
	MPI_Barrier(MPI_COMM_WORLD);
	STOP_TIMER((2), (start), (end), (total), (rank), (fptr));

	/* Phase 3 */
	START_TIMER((start));
	phase3(size, rank, nInts, privateInts, pivots, &localPartitionSizes,
	    &partitionIndices, &incomingPartitionSizes, &partitions); 
	MPI_Barrier(MPI_COMM_WORLD);
	STOP_TIMER((3), (start), (end), (total), (rank), (fptr));

	/* Phase 4 */
	START_TIMER((start));
	phase4(size, incomingPartitionSizes, partitions, &mergedPartitions);
	MPI_Barrier(MPI_COMM_WORLD);
	STOP_TIMER((4), (start), (end), (total), (rank), (fptr));
	if (rank == MASTER) {
		total = end - algStart;
		fprintf(fptr, "The algorithm took %f seconds in total\n", total);
	}

	if (!validateResults) return;


	/* Run validation test */
	
	/* "Phase 5" concatenate the lists back at the master */
	phase5(size, rank, nInts, incomingPartitionSizes,
	    mergedPartitions, &partitionSizes, &sortedArray);

	/* 
	 * Assert that the array is equivalent to the sorted original array
	 * where we sort the original array using a known, proven, sequential,
	 * method.
	 */
	if (rank == MASTER) {
		qsort(toSort, nInts, sizeof(int), intComp);
	}

	for (i = 0; i < nInts; i++) {
		if (rank == MASTER) {
			if (toSort[i] != sortedArray[i]) {
				printf("OH NO, got %d at pos %d, expected "
				    "%d\n", sortedArray[i], i, toSort[i]);
			}
		}
	}
	
	if (rank == MASTER) fclose(fptr);
}