You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			81 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
#include "Py_py-api.h"
 | 
						|
#include "genlib.h"
 | 
						|
#include "geostat.h"
 | 
						|
#include "simpio.h"
 | 
						|
#include "toolsFFTMA.h"
 | 
						|
#include "toolsIO.h"
 | 
						|
#include "log.h"
 | 
						|
#include "memory.h"
 | 
						|
#include <Python.h>
 | 
						|
#include <numpy/arrayobject.h>
 | 
						|
#include <stdarg.h>
 | 
						|
#include <stddef.h>
 | 
						|
#include <stdio.h>
 | 
						|
#include <stdlib.h>
 | 
						|
#include <string.h>
 | 
						|
#include <time.h>
 | 
						|
 | 
						|
/* kgeneration   */
 | 
						|
/* Z is the GWN with 0-mean and 1-variance */
 | 
						|
/* Y is the realization with mean and variance wanted */
 | 
						|
 | 
						|
void Py_kgeneration(long seed, struct grid_mod grid, struct statistic_mod stat, struct vario_mod variogram, struct realization_mod* Z, struct realization_mod* Y, int n[3], int cores) { 
 | 
						|
    double* used_ram_t0 = malloc(sizeof(double));
 | 
						|
    getVirtualMemUsed(used_ram_t0);
 | 
						|
 | 
						|
    clock_t t = clock();
 | 
						|
 
 | 
						|
    int i, N;
 | 
						|
    int typelog;
 | 
						|
 | 
						|
    /*generate Gaussian white noise*/
 | 
						|
    N = grid.NX * grid.NY * grid.NZ;
 | 
						|
    n[0] = 0;
 | 
						|
    n[1] = 0;
 | 
						|
    n[2] = 0;
 | 
						|
 | 
						|
    log_info("RESULT = in progress, N = %d", N);
 | 
						|
 | 
						|
    struct cpustat initial[cores];
 | 
						|
    struct cpustat final[cores];
 | 
						|
 | 
						|
    for (int i = 0; i < cores; i++) {
 | 
						|
        get_stats(&initial[i], i - 1);
 | 
						|
    }
 | 
						|
 | 
						|
    generate(&seed, N, Z, cores);
 | 
						|
 | 
						|
    /*FFTMA*/
 | 
						|
    printf("pre fftma2\n");
 | 
						|
    FFTMA2(variogram, grid, n, Z, Y, cores, &seed);
 | 
						|
    printf("post fftma2\n");
 | 
						|
 | 
						|
    /* make a log normal realization */
 | 
						|
    if (stat.type == 1 || stat.type == 2) {
 | 
						|
        typelog = stat.type + 2;
 | 
						|
        nor2log(Y, typelog, Y);
 | 
						|
    }
 | 
						|
 | 
						|
    printf("termino nor2log\n");
 | 
						|
 | 
						|
    t = clock() - t;
 | 
						|
    double time_taken = ((double)t)/CLOCKS_PER_SEC; // calculate the elapsed time
 | 
						|
 | 
						|
    for (int i = 0; i < cores; i++) {
 | 
						|
        get_stats(&final[i], i - 1);
 | 
						|
    }
 | 
						|
 | 
						|
    for (int i = 0; i < cores; i++) {
 | 
						|
        log_info("CPU %d: %lf%%", i, calculate_load(&initial[i], &final[i]));
 | 
						|
    }
 | 
						|
 | 
						|
    double* used_ram_tf = malloc(sizeof(double));
 | 
						|
    getVirtualMemUsed(used_ram_tf);
 | 
						|
    
 | 
						|
    log_info("RESULT = success, ELAPSED = %f seconds, DIF USED VIRTUAL MEM = %5.1f MB", time_taken, *used_ram_tf - *used_ram_t0);
 | 
						|
 | 
						|
    printf("termino pykgeneration\n");
 | 
						|
    free(used_ram_t0);
 | 
						|
    free(used_ram_tf);
 | 
						|
}
 |