def example_1():
    """Square some numbers on remote hosts!
    """
    with cfut.SlurmExecutor(True) as executor:
        futures = [executor.submit(square, n) for n in range(5)]
        for future in concurrent.futures.as_completed(futures):
            print future.result()
def example_2():
    """Get host identifying information about the servers running
    our jobs.
    """
    with cfut.SlurmExecutor(False) as executor:
        futures = [executor.submit(hostinfo) for n in range(15)]
        for future in concurrent.futures.as_completed(futures):
            print(future.result().strip())
    def run(self):
        print(f'Listing package-configuration pairs ...')
        pkgs = self.list_pkg_paths()
        shuffle(pkgs)
        print(f'Will run on {len(pkgs)} configurations.')
        pkg_chunks = chunked_or_distributed(
            pkgs, max_groups=49, optimal_group_size=self.cpus_per_task)

        with cfut.SlurmExecutor(additional_setup_lines=self.sbatch_lines,
                                keep_logs=True) as executor:
            for err in suppressed_iterator(
                    executor.map(self.run_chunk, pkg_chunks)):
                if err is not None:
                    print(err)
def example_3():
    """Demonstrates the use of the map() convenience function.
    """
    exc = cfut.SlurmExecutor(False)
    print list(cfut.map(exc, square, [5, 7, 11]))