[yt-svn] commit/yt: 8 new changesets

Bitbucket commits-noreply at bitbucket.org
Fri Mar 16 07:51:08 PDT 2012


8 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/ee67b630886d/
changeset:   ee67b630886d
branch:      yt
user:        MatthewTurk
date:        2011-11-29 16:51:53
summary:     Initial import of old rockstar interface
affected #:  3 files

diff -r a519b8754ba86d786f6ed525584101183e86c6cc -r ee67b630886da98e781cabe94430d81fa400d9e2 yt/analysis_modules/halo_finding/rockstar/rockstar.py
--- /dev/null
+++ b/yt/analysis_modules/halo_finding/rockstar/rockstar.py
@@ -0,0 +1,133 @@
+"""
+Operations to get Rockstar loaded up
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: Columbia University
+Homepage: http://yt.enzotools.org/
+License:
+  Copyright (C) 2011 Matthew Turk.  All Rights Reserved.
+
+  This file is part of yt.
+
+  yt is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+"""
+
+from yt.config import ytcfg
+ytcfg["yt","loglevel"] = "50"
+from yt.mods import *
+from os import environ
+environ['CFLAGS'] = "-I. -Iio/ -Iutil/ -I"+na.get_include()
+environ['LDFLAGS'] = "-L. -lrockstar"
+from yt.utilities.parallel_tools.parallel_analysis_interface import \
+    ParallelAnalysisInterface, ProcessorPool, Communicator
+
+import pyximport; pyximport.install()
+import rockstar_interface
+import argparse
+import socket
+import time
+
+class DomainDecomposer(ParallelAnalysisInterface):
+    def __init__(self, pf, comm):
+        ParallelAnalysisInterface.__init__(self, comm=comm)
+        self.pf = pf
+        self.hierarchy = pf.h
+        self.center = (pf.domain_left_edge + pf.domain_right_edge)/2.0
+
+    def decompose(self):
+        dd = self.pf.h.all_data()
+        check, LE, RE, data_source = self.partition_hierarchy_3d(dd)
+        return data_source
+
+class RockstarHaloFinder(ParallelAnalysisInterface):
+    def __init__(self, pf, num_readers = 0, num_writers = 0):
+        ParallelAnalysisInterface.__init__(self)
+        # No subvolume support
+        self.pf = pf
+        self.hierarchy = pf.h
+        self.num_readers = num_readers
+        self.num_writers = num_writers
+        if self.num_readers + self.num_writers + 1 != self.comm.size:
+            raise RuntimeError
+        self.center = (pf.domain_right_edge + pf.domain_left_edge)/2.0
+        data_source = None
+        if self.comm.size > 1:
+            self.pool = ProcessorPool()
+            self.pool.add_workgroup(1, name = "server")
+            self.pool.add_workgroup(num_readers, name = "readers")
+            self.pool.add_workgroup(num_writers, name = "writers")
+            for wg in self.pool.workgroups:
+                if self.comm.rank in wg.ranks: self.workgroup = wg
+            if self.workgroup.name == "readers":
+                comm = Communicator(self.workgroup.comm)
+                dd = DomainDecomposer(self.pf, comm)
+                data_source = dd.decompose()
+        else:
+            data_source = self.pf.h.all_data()
+        self.handler = rockstar_interface.RockstarInterface(
+                self.pf, data_source)
+
+    def _get_hosts(self):
+        if self.comm.size == 1 or self.workgroup.name == "server":
+            server_address = socket.gethostname()
+            sock = socket.socket()
+            sock.bind(('', 0))
+            port = sock.getsockname()[-1]
+            del sock
+        else:
+            server_address, port = None, None
+        self.server_address, self.port = self.comm.mpi_bcast_pickled(
+            (server_address, port))
+        self.port = str(self.port)
+
+    def run(self):
+        self._get_hosts()
+        if self.comm.size > 1 and self.workgroup.name == "writers":
+            sock = socket.socket()
+            sock.bind(('', 0))
+            port = sock.getsockname()[-1]
+            del sock
+        else:
+            port = -1
+        self.handler.setup_rockstar(self.server_address, self.port,
+                    parallel = self.comm.size > 1,
+                    num_readers = self.num_readers,
+                    num_writers = self.num_writers,
+                    writing_port = port)
+        if self.comm.size == 1:
+            self.handler.call_rockstar()
+        else:
+            self.comm.barrier()
+            if self.workgroup.name == "server":
+                self.handler.start_server()
+            elif self.workgroup.name == "readers":
+                time.sleep(0.5)
+                self.handler.start_client()
+            elif self.workgroup.name == "writers":
+                time.sleep(1.0)# + self.workgroup.comm.rank/10.0)
+                self.handler.start_client()
+        self.comm.barrier()
+
+if __name__ == "__main__":
+    pf = load("/home/mturk/Research/data/DD0252/DD0252")
+    #pf = load("/home/mturk/Research/data/DD0023/DD0023")
+    nr = int(sys.argv[-2])
+    nw = int(sys.argv[-1])
+    print nr, nw
+    pf.h
+    rh = RockstarHaloFinder(pf, num_readers = nr, num_writers = nw)
+    t1 = time.time()
+    rh.run()
+    t2 = time.time()
+    print "Total runtime: %0.3e" % (t2-t1)


