//-----------------------------------------------------------------------------
// function : lamport_scheduler
// description: This function implements the scheduler described by Lamport.
//-----------------------------------------------------------------------------
void lamport_scheduler( Source_code *source )
{
cout << LAMPORT_START;
// create the distance matrix from the h-transformations
Matrix distance_matrix = create_distance_matrix( source );
// partition the distance matrix by distance levels
Matrix **matrix_list = partition_by_levels( distance_matrix );
// calculate the first column vector of the transformation matrix
Matrix vector_u = find_first_column_vector( matrix_list,
source->get_n_vars() );
// create the transformation matrix
Matrix transformation_matrix =
create_transformation_matrix( vector_u );
Affin_function *schedule = calculate_schedule( transformation_matrix,
source );
Affin_function *placement = calculate_placement( transformation_matrix,
source );
cout << LAMPORT_RESULT;
transformation_matrix.print();
source->print_schedules();
source->print_placements();
source->save_placements();
source->save_schedules();
#ifndef NDEBUG
cout << ROUTINE_DONE;
#endif
}
This routine is called by the main function of the scheduling algorithms
in mainsched.cc, if the
parameter job given to the binary scheduler was "l".
The implementation above is straightforward. Since the algorithm expects
a distance matrix, we first have to convert the more general representation
of dependences, given by the h-transformations, to matrix form. After this
the elements of the distance matrix, namely the distance vectors, are sorted
after their dependence level. Now all is done to start the algorithm, that
consists of two parts:
Note: The method of lamport calculates besides the schedule also an allocation, which is in most cases useless for minimizing communication.