def run(self,view,model,input_format,trainfile,num_engines,simsdir,overwrite,max_sims,simsfile,modelfile):

        logging.info('finding number of items...')
        dataset = load_sparse_matrix(input_format,trainfile)
        num_users,num_items = dataset.shape
        del dataset
        logging.info('%d users and %d items', num_users, num_items)

        logging.info('creating sims directory {0}...'.format(simsdir))
        subprocess.check_call(['mkdir','-p',simsdir])

        done = []
        if not overwrite:
            logging.info('checking for existing output sims...')
            done.extend(self.find_done(simsdir))
            if done:
                logging.info('found {0} output files'.format(len(done)))

        logging.info('creating tasks...')
        tasks = self.create_tasks(model,input_format,trainfile,simsdir,num_items,num_engines,max_sims,done)

        if num_engines > 0:
            logging.info('running %d tasks in parallel across ipython'
                         ' engines...', len(tasks))
            async_job = view.map_async(process,tasks,retries=2)
            # wait for tasks to complete
            results = async_job.get()
        else:
            # Sequential run to make it easier for debugging
            logging.info('training similarity model sequentially')
            results = [process(task) for task in tasks]

        logging.info('checking output files...')
        done = self.find_done(simsdir)
        remaining = len(tasks) - len(done)
        if remaining == 0:
            logging.info('SUCCESS: all tasks completed')
            logging.info('concatenating {0} partial output files...'.format(len(done)))
            paths = [os.path.join(simsdir,'sims.{0}-{1}.tsv'.format(start,end)) for start,end in done]
            cmd = ['cat']+paths
            subprocess.check_call(cmd,stdout=open(simsfile,'w'))
            logging.info('removing partial output files...')
            rmtree(simsdir)
            logging.info('loading %d items in %s model from %s',
                         num_items, type(model).__name__, simsfile)
            model.load_similarity_matrix(simsfile,num_items)
            save_recommender(model,modelfile)
            logging.info('done')
        else:
            logging.error('FAILED: {0}/{1} tasks did not complete successfully'.format(remaining,len(tasks)))
            logging.error('try rerunning the command to retry the remaining tasks')
dataset/ETHPy150Open Mendeley/mrec/mrec/parallel/item_similarity.py/ItemSimilarityRunner.run/original