diff -r a519b8754ba86d786f6ed525584101183e86c6cc -r ee67b630886da98e781cabe94430d81fa400d9e2 yt/analysis_modules/halo_finding/rockstar/rockstar_interface.pyx
--- /dev/null
+++ b/yt/analysis_modules/halo_finding/rockstar/rockstar_interface.pyx
@@ -0,0 +1,335 @@
+"""
+Particle operations for Lagrangian Volume
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: Columbia University
+Homepage: http://yt.enzotools.org/
+License:
+  Copyright (C) 2011 Matthew Turk.  All Rights Reserved.
+
+  This file is part of yt.
+
+  yt is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+"""
+
+import numpy as np
+import os, sys
+cimport numpy as np
+cimport cython
+from stdlib cimport malloc
+
+cdef import from "particle.h":
+    struct particle:
+        np.int64_t id
+        float pos[6]
+
+cdef import from "io_generic.h":
+    ctypedef void (*LPG) (char *filename, particle **p, np.int64_t *num_p)
+    void set_load_particles_generic(LPG func)
+
+cdef import from "rockstar.h":
+    void rockstar(float *bounds, np.int64_t manual_subs)
+
+cdef import from "config.h":
+    void setup_config()
+
+cdef import from "server.h":
+    int server()
+
+cdef import from "client.h":
+    void client()
+
+cdef import from "meta_io.h":
+    void read_particles(char *filename)
+    void output_and_free_halos(np.int64_t id_offset, np.int64_t snap, 
+			   np.int64_t chunk, float *bounds)
+
+cdef import from "config_vars.h":
+    # Rockstar cleverly puts all of the config variables inside a templated
+    # definition of their vaiables.
+    char *FILE_FORMAT
+    np.float64_t PARTICLE_MASS
+
+    char *MASS_DEFINITION
+    np.int64_t MIN_HALO_OUTPUT_SIZE
+    np.float64_t FORCE_RES
+
+    np.float64_t SCALE_NOW
+    np.float64_t h0
+    np.float64_t Ol
+    np.float64_t Om
+
+    np.int64_t GADGET_ID_BYTES
+    np.float64_t GADGET_MASS_CONVERSION
+    np.float64_t GADGET_LENGTH_CONVERSION
+    np.int64_t GADGET_SKIP_NON_HALO_PARTICLES
+    np.int64_t RESCALE_PARTICLE_MASS
+
+    np.int64_t PARALLEL_IO
+    char *PARALLEL_IO_SERVER_ADDRESS
+    char *PARALLEL_IO_SERVER_PORT
+    np.int64_t PARALLEL_IO_WRITER_PORT
+    char *PARALLEL_IO_SERVER_INTERFACE
+    char *RUN_ON_SUCCESS
+
+    char *INBASE
+    char *FILENAME
+    np.int64_t STARTING_SNAP
+    np.int64_t NUM_SNAPS
+    np.int64_t NUM_BLOCKS
+    np.int64_t NUM_READERS
+    np.int64_t PRELOAD_PARTICLES
+    char *SNAPSHOT_NAMES
+    char *LIGHTCONE_ALT_SNAPS
+    char *BLOCK_NAMES
+
+    char *OUTBASE
+    np.float64_t OVERLAP_LENGTH
+    np.int64_t NUM_WRITERS
+    np.int64_t FORK_READERS_FROM_WRITERS
+    np.int64_t FORK_PROCESSORS_PER_MACHINE
+
+    char *OUTPUT_FORMAT
+    np.int64_t DELETE_BINARY_OUTPUT_AFTER_FINISHED
+    np.int64_t FULL_PARTICLE_CHUNKS
+    char *BGC2_SNAPNAMES
+
+    np.int64_t BOUND_PROPS
+    np.int64_t BOUND_OUT_TO_HALO_EDGE
+    np.int64_t DO_MERGER_TREE_ONLY
+    np.int64_t IGNORE_PARTICLE_IDS
+    np.float64_t TRIM_OVERLAP
+    np.float64_t ROUND_AFTER_TRIM
+    np.int64_t LIGHTCONE
+    np.int64_t PERIODIC
+
+    np.float64_t LIGHTCONE_ORIGIN[3]
+    np.float64_t LIGHTCONE_ALT_ORIGIN[3]
+
+    np.float64_t LIMIT_CENTER[3]
+    np.float64_t LIMIT_RADIUS
+
+    np.int64_t SWAP_ENDIANNESS
+    np.int64_t GADGET_VARIANT
+
+    np.float64_t FOF_FRACTION
+    np.float64_t FOF_LINKING_LENGTH
+    np.float64_t INCLUDE_HOST_POTENTIAL_RATIO
+    np.float64_t DOUBLE_COUNT_SUBHALO_MASS_RATIO
+    np.int64_t TEMPORAL_HALO_FINDING
+    np.int64_t MIN_HALO_PARTICLES
+    np.float64_t UNBOUND_THRESHOLD
+    np.int64_t ALT_NFW_METRIC
+
+    np.int64_t TOTAL_PARTICLES
+    np.float64_t BOX_SIZE
+    np.int64_t OUTPUT_HMAD
+    np.int64_t OUTPUT_PARTICLES
+    np.int64_t OUTPUT_LEVELS
+    np.float64_t DUMP_PARTICLES[3]
+
+    np.float64_t AVG_PARTICLE_SPACING
+    np.int64_t SINGLE_SNAP
+
+def print_rockstar_settings():
+    # We have to do the config
+    print "FILE_FORMAT =", FILE_FORMAT
+    print "PARTICLE_MASS =", PARTICLE_MASS
+
+    print "MASS_DEFINITION =", MASS_DEFINITION
+    print "MIN_HALO_OUTPUT_SIZE =", MIN_HALO_OUTPUT_SIZE
+    print "FORCE_RES =", FORCE_RES
+
+    print "SCALE_NOW =", SCALE_NOW
+    print "h0 =", h0
+    print "Ol =", Ol
+    print "Om =", Om
+
+    print "GADGET_ID_BYTES =", GADGET_ID_BYTES
+    print "GADGET_MASS_CONVERSION =", GADGET_MASS_CONVERSION
+    print "GADGET_LENGTH_CONVERSION =", GADGET_LENGTH_CONVERSION
+    print "GADGET_SKIP_NON_HALO_PARTICLES =", GADGET_SKIP_NON_HALO_PARTICLES
+    print "RESCALE_PARTICLE_MASS =", RESCALE_PARTICLE_MASS
+
+    print "PARALLEL_IO =", PARALLEL_IO
+    print "PARALLEL_IO_SERVER_ADDRESS =", PARALLEL_IO_SERVER_ADDRESS
+    print "PARALLEL_IO_SERVER_PORT =", PARALLEL_IO_SERVER_PORT
+    print "PARALLEL_IO_WRITER_PORT =", PARALLEL_IO_WRITER_PORT
+    print "PARALLEL_IO_SERVER_INTERFACE =", PARALLEL_IO_SERVER_INTERFACE
+    print "RUN_ON_SUCCESS =", RUN_ON_SUCCESS
+
+    print "INBASE =", INBASE
+    print "FILENAME =", FILENAME
+    print "STARTING_SNAP =", STARTING_SNAP
+    print "NUM_SNAPS =", NUM_SNAPS
+    print "NUM_BLOCKS =", NUM_BLOCKS
+    print "NUM_READERS =", NUM_READERS
+    print "PRELOAD_PARTICLES =", PRELOAD_PARTICLES
+    print "SNAPSHOT_NAMES =", SNAPSHOT_NAMES
+    print "LIGHTCONE_ALT_SNAPS =", LIGHTCONE_ALT_SNAPS
+    print "BLOCK_NAMES =", BLOCK_NAMES
+
+    print "OUTBASE =", OUTBASE
+    print "OVERLAP_LENGTH =", OVERLAP_LENGTH
+    print "NUM_WRITERS =", NUM_WRITERS
+    print "FORK_READERS_FROM_WRITERS =", FORK_READERS_FROM_WRITERS
+    print "FORK_PROCESSORS_PER_MACHINE =", FORK_PROCESSORS_PER_MACHINE
+
+    print "OUTPUT_FORMAT =", OUTPUT_FORMAT
+    print "DELETE_BINARY_OUTPUT_AFTER_FINISHED =", DELETE_BINARY_OUTPUT_AFTER_FINISHED
+    print "FULL_PARTICLE_CHUNKS =", FULL_PARTICLE_CHUNKS
+    print "BGC2_SNAPNAMES =", BGC2_SNAPNAMES
+
+    print "BOUND_PROPS =", BOUND_PROPS
+    print "BOUND_OUT_TO_HALO_EDGE =", BOUND_OUT_TO_HALO_EDGE
+    print "DO_MERGER_TREE_ONLY =", DO_MERGER_TREE_ONLY
+    print "IGNORE_PARTICLE_IDS =", IGNORE_PARTICLE_IDS
+    print "TRIM_OVERLAP =", TRIM_OVERLAP
+    print "ROUND_AFTER_TRIM =", ROUND_AFTER_TRIM
+    print "LIGHTCONE =", LIGHTCONE
+    print "PERIODIC =", PERIODIC
+
+    print "LIGHTCONE_ORIGIN =", LIGHTCONE_ORIGIN[0]
+    print "LIGHTCONE_ORIGIN[1] =", LIGHTCONE_ORIGIN[1]
+    print "LIGHTCONE_ORIGIN[2] =", LIGHTCONE_ORIGIN[2]
+    print "LIGHTCONE_ALT_ORIGIN =", LIGHTCONE_ALT_ORIGIN[0]
+    print "LIGHTCONE_ALT_ORIGIN[1] =", LIGHTCONE_ALT_ORIGIN[1]
+    print "LIGHTCONE_ALT_ORIGIN[2] =", LIGHTCONE_ALT_ORIGIN[2]
+
+    print "LIMIT_CENTER =", LIMIT_CENTER[0]
+    print "LIMIT_CENTER[1] =", LIMIT_CENTER[1]
+    print "LIMIT_CENTER[2] =", LIMIT_CENTER[2]
+    print "LIMIT_RADIUS =", LIMIT_RADIUS
+
+    print "SWAP_ENDIANNESS =", SWAP_ENDIANNESS
+    print "GADGET_VARIANT =", GADGET_VARIANT
+
+    print "FOF_FRACTION =", FOF_FRACTION
+    print "FOF_LINKING_LENGTH =", FOF_LINKING_LENGTH
+    print "INCLUDE_HOST_POTENTIAL_RATIO =", INCLUDE_HOST_POTENTIAL_RATIO
+    print "DOUBLE_COUNT_SUBHALO_MASS_RATIO =", DOUBLE_COUNT_SUBHALO_MASS_RATIO
+    print "TEMPORAL_HALO_FINDING =", TEMPORAL_HALO_FINDING
+    print "MIN_HALO_PARTICLES =", MIN_HALO_PARTICLES
+    print "UNBOUND_THRESHOLD =", UNBOUND_THRESHOLD
+    print "ALT_NFW_METRIC =", ALT_NFW_METRIC
+
+    print "TOTAL_PARTICLES =", TOTAL_PARTICLES
+    print "BOX_SIZE =", BOX_SIZE
+    print "OUTPUT_HMAD =", OUTPUT_HMAD
+    print "OUTPUT_PARTICLES =", OUTPUT_PARTICLES
+    print "OUTPUT_LEVELS =", OUTPUT_LEVELS
+    print "DUMP_PARTICLES =", DUMP_PARTICLES[0]
+    print "DUMP_PARTICLES[1] =", DUMP_PARTICLES[1]
+    print "DUMP_PARTICLES[2] =", DUMP_PARTICLES[2]
+
+    print "AVG_PARTICLE_SPACING =", AVG_PARTICLE_SPACING
+    print "SINGLE_SNAP =", SINGLE_SNAP
+
+cdef class RockstarInterface
+
+cdef RockstarInterface rh
+cdef void rh_read_particles(char *filename, particle **p, np.int64_t *num_p):
+    cdef int i, fi
+    cdef np.float64_t conv[6], left_edge[6]
+    dd = rh.data_source
+    cdef np.ndarray[np.int64_t, ndim=1] arri
+    cdef np.ndarray[np.float64_t, ndim=1] arr
+    arri = dd["particle_index"].astype("int64")
+    del dd["particle_index"]
+    cdef int np = arri.shape[0]
+    p[0] = <particle *> malloc(sizeof(particle) * np)
+    print "Loading indices: size = ", np
+    for i in range(np):
+        p[0][i].id = arri[i]
+    fi = 0
+    conv[0] = conv[1] = conv[2] = rh.pf["mpch"]
+    conv[3] = conv[4] = conv[5] = 1e-5
+    left_edge[0] = rh.pf.domain_left_edge[0]
+    left_edge[1] = rh.pf.domain_left_edge[1]
+    left_edge[2] = rh.pf.domain_left_edge[2]
+    left_edge[0] = left_edge[1] = left_edge[2] = 0.0
+    for field in ["particle_position_x", "particle_position_y",
+                  "particle_position_z",
+                  "particle_velocity_x", "particle_velocity_y",
+                  "particle_velocity_z"]:
+        arr = dd[field].astype("float64")
+        del dd[field]
+        for i in range(np):
+            p[0][i].pos[fi] = (arr[i]-left_edge[fi])*conv[fi]
+        fi += 1
+    num_p[0] = np
+
+cdef class RockstarInterface:
+
+    cdef public object pf
+    cdef public object data_source
+    cdef int rank
+    cdef int size
+
+    def __cinit__(self, pf, data_source):
+        self.pf = pf
+        self.data_source = data_source
+
+    def setup_rockstar(self, char *server_address, char *server_port,
+                       np.float64_t particle_mass = -1.0,
+                       int parallel = False, int num_readers = 1,
+                       int num_writers = 1,
+                       int writing_port = -1):
+        global PARALLEL_IO, PARALLEL_IO_SERVER_ADDRESS, PARALLEL_IO_SERVER_PORT
+        global FILENAME, FILE_FORMAT, NUM_SNAPS, STARTING_SNAP, h0, Ol, Om
+        global BOX_SIZE, PERIODIC, PARTICLE_MASS, NUM_BLOCKS, NUM_READERS
+        global FORK_READERS_FROM_WRITERS, PARALLEL_IO_WRITER_PORT, NUM_WRITERS
+        global rh
+        if parallel:
+            PARALLEL_IO = 1
+            PARALLEL_IO_SERVER_ADDRESS = server_address
+            PARALLEL_IO_SERVER_PORT = server_port
+            if writing_port > 0:
+                PARALLEL_IO_WRITER_PORT = writing_port
+        else:
+            PARALLEL_IO = 0
+            PARALLEL_IO_SERVER_ADDRESS = server_address
+            PARALLEL_IO_SERVER_PORT = server_port
+        FILENAME = "inline.<block>"
+        FILE_FORMAT = "GENERIC"
+        NUM_SNAPS = 1
+        NUM_READERS = NUM_BLOCKS = num_readers
+        NUM_WRITERS = num_writers
+
+        h0 = self.pf.hubble_constant
+        Ol = self.pf.omega_lambda
+        Om = self.pf.omega_matter
+
+        if particle_mass < 0:
+            print "Assuming single-mass particle."
+            particle_mass = self.pf.h.grids[0]["ParticleMassMsun"][0] * h0
+        PARTICLE_MASS = particle_mass
+        PERIODIC = 1
+        BOX_SIZE = (self.pf.domain_right_edge[0] -
+                    self.pf.domain_left_edge[0]) * self.pf['mpch']
+        setup_config()
+        rh = self
+        cdef LPG func = rh_read_particles
+        set_load_particles_generic(func)
+
+    def call_rockstar(self):
+        read_particles("generic")
+        rockstar(NULL, 0)
+        output_and_free_halos(0, 0, 0, NULL)
+
+    def start_server(self):
+        server()
+
+    def start_client(self):
+        client()


