Created
July 24, 2013 05:09
-
-
Save jzrake/6068200 to your computer and use it in GitHub Desktop.
Short example of using cow functions with parallel write and FFT's. This example is from the CAL group meeting on Wednesday 7/24, after Jonathan's going away party.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "cow.h" | |
double cheese_function(double x, double y, double z) | |
{ | |
return x + y + z; | |
} | |
double butter_function(double x, double y, double z) | |
{ | |
return x + y + z; | |
} | |
double yogurt_function(double x, double y, double z) | |
{ | |
return x + y + z; | |
} | |
int main(int argc, char **argv) | |
{ | |
cow_init(argc, argv, COW_DEFAULT); | |
cow_domain *domain = cow_domain_new(); | |
cow_dfield *dfield = cow_dfield_new(); | |
cow_domain_setndim(domain, 3); | |
cow_domain_setguard(domain, 3); | |
cow_domain_setsize(domain, 0, 128); | |
cow_domain_setsize(domain, 1, 128); | |
cow_domain_setsize(domain, 2, 128); | |
cow_domain_commit(domain); | |
cow_domain_setcollective(domain, 0); | |
cow_dfield_setdomain(dfield, domain); | |
cow_dfield_setname(dfield, "dairy"); | |
cow_dfield_addmember(dfield, "cheese"); | |
cow_dfield_addmember(dfield, "butter"); | |
cow_dfield_addmember(dfield, "yogurt"); | |
cow_dfield_commit(dfield); | |
double *dairy_data = (double*) cow_dfield_getdatabuffer(dfield); | |
int n,i,j,k; | |
int totsize = cow_domain_getnumlocalzonesincguard(domain, COW_ALL_DIMS); | |
int nx = cow_domain_getnumlocalzonesinterior(domain, 0); | |
int ny = cow_domain_getnumlocalzonesinterior(domain, 1); | |
int nz = cow_domain_getnumlocalzonesinterior(domain, 2); | |
int ng = cow_domain_getguard(domain); | |
int sx = cow_dfield_getstride(dfield, 0); | |
int sy = cow_dfield_getstride(dfield, 1); | |
int sz = cow_dfield_getstride(dfield, 2); | |
for (n=0; n<totsize; ++n) { | |
dairy_data[3*n + 0] = 1.0; // cheese | |
dairy_data[3*n + 1] = 2.0; // butter | |
dairy_data[3*n + 2] = 3.0; // yogurt | |
} | |
for (i=ng; i<nx + ng; ++i) { | |
for (j=ng; j<ny + ng; ++j) { | |
for (k=ng; k<nz + ng; ++k) { | |
double x = cow_domain_positionatindex(domain, 0, i); | |
double y = cow_domain_positionatindex(domain, 1, j); | |
double z = cow_domain_positionatindex(domain, 2, k); | |
int m = i*sx + j*sy + k*sz; | |
dairy_data[m + 0] = cheese_function(x, y, z); | |
dairy_data[m + 1] = butter_function(x, y, z); | |
dairy_data[m + 2] = yogurt_function(x, y, z); | |
} | |
} | |
} | |
cow_dfield_syncguard(dfield); | |
cow_dfield_write(dfield, "dairy.h5"); | |
cow_fft_helmholtzdecomp(dfield, COW_PROJECT_OUT_CURL); | |
cow_dfield_del(dfield); | |
cow_domain_del(domain); | |
cow_finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment