단위 질량의 10^10 입자에 대한 질량 분포 코드를 시뮬레이트하고 싶습니다.float 배열의 최대 인덱싱 범위는 무엇입니까?
그러나이 코드는 입자 수가 10^8 인 경우에만 작동합니다.
long par = 85000000;
float p[85000000][2];
및 크기로 진행이 에러를 나타낸다^9 10 10^10
하다 "재배치 맞게 절단"
long par = 85000000;
float p[85000000][2];
방법 float 배열의 가능한 최대 인덱싱 범위를 찾으려면?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <sys/time.h>
long double net[4096][4096];
int max = 4000;
long par = 85000000;
float p[85000000][2];
int main(int argc, char *argv[]) {
int i;
for(i = 0; i < par/1000; i++) {
p[i][0]= ((long double)rand()/(long double)(RAND_MAX) * (long double)max);
p[i][1]= ((long double)rand()/(long double)(RAND_MAX) * (long double)max);
}
clock_t begin = clock();
for (i = 0; i < par/1000; i++) {
double x = p[i][0];
double y = p[i][1];
int left = (int)floor(x);
int right = left + 1;
if (left >= 4095)
printf("out of bound left is %d/n", left);
int bottom = (int)floor(y);
int top = bottom +1;
double fL = x - left;
double fR = 1 - fL;
double fB = y - bottom;
double fT = 1 - fB;
net[left][bottom] = net[left][bottom] +(fT * fR) ;
net[right][bottom] = net[right][bottom] +(fT * fL) ;
net[left][top] = net[left][top] +(fB * fR) ;
net[right][top] = net[right][top] +(fB * fL) ;
}
clock_t close = clock();
FILE *f = fopen("file.txt", "a");
if (!f) {
printf("Error opening file!\n");
exit(1);
}
fprintf (f,"Computation time for grid size %d X %d and %ld particle is "
"%4.6lf ,\n",max, max,par,(double)(close-begin));
fclose(f);
}
의 namesake입니까? 어떤 이유로'malloc '을 사용하지 않습니까? – usr2564301
스택 제한을 맞추기 위해'malloc'과 힙 메모리를 사용합니다. – meskobalazs
@meskobalazs 응답 시간! – Quentin