diff -r a519b8754ba86d786f6ed525584101183e86c6cc -r ee67b630886da98e781cabe94430d81fa400d9e2 yt/analysis_modules/halo_finding/setup.py
--- a/yt/analysis_modules/halo_finding/setup.py
+++ b/yt/analysis_modules/halo_finding/setup.py
@@ -10,6 +10,8 @@
     config.add_subpackage("fof")
     config.add_subpackage("hop")
     config.add_subpackage("parallel_hop")
+    if "ROCKSTAR_DIR" in os.environ:
+        config.add_subpackage("rockstar")
     config.make_config_py() # installs __config__.py
     #config.make_svn_version_py()
     return config



https://bitbucket.org/yt_analysis/yt/changeset/8b1f498aca99/
changeset:   8b1f498aca99
branch:      yt
user:        MatthewTurk
date:        2011-11-29 17:01:56
summary:     Adding rockstar into a setup.py system
affected #:  4 files



diff -r ee67b630886da98e781cabe94430d81fa400d9e2 -r 8b1f498aca9939eea0f988db56a2ba0be596986d yt/analysis_modules/halo_finding/rockstar/api.py
--- /dev/null
+++ b/yt/analysis_modules/halo_finding/rockstar/api.py
@@ -0,0 +1,27 @@
+"""
+API for Rockstar halo finding
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: Columbia
+Homepage: http://yt-project.org/
+License:
+  Copyright (C) 2011 Matthew Turk.  All Rights Reserved.
+
+  This file is part of yt.
+
+  yt is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+"""
+
+from .rockstar import RockstarHaloFinder


