00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <math.h>
00005
00006 #include "allvars.h"
00007 #include "proto.h"
00008
00019 void allocate_commbuffers(void)
00020 {
00021 size_t bytes;
00022
00023 Exportflag = malloc(NTask * sizeof(char));
00024 DomainStartList = malloc(NTask * sizeof(int));
00025 DomainEndList = malloc(NTask * sizeof(int));
00026
00027 TopNodes = malloc(MAXTOPNODES * sizeof(struct topnode_data));
00028
00029 DomainWork = malloc(MAXTOPNODES * sizeof(double));
00030 DomainCount = malloc(MAXTOPNODES * sizeof(int));
00031 DomainCountSph = malloc(MAXTOPNODES * sizeof(int));
00032 DomainTask = malloc(MAXTOPNODES * sizeof(int));
00033 DomainNodeIndex = malloc(MAXTOPNODES * sizeof(int));
00034 DomainTreeNodeLen = malloc(MAXTOPNODES * sizeof(FLOAT));
00035 DomainHmax = malloc(MAXTOPNODES * sizeof(FLOAT));
00036 DomainMoment = malloc(MAXTOPNODES * sizeof(struct DomainNODE));
00037
00038 if(!(CommBuffer = malloc(bytes = All.BufferSize * 1024 * 1024)))
00039 {
00040 printf("failed to allocate memory for `CommBuffer' (%g MB).\n", bytes / (1024.0 * 1024.0));
00041 endrun(2);
00042 }
00043
00044 All.BunchSizeForce =
00045 (All.BufferSize * 1024 * 1024) / (sizeof(struct gravdata_index) + 2 * sizeof(struct gravdata_in));
00046
00047 if(All.BunchSizeForce & 1)
00048 All.BunchSizeForce -= 1;
00049
00050
00051 GravDataIndexTable = (struct gravdata_index *) CommBuffer;
00052 GravDataIn = (struct gravdata_in *) (GravDataIndexTable + All.BunchSizeForce);
00053 GravDataGet = GravDataIn + All.BunchSizeForce;
00054 GravDataOut = GravDataIn;
00055 GravDataResult = GravDataGet;
00056
00057
00058 All.BunchSizeDensity =
00059 (All.BufferSize * 1024 * 1024) / (2 * sizeof(struct densdata_in) + 2 * sizeof(struct densdata_out));
00060
00061 DensDataIn = (struct densdata_in *) CommBuffer;
00062 DensDataGet = DensDataIn + All.BunchSizeDensity;
00063 DensDataResult = (struct densdata_out *) (DensDataGet + All.BunchSizeDensity);
00064 DensDataPartialResult = DensDataResult + All.BunchSizeDensity;
00065
00066 All.BunchSizeHydro =
00067 (All.BufferSize * 1024 * 1024) / (2 * sizeof(struct hydrodata_in) + 2 * sizeof(struct hydrodata_out));
00068
00069 HydroDataIn = (struct hydrodata_in *) CommBuffer;
00070 HydroDataGet = HydroDataIn + All.BunchSizeHydro;
00071 HydroDataResult = (struct hydrodata_out *) (HydroDataGet + All.BunchSizeHydro);
00072 HydroDataPartialResult = HydroDataResult + All.BunchSizeHydro;
00073
00074 All.BunchSizeDomain =
00075 (All.BufferSize * 1024 * 1024) / (sizeof(struct particle_data) + sizeof(struct sph_particle_data) +
00076 sizeof(peanokey));
00077
00078 if(All.BunchSizeDomain & 1)
00079 All.BunchSizeDomain -= 1;
00080
00081
00082 DomainPartBuf = (struct particle_data *) CommBuffer;
00083 DomainSphBuf = (struct sph_particle_data *) (DomainPartBuf + All.BunchSizeDomain);
00084 DomainKeyBuf = (peanokey *) (DomainSphBuf + All.BunchSizeDomain);
00085
00086
00087 if(ThisTask == 0)
00088 {
00089 printf("\nAllocated %d MByte communication buffer per processor.\n\n", All.BufferSize);
00090 printf("Communication buffer has room for %d particles in gravity computation\n", All.BunchSizeForce);
00091 printf("Communication buffer has room for %d particles in density computation\n", All.BunchSizeDensity);
00092 printf("Communication buffer has room for %d particles in hydro computation\n", All.BunchSizeHydro);
00093 printf("Communication buffer has room for %d particles in domain decomposition\n", All.BunchSizeDomain);
00094 printf("\n");
00095 }
00096 }
00097
00098
00099
00103 void allocate_memory(void)
00104 {
00105 size_t bytes;
00106 double bytes_tot = 0;
00107
00108 if(All.MaxPart > 0)
00109 {
00110 if(!(P = malloc(bytes = All.MaxPart * sizeof(struct particle_data))))
00111 {
00112 printf("failed to allocate memory for `P' (%g MB).\n", bytes / (1024.0 * 1024.0));
00113 endrun(1);
00114 }
00115 bytes_tot += bytes;
00116
00117 if(ThisTask == 0)
00118 printf("\nAllocated %g MByte for particle storage. %d\n\n", bytes_tot / (1024.0 * 1024.0), sizeof(struct particle_data));
00119 }
00120
00121 if(All.MaxPartSph > 0)
00122 {
00123 bytes_tot = 0;
00124
00125 if(!(SphP = malloc(bytes = All.MaxPartSph * sizeof(struct sph_particle_data))))
00126 {
00127 printf("failed to allocate memory for `SphP' (%g MB) %d.\n", bytes / (1024.0 * 1024.0), sizeof(struct sph_particle_data));
00128 endrun(1);
00129 }
00130 bytes_tot += bytes;
00131
00132 if(ThisTask == 0)
00133 printf("Allocated %g MByte for storage of SPH data. %d\n\n", bytes_tot / (1024.0 * 1024.0), sizeof(struct sph_particle_data));
00134 }
00135 }
00136
00137
00138
00139
00144 void free_memory(void)
00145 {
00146 if(All.MaxPartSph > 0)
00147 free(SphP);
00148
00149 if(All.MaxPart > 0)
00150 free(P);
00151 }
00152