#include #include #include #include "define.h" #include "comp_errors.h" #include "files.h" #include "boid.h" #include "box.h" #include "nextstep.h" #include "main.h" #ifdef ENDO_GAMMA #define GAMMA_FILE #endif #ifdef ECTO_GAMMA #ifndef GAMMA_FILE #define GAMMA_FILE #endif #endif #ifdef COUNT_NEIGHBORS double getAverageNeighborsNo(const struct Boid* const boid) /* Where 'boid' is address of the first element of an array. */ { unsigned int boidCount; double averageNeighborsNo = 0.0; for (boidCount = 0; boidCount < N; ++boidCount) averageNeighborsNo += ((double)boid[boidCount].endoNeighbors + \ (double)boid[boidCount].ectoNeighbors); averageNeighborsNo /= N; return averageNeighborsNo; } #endif #if defined(ENDO_GAMMA) || defined(ECTO_GAMMA) double getGamma (const struct Boid* const boids) { double gamma = 0.0; unsigned int boidCount; unsigned int endoBoids = (unsigned)(ENDOPROP*N); // printf("EndoBoids: %u\n", endoBoids); #ifdef ENDO_GAMMA for (boidCount = endoBoids; boidCount < N; --boidCount) /* Considering overflow. */ gamma += boids[boidCount].gamma; #endif // printf("BoidCount: %u\n", boidCount); #ifdef ECTO_GAMMA for (boidCount = endoBoids + 1; boidCount < N; ++boidCount) gamma += boids[boidCount].gamma; #endif #ifdef ENDO_GAMMA #ifdef ECTO_GAMMA gamma /= N; #else gamma /= endoBoids; #endif #else #ifdef ECTO_GAMMA gamma /= (N-endoBoids); #endif #endif return gamma; } #endif /* #if defined(ENDO_GAMMA) || defined(ECTO_GAMMA) */ void one_system () { struct Boid boids[N]; struct Box boxes[BOXES]; unsigned int boidCount, boxID, threadCount; unsigned long long int step, continuousStep = 0; FILE* godFile = initializeGodFile(); FILE* finalConfigurationFile; #ifdef PLOT_EXIT_FILES FILE* endoFile; FILE* ectoFile; #endif #ifdef GAMMA_FILE FILE* gammaFile = initializeGammaFile(); #endif #ifdef COUNT_NEIGHBORS FILE* averageNeighborsFile = initializeAverageNeighborsFile(); #endif /* Set the pthread_create parameters. */ struct Parameters parametersStruct[NUM_THREADS]; void* parameters[NUM_THREADS]; for (threadCount=0; threadCount 1) { if (strcmp(argv[1], "-p") == 0) printParameters(); else printHelp(); } else { int returned = checkParameters(); if (returned != 0) return returned; srand(time(NULL)); one_system(); } return 0; }