diff -r ee67b630886da98e781cabe94430d81fa400d9e2 -r 8b1f498aca9939eea0f988db56a2ba0be596986d yt/analysis_modules/halo_finding/rockstar/rockstar.py
--- a/yt/analysis_modules/halo_finding/rockstar/rockstar.py
+++ b/yt/analysis_modules/halo_finding/rockstar/rockstar.py
@@ -23,16 +23,11 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
-from yt.config import ytcfg
-ytcfg["yt","loglevel"] = "50"
 from yt.mods import *
 from os import environ
-environ['CFLAGS'] = "-I. -Iio/ -Iutil/ -I"+na.get_include()
-environ['LDFLAGS'] = "-L. -lrockstar"
 from yt.utilities.parallel_tools.parallel_analysis_interface import \
     ParallelAnalysisInterface, ProcessorPool, Communicator
 
-import pyximport; pyximport.install()
 import rockstar_interface
 import argparse
 import socket
@@ -118,16 +113,3 @@
                 time.sleep(1.0)# + self.workgroup.comm.rank/10.0)
                 self.handler.start_client()
         self.comm.barrier()
-
-if __name__ == "__main__":
-    pf = load("/home/mturk/Research/data/DD0252/DD0252")
-    #pf = load("/home/mturk/Research/data/DD0023/DD0023")
-    nr = int(sys.argv[-2])
-    nw = int(sys.argv[-1])
-    print nr, nw
-    pf.h
-    rh = RockstarHaloFinder(pf, num_readers = nr, num_writers = nw)
-    t1 = time.time()
-    rh.run()
-    t2 = time.time()
-    print "Total runtime: %0.3e" % (t2-t1)


