Commit e5a5c67a authored by Sergey Litvinov's avatar Sergey Litvinov
Browse files

copy-past all units

parent 26edc647
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#include <conf.h>
#include "inc/conf.h"
#include "algo/force_stat/imp.h"
#include "d/api.h"
#include "inc/dev.h"
#include "inc/type.h"
#include "io/txt/imp.h"
#include "mpi/glb.h"
#include "conf/imp.h"
#include "conf/imp.h"
#include "utils/cc.h"
#include "utils/mc.h"
#include "utils/error.h"
#include "utils/imp.h"
#include "utils/msg.h"
#include "mpi/wrapper.h"
static const char *prog_name = "./udx";
void usg0() {
fprintf(stderr, "%s i=\\\"force.txt\\\"\n", prog_name);
fprintf(stderr, "force.txt: f0x f0y f0z\n");
fprintf(stderr, " ...\n");
fprintf(stderr, " fnx fny fnz\n");
fprintf(stderr, "dumps forces statistics\n");
exit(0);
}
void usg(int c, char **v) {
if (c > 1 && same_str(v[1], "-h"))
usg0();
}
void main0(int n, const Force *hst) {
float max;
Force *dev;
Dalloc(&dev, n);
cH2D(dev, hst, n);
UC(max = force_stat_max(n, dev));
printf("%g\n", max);
Dfree(dev);
}
int main(int argc, char **argv) {
const char *i; /* input file */
const Force *ff;
int n, rank;
Config *cfg;
TxtRead *txt;
MPI_Comm cart;
int dims[3];
usg(argc, argv);
m::ini(&argc, &argv);
m::get_dims(&argc, &argv, dims);
m::get_cart(MPI_COMM_WORLD, dims, &cart);
MC(m::Comm_rank(cart, &rank));
msg_ini(rank);
UC(conf_ini(&cfg));
UC(conf_read(argc, argv, /**/ cfg));
UC(conf_lookup_string(cfg, "i", &i));
UC(txt_read_ff(i, &txt));
ff = txt_read_get_ff(txt);
n = txt_read_get_n(txt);
UC(main0(n, ff));
UC(txt_read_fin(txt));
UC(conf_fin(cfg));
MC(m::Barrier(cart));
m::fin();
}
#include <stdio.h>
#include <float.h>
#include <mpi.h>
#include "utils/mc.h"
#include "utils/msg.h"
#include "mpi/glb.h"
#include "mpi/wrapper.h"
#include "utils/mc.h"
#include "algo/kahan_sum/imp.h"
void main0() {
double input, sum, sum0;
KahanSum *kahan_sum;
kahan_sum_ini(&kahan_sum);
sum0 = 0;
while (scanf("%lf", &input) == 1) {
kahan_sum_add(kahan_sum, input);
sum0 += input;
}
sum = kahan_sum_get(kahan_sum);
printf("%.17e %.17e\n",sum, sum0);
kahan_sum_fin(kahan_sum);
}
int main(int argc, char **argv) {
int rank, size, dims[3];
MPI_Comm cart;
m::ini(&argc, &argv);
m::get_dims(&argc, &argv, dims);
m::get_cart(MPI_COMM_WORLD, dims, &cart);
main0();
MC(m::Comm_rank(cart, &rank));
MC(m::Comm_size(cart, &size));
msg_ini(rank);
MC(m::Barrier(cart));
m::fin();
}
#include <stdio.h>
#include <float.h>
#include <mpi.h>
#include "utils/mc.h"
#include "utils/msg.h"
#include "mpi/glb.h"
#include "mpi/wrapper.h"
#include "utils/mc.h"
#include "algo/key_list/imp.h"
void main0() {
KeyList *q, *p;
key_list_ini(&q);
key_list_push(q, "a");
key_list_push(q, "b c");
key_list_push(q, "d");
key_list_copy(q, /**/ &p);
msg_print("offset: %d", key_list_offset(q, "a"));
msg_print("offset: %d", key_list_offset(q, "b c"));
msg_print("offset: %d", key_list_offset(q, "d"));
msg_print("width: %d", key_list_width(q, "b c"));
msg_print("size: %d", key_list_size(q));
key_list_mark(q, "a");
key_list_mark(q, "b c");
key_list_mark(q, "d");
msg_print("marked: %d", key_list_marked(q));
key_list_log(q);
key_list_log(p);
key_list_fin(p);
key_list_fin(q);
}
int main(int argc, char **argv) {
int rank, size, dims[3];
MPI_Comm cart;
m::ini(&argc, &argv);
m::get_dims(&argc, &argv, dims);
m::get_cart(MPI_COMM_WORLD, dims, &cart);
main0();
MC(m::Comm_rank(cart, &rank));
MC(m::Comm_size(cart, &size));
msg_ini(rank);
MC(m::Barrier(cart));
m::fin();
}
#include <stdio.h>
#include <math.h>
#include <mpi.h>
#include <conf.h>
#include "inc/conf.h"
#include "mpi/glb.h"
#include "d/api.h"
#include "inc/dev.h"
#include "utils/cc.h"
#include "algo/scan/imp.h"
void set(int *a, int *n) {
int x, i;
i = 0;
while (scanf("%d", &x) == 1)
a[i++] = x;
*n = i;
}
#define M 9999
static Scan *w;
static int *x, *y;
static void dump0(int *hst, int n) {
int i;
for (i = 0; i < n; i++)
printf("%d\n", hst[i]);
}
static void dump(int *dev, int n) {
int hst[M];
cD2H(hst, dev, n);
dump0(hst, n);
}
static void scan0(int *hst, int n) { /* local scan wrapper */
scan_ini(n, &w);
cH2D(x, hst, n);
scan_apply(x, n, y, w);
scan_fin(w);
}
static void main0() {
int n, a[M];
set(a, &n); /* see set.cpp */
scan0(a, n);
dump(y, n);
}
static void main1() {
Dalloc(&x, M);
Dalloc(&y, M);
main0();
Dfree(x);
Dfree(y);
}
int main(int argc, char **argv) {
m::ini(&argc, &argv);
main1();
m::fin();
}
#include <mpi.h>
#include <stdio.h>
#include <string.h>
#include <conf.h>
#include "inc/conf.h"
#include "d/api.h"
#include "utils/msg.h"
#include "utils/error.h"
#include "utils/imp.h"
#include "utils/cc.h"
#include "utils/mc.h"
#include "mpi/glb.h"
#include "mpi/wrapper.h"
#include "inc/dev.h"
#include "inc/type.h"
#include "conf/imp.h"
#include "struct/partlist/type.h"
#include "clist/imp.h"
#include "pair/imp.h"
#include "coords/ini.h"
#include "coords/imp.h"
#include "struct/parray/imp.h"
#include "struct/farray/imp.h"
#include "flu/type.h"
#include "fluforces/imp.h"
#include "io/txt/imp.h"
static Particle *pp, *pp0, *pp_hst;
static Force *ff, *ff_hst;
static int n;
static Clist *clist;
static ClistMap *cmap;
static FluForcesBulk *bulkforces;
static void read_pp(const char *fname) {
TxtRead *tr;
long sz;
UC(txt_read_pp(fname, &tr));
n = txt_read_get_n(tr);
msg_print("have read %d particles", n);
sz = n + 32;
EMALLOC(sz, &pp_hst);
EMALLOC(sz, &ff_hst);
Dalloc(&pp, sz);
Dalloc(&pp0, sz);
Dalloc(&ff, sz);
memcpy(pp_hst, txt_read_get_pp(tr), sz * sizeof(Particle));
CC(d::Memcpy(pp, pp_hst, sz * sizeof(Particle), H2D));
CC(d::Memset(ff, 0, sz * sizeof(Force)));
UC(txt_read_fin(tr));
}
static void dealloc() {
Dfree(pp);
Dfree(pp0);
Dfree(ff);
EFREE(pp_hst);
EFREE(ff_hst);
n = 0;
}
static void build_clist() {
UC(clist_build(n, n, pp, /**/ pp0, clist, cmap));
Particle *tmp = pp;
pp = pp0;
pp0 = tmp;
}
static void set_params(const Config *cfg, float dt, PairParams *p) {
float kBT;
UC(conf_lookup_float(cfg, "glb.kBT", &kBT));
msg_print("kBT: %g", kBT);
UC(pair_set_conf(cfg, "flu", p));
UC(pair_compute_dpd_sigma(kBT, dt, /**/ p));
}
int main(int argc, char **argv) {
Config *cfg;
const char *fin, *fout;
PaArray parray;
FoArray farray;
Coords *coords;
int maxp;
int3 L;
PairParams *params;
float dt;
int rank, dims[3];
MPI_Comm cart;
m::ini(&argc, &argv);
m::get_dims(&argc, &argv, dims);
m::get_cart(MPI_COMM_WORLD, dims, &cart);
MC(m::Comm_rank(cart, &rank));
msg_ini(rank);
UC(conf_ini(&cfg));
UC(conf_read(argc, argv, cfg));
UC(coords_ini_conf(cart, cfg, &coords));
L = subdomain(coords);
UC(pair_ini(&params));
UC(conf_lookup_float(cfg, "time.dt", &dt));
UC(set_params(cfg, dt, params));
UC(conf_lookup_string(cfg, "in", &fin));
UC(conf_lookup_string(cfg, "out", &fout));
UC(read_pp(fin));
maxp = n + 32;
UC(clist_ini(L.x, L.y, L.z, &clist));
UC(clist_ini_map(maxp, 1, clist, &cmap));
UC(build_clist());
UC(fluforces_bulk_ini(L, maxp, &bulkforces));
parray_push_pp(pp, &parray);
farray_push_ff(ff, &farray);
UC(fluforces_bulk_prepare(n, &parray, /**/ bulkforces));
UC(fluforces_bulk_apply(params, n, bulkforces, clists_get_ss(clist), clists_get_cc(clist), /**/ &farray));
// particles are reordered because of clists
CC(d::Memcpy(pp_hst, pp, n*sizeof(Particle), D2H));
CC(d::Memcpy(ff_hst, ff, n*sizeof(Force) , D2H));
UC(txt_write_pp_ff(n, pp_hst, ff_hst, fout));
UC(fluforces_bulk_fin(bulkforces));
UC(clist_fin(clist));
UC(clist_fin_map(cmap));
UC(dealloc());
UC(pair_fin(params));
UC(coords_fin(coords));
UC(conf_fin(cfg));
MC(m::Barrier(cart));
m::fin();
}
#include <stdio.h>
#include <mpi.h>
#include <assert.h>
#include <conf.h>
#include "inc/conf.h"
#include "utils/msg.h"
#include "d/api.h"
#include "inc/dev.h"
#include "inc/type.h"
#include "utils/error.h"
#include "utils/imp.h"
#include "utils/cc.h"
#include "utils/mc.h"
#include "mpi/glb.h"
#include "mpi/wrapper.h"
#include "conf/imp.h"
#include "coords/ini.h"
#include "coords/imp.h"
#include "struct/partlist/type.h"
#include "algo/scan/imp.h"
#include "clist/imp.h"
enum {X,Y,Z};
#define MAXN 10000
void read(int *n, Particle *pp) {
int i;
Particle p;
i = 0;
while (scanf("%f %f %f %f %f %f",
&p.r[X], &p.r[Y], &p.r[Z],
&p.v[X], &p.v[Y], &p.v[Z]) == 6)
pp[i++] = p;
*n = i;
}
int num_parts_inside(int3 L, int n, const Particle *pp) {
enum {X, Y, Z};
int i, ni;
const float *r;
for (i = ni = 0; i < n; ++i) {
r = pp[i].r;
ni +=
(-L.x/2 <= r[X] && r[X] < L.x/2) &&
(-L.y/2 <= r[Y] && r[Y] < L.y/2) &&
(-L.z/2 <= r[Z] && r[Z] < L.z/2);
}
return ni;
}
void print_cells(int3 L, const int *ss, const int *cc) {
int i, n, s, c;
n = L.x * L.y * L.z;
for (i = 0; i < n; ++i) {
s = ss[i];
c = cc[i];
printf("%d\n%d\n", s, c);
}
}
int3 ccoords(int3 d, int cid) {
int3 c;
c.x = cid % d.x;
c.z = cid / (d.y * d.x);
c.y = (cid - d.y * d.x * c.z) / d.x;
return c;
}
bool valid(int c, int d, float x) {
return (x >= c - 0.5 * d) && (x < c + 1 - 0.5 * d);
}
bool valid_cell(int3 d, int cid, int s, int c, const Particle *pp) {
int i, j;
Particle p;
int3 cell = ccoords(d, cid);
for (i = 0; i < c; ++i) {
j = s + i;
p = pp[j];
// msg_print("%3f %3f %3f at %d %d %d",
// p.r[X], p.r[Y], p.r[Z], cell.x, cell.y, cell.z);
if ( ! valid(cell.x, d.x, p.r[X]) ||
! valid(cell.y, d.y, p.r[Y]) ||
! valid(cell.z, d.z, p.r[Z]) )
return false;
}
return true;
}
bool valid(int3 d, const int *starts, const int *counts, const Particle *pp, int n) {
int cid, s, c, nc;
nc = d.x * d.y * d.z;
for (cid = 0; cid < nc; ++cid) {
s = starts[cid];
c = counts[cid];
if (!valid_cell(d, cid, s, c, pp)) return false;
}
return true;
}
int main(int argc, char **argv) {
Particle *pp, *ppout;
Particle *pp_hst;
int n = 0, nout, *starts, *counts;
int3 L;
Clist *clist;
ClistMap *m;
Config *cfg;
Coords *coords;
int rank, dims[3];
MPI_Comm cart;
m::ini(&argc, &argv);
m::get_dims(&argc, &argv, dims);
m::get_cart(MPI_COMM_WORLD, dims, &cart);
MC(m::Comm_rank(cart, &rank));
msg_ini(rank);
UC(conf_ini(&cfg));
UC(conf_read(argc, argv, cfg));
UC(coords_ini_conf(cart, cfg, &coords));
L = subdomain(coords);
UC(clist_ini(L.x, L.y, L.z, /**/ &clist));
EMALLOC(MAXN, &pp_hst);
EMALLOC(clists_get_n(clist), &counts);
EMALLOC(clists_get_n(clist), &starts);
Dalloc(&pp, MAXN);
Dalloc(&ppout, MAXN);
read(&n, pp_hst);
nout = num_parts_inside(L, n, pp_hst);
UC(clist_ini_map(n, 1, clist, /**/ &m));
CC(d::Memcpy(pp, pp_hst, n * sizeof(Particle), H2D));
UC(clist_build(n, nout, pp, /**/ ppout, clist, m));
CC(d::Memcpy(counts, clists_get_cc(clist), clists_get_n(clist) * sizeof(int), D2H));
CC(d::Memcpy(starts, clists_get_ss(clist), clists_get_n(clist) * sizeof(int), D2H));
CC(d::Memcpy(pp_hst, ppout, nout * sizeof(Particle), D2H));
if (valid(L, starts, counts, pp_hst, nout))
printf("0\n");
else
printf("1\n");
print_cells(L, starts, counts);
Dfree(pp);
Dfree(ppout);
EFREE(counts);
EFREE(starts);
EFREE(pp_hst);
UC(clist_fin(/**/ clist));
UC(clist_fin_map(/**/ m));
UC(conf_fin(cfg));
UC(coords_fin(coords));
MC(m::Barrier(cart));
m::fin();
}
#include <stdio.h>
#include <assert.h>
#include <mpi.h>
#include <vector_types.h>
#include <conf.h>
#include "inc/conf.h"
#include "utils/msg.h"
#include "utils/mc.h"
#include "mpi/glb.h"
#include "mpi/wrapper.h"
#include "conf/imp.h"
#include "coords/ini.h"
#include "coords/imp.h"
#include "utils/error.h"
#include "frag/imp.h"
#include "comm/imp.h"
/* generate a unique sequence given a unique val */
void fill_bag(int val, int sz, int *ii) {
for (int i = 0; i < sz; ++i) ii[i] = -2*val + val*val;
}
void fill_bags(hBags *b) {
int c, i;
for (i = 0; i < 26; ++i) {
c = i;
fill_bag(i, c, (int*) b->data[i]);
b->counts[i] = c;
}
}
void comp(const int *aa, const int *bb, int n) {