diff -r ee67b630886da98e781cabe94430d81fa400d9e2 -r 8b1f498aca9939eea0f988db56a2ba0be596986d yt/analysis_modules/halo_finding/rockstar/setup.py
--- /dev/null
+++ b/yt/analysis_modules/halo_finding/rockstar/setup.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+import setuptools
+import os, sys, os.path
+
+import os.path
+
+def configuration(parent_package='',top_path=None):
+    from numpy.distutils.misc_util import Configuration
+    config = Configuration('rockstar',parent_package,top_path)
+    config.make_config_py() # installs __config__.py
+    #config.make_svn_version_py()
+    rd = os.environ["ROCKSTAR_DIR"]
+    config.add_extension("rockstar_interface",
+                         "yt/analysis_modules/halo_finding/rockstar/rockstar_interface.pyx",
+                         library_dirs=[rd],
+                         libraries=["rockstar"],
+                         include_dirs=[rd,
+                                       os.path.join(rd, "io"),
+                                       os.path.join(rd, "util")])
+    return config
+



https://bitbucket.org/yt_analysis/yt/changeset/7b2a6aa6ab1f/
changeset:   7b2a6aa6ab1f
branch:      yt
user:        MatthewTurk
date:        2011-11-29 20:00:07
summary:     Adding a "block_ratio" argument to the rockstar interface, to subdivide a given
reader even further.  Additionally, no more spatial decomposition: instead, now
do everything non-spatially, and assume it will be properly distributed in rock
star itself.
affected #:  2 files

diff -r 8b1f498aca9939eea0f988db56a2ba0be596986d -r 7b2a6aa6ab1f0fd020490c0eb9e21339606f6e91 yt/analysis_modules/halo_finding/rockstar/rockstar.py
--- a/yt/analysis_modules/halo_finding/rockstar/rockstar.py
+++ b/yt/analysis_modules/halo_finding/rockstar/rockstar.py
@@ -29,7 +29,6 @@
     ParallelAnalysisInterface, ProcessorPool, Communicator
 
 import rockstar_interface
-import argparse
 import socket
 import time
 
@@ -66,10 +65,7 @@
                 if self.comm.rank in wg.ranks: self.workgroup = wg
             if self.workgroup.name == "readers":
                 comm = Communicator(self.workgroup.comm)
-                dd = DomainDecomposer(self.pf, comm)
-                data_source = dd.decompose()
-        else:
-            data_source = self.pf.h.all_data()
+        data_source = self.pf.h.all_data()
         self.handler = rockstar_interface.RockstarInterface(
                 self.pf, data_source)
 


diff -r 8b1f498aca9939eea0f988db56a2ba0be596986d -r 7b2a6aa6ab1f0fd020490c0eb9e21339606f6e91 yt/analysis_modules/halo_finding/rockstar/rockstar_interface.pyx
--- a/yt/analysis_modules/halo_finding/rockstar/rockstar_interface.pyx
+++ b/yt/analysis_modules/halo_finding/rockstar/rockstar_interface.pyx
@@ -240,35 +240,46 @@
 
 cdef RockstarInterface rh
 cdef void rh_read_particles(char *filename, particle **p, np.int64_t *num_p):
-    cdef int i, fi
+    cdef int i, fi, npart, tnpart
     cdef np.float64_t conv[6], left_edge[6]
     dd = rh.data_source
     cdef np.ndarray[np.int64_t, ndim=1] arri
     cdef np.ndarray[np.float64_t, ndim=1] arr
-    arri = dd["particle_index"].astype("int64")
-    del dd["particle_index"]
-    cdef int np = arri.shape[0]
-    p[0] = <particle *> malloc(sizeof(particle) * np)
-    print "Loading indices: size = ", np
-    for i in range(np):
-        p[0][i].id = arri[i]
-    fi = 0
+    block = int(str(filename).rsplit(".")[-1])
+
+    # Now we want to grab data from only a subset of the grids.
+    n = rh.block_ratio
+    grid_chunks = [dd._grids[i:i+n] for i in range(0, len(dd._grids), n)]
+    grids = grid_chunks[block]
+    tnpart = 0
+    for g in grids:
+        tnpart += dd._get_data_from_grid(g, "particle_index").size
+    p[0] = <particle *> malloc(sizeof(particle) * tnpart)
+    #print "Loading indices: size = ", tnpart
     conv[0] = conv[1] = conv[2] = rh.pf["mpch"]
     conv[3] = conv[4] = conv[5] = 1e-5
     left_edge[0] = rh.pf.domain_left_edge[0]
     left_edge[1] = rh.pf.domain_left_edge[1]
     left_edge[2] = rh.pf.domain_left_edge[2]
     left_edge[0] = left_edge[1] = left_edge[2] = 0.0
-    for field in ["particle_position_x", "particle_position_y",
-                  "particle_position_z",
-                  "particle_velocity_x", "particle_velocity_y",
-                  "particle_velocity_z"]:
-        arr = dd[field].astype("float64")
-        del dd[field]
-        for i in range(np):
-            p[0][i].pos[fi] = (arr[i]-left_edge[fi])*conv[fi]
-        fi += 1
-    num_p[0] = np
+    pi = 0
+    for g in grids:
+        arri = dd._get_data_from_grid(g, "particle_index").astype("int64")
+        npart = arri.size
+        for i in range(npart):
+            p[0][i+pi].id = arri[i]
+        fi = 0
+        for field in ["particle_position_x", "particle_position_y",
+                      "particle_position_z",
+                      "particle_velocity_x", "particle_velocity_y",
+                      "particle_velocity_z"]:
+            arr = dd._get_data_from_grid(g, field).astype("float64")
+            for i in range(npart):
+                p[0][i+pi].pos[fi] = (arr[i]-left_edge[fi])*conv[fi]
+            fi += 1
+        pi += npart
+    num_p[0] = tnpart
+    assert(pi == tnpart)
 
 cdef class RockstarInterface:
 
@@ -276,6 +287,7 @@
     cdef public object data_source
     cdef int rank
     cdef int size
+    cdef int block_ratio
 
     def __cinit__(self, pf, data_source):
         self.pf = pf
@@ -285,7 +297,7 @@
                        np.float64_t particle_mass = -1.0,
                        int parallel = False, int num_readers = 1,
                        int num_writers = 1,
-                       int writing_port = -1):
+                       int writing_port = -1, int block_ratio = 10):
         global PARALLEL_IO, PARALLEL_IO_SERVER_ADDRESS, PARALLEL_IO_SERVER_PORT
         global FILENAME, FILE_FORMAT, NUM_SNAPS, STARTING_SNAP, h0, Ol, Om
         global BOX_SIZE, PERIODIC, PARTICLE_MASS, NUM_BLOCKS, NUM_READERS
@@ -304,8 +316,10 @@
         FILENAME = "inline.<block>"
         FILE_FORMAT = "GENERIC"
         NUM_SNAPS = 1
-        NUM_READERS = NUM_BLOCKS = num_readers
+        NUM_READERS = num_readers
+        NUM_BLOCKS = num_readers * block_ratio
         NUM_WRITERS = num_writers
+        self.block_ratio = block_ratio
 
         h0 = self.pf.hubble_constant
         Ol = self.pf.omega_lambda



https://bitbucket.org/yt_analysis/yt/changeset/43ab264e153e/
changeset:   43ab264e153e
branch:      yt
user:        MatthewTurk
date:        2011-11-29 21:57:48
summary:     Fix block ratio to *actually* work in any circumstance, ever.  Before it was
completely broken.  Fix a couple units issues.
affected #:  2 files

diff -r 7b2a6aa6ab1f0fd020490c0eb9e21339606f6e91 -r 43ab264e153e13162346a9ac2b8acb14c9e562eb yt/analysis_modules/halo_finding/rockstar/rockstar.py
--- a/yt/analysis_modules/halo_finding/rockstar/rockstar.py
+++ b/yt/analysis_modules/halo_finding/rockstar/rockstar.py
@@ -82,7 +82,7 @@
             (server_address, port))
         self.port = str(self.port)
 
-    def run(self):
+    def run(self, block_ratio = 1):
         self._get_hosts()
         if self.comm.size > 1 and self.workgroup.name == "writers":
             sock = socket.socket()
@@ -95,7 +95,8 @@
                     parallel = self.comm.size > 1,
                     num_readers = self.num_readers,
                     num_writers = self.num_writers,
-                    writing_port = port)
+                    writing_port = port,
+                    block_ratio = block_ratio)
         if self.comm.size == 1:
             self.handler.call_rockstar()
         else:


diff -r 7b2a6aa6ab1f0fd020490c0eb9e21339606f6e91 -r 43ab264e153e13162346a9ac2b8acb14c9e562eb yt/analysis_modules/halo_finding/rockstar/rockstar_interface.pyx
--- a/yt/analysis_modules/halo_finding/rockstar/rockstar_interface.pyx
+++ b/yt/analysis_modules/halo_finding/rockstar/rockstar_interface.pyx
@@ -249,19 +249,18 @@
 
     # Now we want to grab data from only a subset of the grids.
     n = rh.block_ratio
-    grid_chunks = [dd._grids[i:i+n] for i in range(0, len(dd._grids), n)]
-    grids = grid_chunks[block]
+    grids = np.array_split(dd._grids, NUM_BLOCKS)[block]
     tnpart = 0
     for g in grids:
         tnpart += dd._get_data_from_grid(g, "particle_index").size
     p[0] = <particle *> malloc(sizeof(particle) * tnpart)
     #print "Loading indices: size = ", tnpart
-    conv[0] = conv[1] = conv[2] = rh.pf["mpch"]
+    conv[0] = conv[1] = conv[2] = rh.pf["mpchcm"]
     conv[3] = conv[4] = conv[5] = 1e-5
     left_edge[0] = rh.pf.domain_left_edge[0]
     left_edge[1] = rh.pf.domain_left_edge[1]
     left_edge[2] = rh.pf.domain_left_edge[2]
-    left_edge[0] = left_edge[1] = left_edge[2] = 0.0
+    left_edge[3] = left_edge[4] = left_edge[5] = 0.0
     pi = 0
     for g in grids:
         arri = dd._get_data_from_grid(g, "particle_index").astype("int64")
@@ -279,7 +278,7 @@
             fi += 1
         pi += npart
     num_p[0] = tnpart
-    assert(pi == tnpart)
+    print "TOTAL", block, tnpart, len(grids)
 
 cdef class RockstarInterface:
 
@@ -297,7 +296,7 @@
                        np.float64_t particle_mass = -1.0,
                        int parallel = False, int num_readers = 1,
                        int num_writers = 1,
-                       int writing_port = -1, int block_ratio = 10):
+                       int writing_port = -1, int block_ratio = 1):
         global PARALLEL_IO, PARALLEL_IO_SERVER_ADDRESS, PARALLEL_IO_SERVER_PORT
         global FILENAME, FILE_FORMAT, NUM_SNAPS, STARTING_SNAP, h0, Ol, Om
         global BOX_SIZE, PERIODIC, PARTICLE_MASS, NUM_BLOCKS, NUM_READERS
@@ -327,11 +326,11 @@
 
         if particle_mass < 0:
             print "Assuming single-mass particle."
-            particle_mass = self.pf.h.grids[0]["ParticleMassMsun"][0] * h0
+            particle_mass = self.pf.h.grids[0]["ParticleMassMsun"][0] / h0
         PARTICLE_MASS = particle_mass
         PERIODIC = 1
         BOX_SIZE = (self.pf.domain_right_edge[0] -
-                    self.pf.domain_left_edge[0]) * self.pf['mpch']
+                    self.pf.domain_left_edge[0]) * self.pf['mpchcm']
         setup_config()
         rh = self
         cdef LPG func = rh_read_particles



https://bitbucket.org/yt_analysis/yt/changeset/f42b8087ace9/
changeset:   f42b8087ace9
branch:      yt
user:        MatthewTurk
date:        2011-11-30 15:20:52
summary:     A few more debugging changes, and removing socket-connection code from yt and leaving it up to Rockstar
affected #:  2 files

diff -r 43ab264e153e13162346a9ac2b8acb14c9e562eb -r f42b8087ace9e2d15606e5742dee5f31f73b8d54 yt/analysis_modules/halo_finding/rockstar/rockstar.py
--- a/yt/analysis_modules/halo_finding/rockstar/rockstar.py
+++ b/yt/analysis_modules/halo_finding/rockstar/rockstar.py
@@ -63,8 +63,6 @@
             self.pool.add_workgroup(num_writers, name = "writers")
             for wg in self.pool.workgroups:
                 if self.comm.rank in wg.ranks: self.workgroup = wg
-            if self.workgroup.name == "readers":
-                comm = Communicator(self.workgroup.comm)
         data_source = self.pf.h.all_data()
         self.handler = rockstar_interface.RockstarInterface(
                 self.pf, data_source)
@@ -84,18 +82,11 @@
 
     def run(self, block_ratio = 1):
         self._get_hosts()
-        if self.comm.size > 1 and self.workgroup.name == "writers":
-            sock = socket.socket()
-            sock.bind(('', 0))
-            port = sock.getsockname()[-1]
-            del sock
-        else:
-            port = -1
         self.handler.setup_rockstar(self.server_address, self.port,
                     parallel = self.comm.size > 1,
                     num_readers = self.num_readers,
                     num_writers = self.num_writers,
-                    writing_port = port,
+                    writing_port = -1,
                     block_ratio = block_ratio)
         if self.comm.size == 1:
             self.handler.call_rockstar()
@@ -104,9 +95,9 @@
             if self.workgroup.name == "server":
                 self.handler.start_server()
             elif self.workgroup.name == "readers":
-                time.sleep(0.5)
+                time.sleep(0.5 + self.workgroup.comm.rank/10.0)
                 self.handler.start_client()
             elif self.workgroup.name == "writers":
-                time.sleep(1.0)# + self.workgroup.comm.rank/10.0)
+                time.sleep(1.0 + self.workgroup.comm.rank/10.0)
                 self.handler.start_client()
         self.comm.barrier()


diff -r 43ab264e153e13162346a9ac2b8acb14c9e562eb -r f42b8087ace9e2d15606e5742dee5f31f73b8d54 yt/analysis_modules/halo_finding/rockstar/rockstar_interface.pyx
--- a/yt/analysis_modules/halo_finding/rockstar/rockstar_interface.pyx
+++ b/yt/analysis_modules/halo_finding/rockstar/rockstar_interface.pyx
@@ -278,7 +278,7 @@
             fi += 1
         pi += npart
     num_p[0] = tnpart
-    print "TOTAL", block, tnpart, len(grids)
+    print "TOTAL", block, pi, tnpart, len(grids)
 
 cdef class RockstarInterface:
 
@@ -314,6 +314,7 @@
             PARALLEL_IO_SERVER_PORT = server_port
         FILENAME = "inline.<block>"
         FILE_FORMAT = "GENERIC"
+        OUTPUT_FORMAT = "ASCII"
         NUM_SNAPS = 1
         NUM_READERS = num_readers
         NUM_BLOCKS = num_readers * block_ratio



https://bitbucket.org/yt_analysis/yt/changeset/f934201630f9/
changeset:   f934201630f9
branch:      yt
user:        MatthewTurk
date:        2012-03-16 14:32:14
summary:     Merging, including all the halo functions
affected #:  188 files
Diff too large to display.

https://bitbucket.org/yt_analysis/yt/changeset/597c862c8454/
changeset:   597c862c8454
branch:      yt
user:        MatthewTurk
date:        2012-03-16 15:07:18
summary:     Adding a context manager for parallel profiling, inserting an error in the case
of a block_ratio != 1, which is not currently supported.
affected #:  2 files

diff -r f934201630f9c8b8c7e10cc36a9530480812e924 -r 597c862c8454043a0f52e0a94d0866909d64ec67 yt/analysis_modules/halo_finding/rockstar/rockstar.py
--- a/yt/analysis_modules/halo_finding/rockstar/rockstar.py
+++ b/yt/analysis_modules/halo_finding/rockstar/rockstar.py
@@ -81,6 +81,8 @@
         self.port = str(self.port)
 
     def run(self, block_ratio = 1):
+        if block_ratio != 1:
+            raise NotImplementedError
         self._get_hosts()
         self.handler.setup_rockstar(self.server_address, self.port,
                     parallel = self.comm.size > 1,


diff -r f934201630f9c8b8c7e10cc36a9530480812e924 -r 597c862c8454043a0f52e0a94d0866909d64ec67 yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -24,6 +24,7 @@
 """
 
 import time, types, signal, inspect, traceback, sys, pdb, os
+import contextlib
 import warnings, struct, subprocess
 from math import floor, ceil
 
@@ -562,3 +563,15 @@
        isinstance(length[1], types.StringTypes):
        length = length[0]/pf[length[1]]
     return length
+
+ at contextlib.contextmanager
+def parallel_profile(prefix):
+    import cProfile
+    from yt.config import ytcfg
+    fn = "%s_%04i.cprof" % (prefix,
+                ytcfg.getint("yt", "__topcomm_parallel_rank"))
+    p = cProfile.Profile()
+    p.enable()
+    yield
+    p.disable()
+    p.dump_stats(fn)



https://bitbucket.org/yt_analysis/yt/changeset/6970ff964290/
changeset:   6970ff964290
branch:      yt
user:        MatthewTurk
date:        2012-03-16 15:15:46
summary:     Killing sleeps for now
affected #:  1 file

diff -r 597c862c8454043a0f52e0a94d0866909d64ec67 -r 6970ff9642908ef6512a3828b90ca978534e185a yt/analysis_modules/halo_finding/rockstar/rockstar.py
--- a/yt/analysis_modules/halo_finding/rockstar/rockstar.py
+++ b/yt/analysis_modules/halo_finding/rockstar/rockstar.py
@@ -97,9 +97,9 @@
             if self.workgroup.name == "server":
                 self.handler.start_server()
             elif self.workgroup.name == "readers":
-                time.sleep(0.5 + self.workgroup.comm.rank/10.0)
+                #time.sleep(0.5 + self.workgroup.comm.rank/10.0)
                 self.handler.start_client()
             elif self.workgroup.name == "writers":
-                time.sleep(1.0 + self.workgroup.comm.rank/10.0)
+                #time.sleep(1.0 + self.workgroup.comm.rank/10.0)
                 self.handler.start_client()
         self.comm.barrier()

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list